0% found this document useful (0 votes)
6 views4 pages

Code of Problems

Matlab coding

Uploaded by

abobaker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Code of Problems

Matlab coding

Uploaded by

abobaker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Code of problem 1:

result1 = (17 * sqrt(5 - 1)) / (15^2 - 13^2) + (5 * 7 * log10(exp(3))) / (pi *


sqrt(121)) + log(exp(4)) + sqrt(11);
disp(result1);
Code of problem 2:

x = 5 * pi / 6;
B = (tan(x) + sin(2 * x)) / cos(x) + log(abs(x^5 - x^2)) + cosh(x) - 2 * tanh(x);
disp(B);

Code of problem 3:
a = 1;
b = 2;
c = 1.8;
x = a + (a*b*(a + b)) / (c * sqrt(a*b) + sqrt(c^4)) + sqrt(14) / exp(c) + log(2) +
log10(c) / log10(a + b + c) + 2 * sinh(a) - 3 * tanh(b);
disp(x);

Code of problem 4:
Part(a)
row_vector = [11, -3, exp(7.8), log(59), tan(pi/3), 5 * log10(26)];
column_vector = row_vector';
disp(row_vector);
disp(column_vector);
Part(b)
row_vector_20=linspace(5, 5+19*spacing(5), 20); % spacing(5) gives the difference
between consecutive values
disp(row_vector_20);
Part(c)
column_vector_15 = linspace(-2, -2 + 14 * spacing(-2), 15);
disp(column_vector_15);

Code of problem 5:
Part(a)
A = reshape(1:40, 5, 8)'; % Matrix A
B = A([1, 3, 5], [1, 2, 4, 8]);
disp(B);
Part (b)
C = [A(5,:), A(:,4)', A(:,6)'];
disp(C);
Code of problem 6:
x_values = [2, 3, 8, 10, -1, -3, -5, -6.2];
y = ((x_values .* sqrt(2) + 0.02 + exp(x_values)) ./ x_values).^1.8 .*
log(x_values);
disp(y);

Code of problem 7:
a = 0.75;
b = 1.13;
x = [2, 5, 1, 9];
y = [0.2, 1.1, 1.8, 2];
z = [-3, 2, 5, 4];

A = a * x + b * y + z;
disp(A);
Code of problem 8:
% Define matrices A, B, and C
A = [1 2 3; -8 5 7; -8 4 6];
B = [12 -5 4; 7 11 6; 1 8 13];
C = [7 13 4; -2 8 -5; 9 -6 11];

% a) A + B = B + A
AB_equal_BA = isequal(A + B, B + A);

% b) A + (B + C) = (A + B) + C
ABC_equal_ABC = isequal(A + (B + C), (A + B) + C);

% c) T(A + C) = T(A) + T(C)


transpose_property = isequal(transpose(A + C), transpose(A) + transpose(C));

% d) A * (B + C) = A * B + A * C
distributive_property = isequal(A * (B + C), A * B + A * C);

% Display results
AB_equal_BA
ABC_equal_ABC
transpose_property
distributive_property

Code of problem 9:
% Define the numerator and denominator polynomials
n_s = [1 6 5 4 3]; % n(s) = s^4 + 6s^3 + 5s^2 + 4s + 3
d_s = [1 7 6 5 4 7]; % d(s) = s^5 + 7s^4 + 6s^3 + 5s^2 + 4s + 7

% a) Find n(10), n(-5), n(-3), and n(-1)


n_values = polyval(n_s, [10, -5, -3, -1]);

% b) Find d(10), d(-5), d(-3), and d(-1)


d_values = polyval(d_s, [10, -5, -3, -1]);

% c) Find H(10), H(-5), H(-3), and H(-1)


H_values = n_values ./ d_values;

% Display results
n_values
d_values
H_values

Code of problem 10:


% Define the polynomials
p1 = [1 5 3 10]; % p1(s) = s^3 + 5s^2 + 3s + 10
p2 = [1 7 5 8 15]; % p2(s) = s^4 + 7s^3 + 5s^2 + 8s + 15
p3 = [1 15 10 6 3 9]; % p3(s) = s^5 + 15s^4 + 10s^3 + 6s^2 + 3s + 9

% a) Evaluate p1(2), p2(2), p3(3)


p1_value = polyval(p1, 2);
p2_value = polyval(p2, 2);
p3_value = polyval(p3, 3);

% b) Multiply p1(s), p2(s), p3(s)


p_mult = conv(p1, conv(p2, p3));
% c) Divide p1(s) * p2(s) / p3(s)
p_div = deconv(conv(p1, p2), p3);

% Display results
p1_value
p2_value
p3_value
p_mult
p_div

Code of problem 11:


% Define the polynomials
p1 = [1 2 -3 7 -8 7]; % p1(x) = x^5 + 2x^4 - 3x^3 + 7x^2 - 8x + 7
p2 = [1 4 -3 -5 9 11]; % p2(x) = x^4 + 3x^3 - 5x^2 + 9x + 11
p3 = [1 -2 -3 9]; % p3(x) = x^3 - 2x^2 - 3x + 9
p4 = [1 -5 13]; % p4(x) = x^2 - 5x + 13
p5 = [1 0 5]; % p5(x) = x + 5

% Evaluate each polynomial at x = 2


p1_value = polyval(p1, 2);
p2_value = polyval(p2, 2);
p3_value = polyval(p3, 2);
p4_value = polyval(p4, 2);
p5_value = polyval(p5, 2);

% Display results
p1_value
p2_value
p3_value
p4_value
p5_value

Code of problem 12:


% Define the polynomial
p = [1 8 5 4 3 2 1 1]; % p(x) = x^7 + 8x^6 + 5x^5 + 4x^4 + 3x^3 + 2x^2 + x + 1

% Find the roots


roots_p = roots(p);

% Display the roots


roots_p

Code of problem 13:

Code of problem 14:

Code of problem 15:

Code of problem 16:


Code of problem 17:

Code of problem 18:

Code of problem 19:

Code of problem 20:

You might also like