In: Mechanical Engineering
a. Estimate the roots of the equation
by plotting the equation.
b. Use the estimates found in part a to nd the roots more accurately with the fzero function.
Program plan:
a. To write a matlab code to find the roots of the equation by plotting the equation.
b. To find the roots with the help of ‘fzero’ function.
Program:
%**********************************************************
%A matlab code is written to find the roots of the given
%equation by plotting the equation. The roots are more
%accurately found with the help of ‘fzero’ function.
%**********************************************************
%Declaration of the array
x=-5:0.01:5;
%Anonymous function
f=@(x) x.^3-3.*x.^2+5.*x.*sin(pi.*x/4-5.*pi/4)+3;
%Function plot
plot(x,f(x));
%Command for creating array
grid on;
%Command for setting appropriate axes
axis([-2,5,-50,50])
%Displays text
disp(\'The roots are\');
%Finds the root near \'2\'
x1=fzero(f,2);
%Finds the root near \'0\'
x2=fzero(f,0);
%Finds the root near \'4\'
x3=fzero(f,4);
%Displays value
disp(x1);
%Displays value
disp(x2);
%Displays value
disp(x3);
Output (a):
Output (b):
>> untitled
The roots are
1.1346
-0.4795
3.8318
Output
>> untitled
The roots are
1.1346
-0.4795
3.8318