0% found this document useful (0 votes)
5 views9 pages

Trigonometric and Matrix Function Plots

The document contains various mathematical solutions involving plotting functions, verifying matrix properties, solving systems of equations, finding roots of equations, and evaluating integrals. It includes MATLAB code snippets for each problem, along with their respective outputs. Key topics include trigonometric functions, quadratic functions, idempotent and nilpotent matrices, and methods for finding local maxima and minima.

Uploaded by

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

Trigonometric and Matrix Function Plots

The document contains various mathematical solutions involving plotting functions, verifying matrix properties, solving systems of equations, finding roots of equations, and evaluating integrals. It includes MATLAB code snippets for each problem, along with their respective outputs. Key topics include trigonometric functions, quadratic functions, idempotent and nilpotent matrices, and methods for finding local maxima and minima.

Uploaded by

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

[Link] figure of the functions cos 𝑥 , sin 𝑥 ,tan 𝑥 and add a legend.

Solution:-
Input:-
x = -pi:1:pi;
figure(1);
plot(x, cos(x), 'r', x, sin(x), 'b', x, tan(x),
'g');
legend('cos(x)', 'sin(x)', 'tan(x)');
title('Trigonometric Functions');
xlabel('x'); ylabel('Function value');
grid on;
Output:-

2. Plot the figure of the functions

𝑓(𝑥) = 𝑥2-5x+6 & g(x)=x2+5x+6.


Solution:-
Input:-
x = -10:1:10;
f = x.^2 - 5*x + 6;
g = x.^2 + 5*x + 6;
figure(2);
plot(x,f,'r',x,g,'b');
legend('f(x)=x^2-5x+6','g(x)=x^2+5x+6');
xlabel('x'); ylabel('y');
title('Two Quadratic Functions');
grid on;
Output:-
𝟐 −𝟐 −𝟒
3. Show that the matrix 𝐴 is idempotent where 𝑨 = [−𝟏 𝟑 𝟒]
𝟏 −𝟐 −𝟑
Solution:-
Input:-
A = [2 -2 -4; -1 3 4; 1 -2 -3];
A2 = A*A;
disp('Matrix A^2 = ');
disp(A2);
if isequal(A2, A)
disp('A is idempotent.');
else
disp('A is NOT idempotent.');
end.

Output:-
Matrix A^2 =
2 -2 -4
-1 3 4
1 -2 -3

A is idempotent

𝟎 −𝟒 𝟐
4. Verify whether the matrix 𝐵 is nilpotent or not where 𝑩 = [𝟎 𝟎 𝟒].
𝟎 𝟎 𝟎
Solution:-
Input:-
B = [0 -4 2; 0 0 4; 0 0 0];
B2 = B*B;
B3 = B*B*B;
disp('B^2 = '); disp(B2);
disp('B^3 = '); disp(B3);
if B3 == zeros(3)
disp('B is nilpotent.');
else
disp('B is NOT nilpotent.');
end
Output:-
B^2 =
0 0 -16
0 0 0
0 0 0
B^3 =
0 0 0
0 0 0
0 0 0

B is nilpotent
𝟐 −𝟐 −𝟒
5. Find the determinant of the matrix 𝐴2 + 5𝐴 − 7𝐼 where 𝑨 = [𝟏 −𝟑 𝟒 ].
𝟏 −𝟐 𝟓
Solution:-
Input:-
A = [2 -2 -4; 1 -3 4; 1 -2 5];
I = eye(3);
M = A^2 + 5*A - 7*I;
detM = det(M);
disp(['Determinant of (A^2 + 5A - 7I) = ', num2str(detM)]);
Output:-
Determinant of (A^2 + 5A - 7I) = -6041

6. Find the roots of the equations 𝑥2 − 6𝑥 − 1


= 0 and 𝑥 − 5 = 0. Also, plot the figures
with different colors, and make legends.
Solution:-
Input:-
r1 = roots([1 ,-6 ,-1]); % x^2 -6x -1 =0
r2 = roots([1 ,-5]); % x -5 = 0
disp('Roots of x^2 -6x -1 = 0'); disp(r1);
disp('Root of x -5 = 0'); disp(r2);

x = -2:1:8;
y1 = x.^2 -6*x -1;
y2 = x -5;
figure(3);
plot(x,y1,'r',x,y2,'b');
legend('x^2-6x-1','x-5');
xlabel('x'); ylabel('y');
title('Roots Visualization');
grid on;
Output:-
Roots of x^2 -6x -1 = 0
-0.1623
6.1623

Root of x -5 = 0
5

7. Solve the following system of linear equations

𝑥+𝑦+𝑧=6

2𝑥 − 𝑦 + 3𝑧 = 14

4𝑥 + 3𝑦 + 2𝑧 = 24

Solution:-
Input:-
A = [1 1 1; 2 -1 3; 4 3 2];
b = [6;14;24];
sol = A\b;
disp('Solution of system :');
disp(['x = ', num2str(sol(1)), ', y = ', num2str(sol(2)), ', z = ', num2str(sol(3))]);

Output:-
Solution of system :
x = 6.2857, y = -0.57143, z = 0.28571
8. Solve the following system of linear equations

