Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Matlab Function file and a script file that runs the function. When run

ID: 2267422 • Letter: C

Question

Create a Matlab Function file and a script file that runs the function. When running the script, the answer's should display on the screen.

Post a clear picture of the hand written work if the problem asks for hand written work.

Comment the MatLab code so I can understand it. I should be able to just copy and paste the code and have it run.

The work and answer should match the answer posted.

Post the code and written work.

Determine the lowest positive root of f(x)= 8 sin(xe*- 1: (a) Graphically (b) Using the Newton-Raphson method (three iterations, (c) Using the secant method (three iterations, xi-l = 0.5 (d) Using the modified secant method (five iterations, Answer: x-0.1450 (it will take 5 iterations of secant to get this number) Xi = 0.3) and Xi = 0.4 Xi = 0.3, 0.01)

Explanation / Answer

% IF YOU KNOW BASIC COMMANDS OF MATLAB YOU WILL UNDERSTAND THIS CODE.

% MOST OF LINES WITH COMMENTS TO UNDERSTAND

% ALL (a) to (d) answers are included; you can copy paste and run it. you will get all answers on screen

% for graph output draw a marker at crossection of lines. you will get answer.

clc;
clear all;

% GRAPHICAL METHOD
for x = 0.1:0.0001:0.16 % loop from intial value to final values
f = 8 * sin(x)* exp(-x)-1;  
plot(x,f,'r-');
hold on
plot(x,0,'b*');
end
% in the output graph put a marker where both lines meet ( y = 0 and x = 0.145)  


% _________________________Newton Raphson method___________________________   
f = 8 * sin(x)* exp(-x)-1;
df = exp(-x)*cos(x)- 8* sin(x)* exp(-x) + exp(-x) * cos( x ); %Derivative of the equation
x0= 0.3;

for i = 1:3
h = -( 8 * sin(x0)* exp(-x0)-1)/ (exp(-x0)*cos(x0)- 8* sin(x0)* exp(-x0) + exp(-x0) * cos( x0 )); %- feval(f,x0)/feval(df,x0);
x0=x0+h;
disp(x0);
end
root=x0;
disp(' Answer by Newton Raphson method is: ');
disp (root);

% ________SECANT METHOD _______________
f = 8 * sin(x)* exp(-x)-1; %Equation
x0 = 0.5 ;   
x1 = 0.4 ;   
for i = 1:5
y1 = x0 *(8 * sin(x1)* exp(-x1)-1)-(x1*( 8 * sin(x0)* exp(-x0)-1 )); % EQUATION IS BROKEN INTO Y1 AND Y2
y2 = (8 * sin(x1)* exp(-x1)-1 )- (8 * sin(x0)* exp(-x0)-1); % DIVIDE Y1 /Y2 TO GET X2
x2 = y1/y2;
x0=x1;
x1=x2;
end
root=x2;
disp(' Answer by Secant method is: ');
display (root);

% ____MODIFIED SECANT METHOD____________

f = 8 * sin(x)* exp(-x)-1; %Equation
xi = 0.3;
delta = 0.01;
for i = 1 : 5
xi = xi - (((delta *(8 * sin(xi)* exp(-xi)-1))/((8 * (sin(xi+delta)* exp(-xi+delta)-1)) - (8 *( sin(xi)* exp(-xi)-1)))));
disp(xi);
end
root = xi;
disp(' Answer by Modified Secant method is: ');
display (root);