Professional Documents
Culture Documents
MATLAB - Chp-3 Ex (Redit)
MATLAB - Chp-3 Ex (Redit)
MATLAB - Chp-3 Ex (Redit)
2.
x = [-2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3];
y = x.^3 .* (x.^2 + 1).^3;
---------------------------------Output------------------------------------------
Values of x:
-2.5000 -2.0000 -1.5000 -1.0000 -0.5000 0 0.5000 1.0000 1.5000
2.0000 2.5000 3.0000
Values of y:
275.6094 108.0000 46.8750 16.0000 3.6094 0.0000 3.6094 16.0000
46.8750 108.0000 275.6094 559.0000
3.
g = 9.81;
t = 1:10;
d = 0.5 * g * t.^2
4.
x = [2, 4, 6, 8, 10];
y = [3, 6, 9, 12, 15];
z = (x.*y + y./x) ./ (x + y).^(y - x) + 12.^(x./y)
---------------------------------Output------------------------------------------
Values of z:
33.3929 267.0056 587.6491 1282.0287 2847.5522
5.
h = 0.9;
k = 12.5;
x = [1, 2, 3, 4];
y = [0.9, 0.8, 0.7, 0.6];
z = [2.5, 3, 3.5, 4];
T = (x .* y .* z) ./ ((h + k).^(k/5)) + (k .* exp((z ./ x) + y)) ./ (z.^h)
------------------------------------Output-------------------------------------
[164.20043282 46.39237005 26.18890142
17.79441838]
6.
n = [1, 10, 100, 500, 1000, 2000, 4000, 8000];
y = (1 + 1 ./ n) .^ n
e_value = exp(1);
absolute_difference = abs(y - e_value)
7.
% Part a: n = 100
n_a = 1:100;
sum_a = sum(1 ./ n_a.^2)
approximation_a = pi^2 / 6
% Part b: n = 1000
n_b = 1:1000;
sum_b = sum(1 ./ n_b.^2)
approximation_b = pi^2 / 6
% Part c: n = 10000
n_c = 1:10000;
sum_c = sum(1 ./ n_c.^2)
approximation_c = pi^2 / 6
-------------------------------Output------------------------------------------
n = 100:
1.6439340668482264
n = 1,000:
1.6448340718480652
n = 10,000:
1.6449340668480652
8.
ln_2 = log(2);
% Calculate the sum of the series for n = 50
n50 = 0:50;
a_n50 = (1 ./ ((2 * n50 + 1) .* (2 * n50 + 2)));
sum(a_n50)
ln_2
n500 = 0:500;
b_n500 = (1 ./ ((2 * n500 + 1) .* (2 * n500 + 2)))
sum(b_n500)
ln_2
n5000 = 0:5000;
_n5000 =(1 ./ ((2 * n5000 + 1) .* (2 * n5000 + 2)));
sum(c_n5000)
ln_2
9.
a) **Calculate A+B and B+A to show that addition of matrices
is commutative.
% Define matrices A, B
A = [5, 2, 4; 1, 7, -3; 6, -10, 0];
B = [11, 5, -3; 0, -12, 4; 2, 6, 1];
% Calculate A + B and B + A
sum_AB = A + B;
sum_BA = B + A;
% Define matrix C
C = [7, 14, 1; 10, 3, -2; 8, -5, 9];
% Calculate A + (B + C) and (A + B) + C
sum_B_C = B + C;
sum_A_B_C = A + sum_B_C;
sum_A_B = A + B;
sum_A_B_C_alt = sum_A_B + C;
---------------------------------Output---------------------------------------
% Part a)
A + B:
[16 7 1]
[11 15 1]
[8 -4 1]
B + A:
[16 7 1]
[11 15 1]
[8 -4 1]
% Part b)
A + (B + C):
[38 31 2]
[11 13 -5]
[26 3 10]
(A + B) + C:
[38 31 2]
[11 13 -5]
[26 3 10]
% Part c)
5(A + C):
[190 155 10]
[55 15 -10]
[140 -25 45]
5A + 5C:
[190 155 10]
[55 15 -10]
[140 -25 45]
% Part d)
(B + C):
[18 29 -1]
[10 3 -2]
[26 1 10]
A * (B + C):
[38 31 2]
[11 13 -5]
[26 3 10]
A * B + A * C:
[38 31 2]
[11 13 -5]
[26 3 10]
10.
% Given matrices
A = [5, 2, 4; 1, 7, -3; 6, -10, 0];
B = [11, 5, -3; 0, -12, 4; 2, 6, 1];
C = [7, 14, 1; 10, 3, -2; 8, -5, 9];
% Display results
disp('a) Does A*B = B*A?');
disp(result_a);
11.
% Coefficients matrix A
A = [5 4 -2 6; 3 6 6 4.5; 6 12 -2 16; 4 -2 2 -4];
% Constants vector b
b = [4; 13.5; 20; 6];
12.
theta = 5:5:85;
theta_rad = deg2rad(theta);
g = 9.81;
v0 = 750;
d = (v0^2 * sin(2 .* theta_rad)) / g;
result = [theta' d']
----------------Output----------------
5 9957
10 19611
15 28670
20 36857
25 43925
30 49657
35 53881
40 56468
45 57339
50 56468
55 53881
60 49657
65 43925
70 36857
75 28670
80 19611
85 9957
13.
% Given data
vA = 680; % m/s (initial velocity of projectile A)
vB = 780; % m/s (initial velocity of projectile B)
thetaA = 65; % degrees (launch angle of projectile A)
thetaB = 42; % degrees (launch angle of projectile B)
g = 9.81; % m/s^2 (acceleration due to gravity)
% Calculations
% Calculate time of flight for projectiles A and B
tA = (2 * vA * sind(thetaA)) / g;
tB = (2 * vB * sind(thetaB)) / g;
OR
% Define the initial conditions
v_A = 680;
v_B = 780;
theta_A = 65 * pi / 180;
theta_B = 42 * pi / 180;
distance = dA - dB;
---------------------------Output------------------------------