𝑥+𝑦+𝑧=9

2𝑥 − 𝑦 + 3𝑧 = 16

4𝑥 + 3𝑦 + 𝑧 = 28
Solution:-
Input:-
A = [1 1 1; 2 -1 3; 4 3 1];
b = [9;16;28];
sol2 = A\b;
disp('Solution of system :');
disp(['x = ', num2str(sol2(1)), ', y = ', num2str(sol2(2)), ', z = ', num2str(sol2(3))]);

Output:-
Solution of system :
x = 5.4, y = 1.4, z = 2.2

9. Find the roots of the equation cos(𝑥) = 𝑥2− 1. Also, plot the figures with different
colors, and make legends.
Solution:-
Input:-
x = -2:0.01:2;
y1 = cos(x);
y2 = x.^2 - 1;
figure(4);
plot(x,y1,'r',x,y2,'b');
legend('cos(x)','x^2-1');
xlabel('x'); ylabel('y');
title('Equation: cos(x)=x^2-1');
grid on;
Output:-
10. Find local maxima or minima of the function 𝑓(𝑥) = 2𝑥3 − 3𝑥2− 12𝑥 + 5.
Solution:-
Input:-
syms x;
f = 2*x^3 - 3*x^2 - 12*x + 5;
df = diff(f);
crit_points = solve(df==0);
d2f = diff(df);
disp('Critical points for f(x)=2x^3-3x^2-12x+5:');
for i=1:length(crit_points)
test = subs(d2f, x, crit_points(i));
f_value = subs(f, x, crit_points(i));
if test < 0
disp(['Local maximum at x = ', char(crit_points(i)), ...
', f(x) = ', char(f_value)]);
else
disp(['Local minimum at x = ', char(crit_points(i)), ...
', f(x) = ', char(f_value)]);
end
end
Output:-
Critical points for f(x)=2x^3-3x^2-12x+5:
Local minimum at x = 2, f(x) = -15
Local maximum at x = -1, f(x) = 12

11. Find the local maxima and minima of 𝑓(𝑥) = 𝑥³ − 6𝑥² + 9𝑥 + 1.

Solution:-
Input:-
syms x;
f = x^3 - 6*x^2 + 9*x + 1;
df = diff(f);
crit_points = solve(df==0);
d2f = diff(df);

for i=1:length(crit_points)
test = subs(d2f, x, crit_points(i));
f_value = subs(f, x, crit_points(i));
if test < 0
disp(['Local maximum at x = ', char(crit_points(i)), ',f(x) = ', char(f_value)]);
else
disp(['Local minimum at x = ', char(crit_points(i)), ', f(x) = ', char(f_value)]);
end
end
Output:-
Local maximum at x = 1,f(x) = 5
Local minimum at x = 3, f(x) = 1

∞ 𝟐 𝟏
12. Evaluate (i) ∫𝟎 𝒆−𝒙 (𝒍𝒏 𝒙)𝟐 𝒅𝒙 (ii) ∫−𝟏(𝒙𝟑 − 𝟗𝒙)𝒅𝒙 .

Solution:-

Input:-
syms x;
I1 = int(exp(-x^2)*(log(x))^2, 0, inf);
I2 = int(x^3 - 9*x, -1, 1);
disp('Integral (i) e^(-x^2)(lnx)^2 dx from 0 to infinity = ');
disp(vpa(I1));
disp('Integral (ii) (x^3 -9x)dx from -1 to 1 = ');
disp(vpa(I2));

Output:-
Integral (i) e^(-x^2)(lnx)^2 dx from 0 to infinity =
1.9475221803007815975843164106279

Integral (ii) (x^3 -9x)dx from -1 to 1 =


0.0
13. 13. Find the area bounded by 𝑦2 = 4𝑥 and 𝑥2 + 𝑦2 = 1.

Solution:-
Input:-

14. Bisection Method to solve 𝑥2− 5𝑥 + 6 = 0.


Solution:-
Input:-
f = @(x) x.^2 - 5*x + 6;
a = 0; b = 5; tol = 1e-5;
while (b-a)/2 > tol
c = (a+b)/2;
if f(c)==0
break;
elseif f(a)*f(c)<0
b=c;
else
a=c;
end
end
root_bis = (a+b)/2;
disp(['Root by Bisection Method = ', num2str(root_bis)]);

Output:-
Root by Bisection Method = 2

15. False Position Method to solve 2𝑒x sin 𝑥 = 3.


Solution:-
Input:-
f = @(x) 2*exp(x).*sin(x) - 3;
a = 0; b = 1; tol = 1e-5; fa = f(a); fb = f(b);
if fa*fb>0
disp('Choose another interval for False Position method.');
else
while abs(b-a)>tol
c = (a*fb - b*fa)/(fb - fa);
fc = f(c);
if fc==0, break; end
if fa*fc<0
b=c; fb=fc;
else
a=c; fa=fc;
end
end
root_fp = c;
disp(['Root by False Position Method = ', num2str(root_fp)]);
end

Output:-
Root by False Position Method = 0.76886

You might also like