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

Please use solely MATLAB, and explain each step as indicated below. Thank you Th

ID: 701640 • Letter: P

Question

Please use solely MATLAB, and explain each step as indicated below. Thank you

This homework will require i) solving an equation using the Newton-Raphson method, ii) solving the same equation using the built in function "fzero" in MATLAB, ii) solving the same equation using the built in function "fsolve" in MATLAB, and iv) plotting the function using "fplot" and showing its solution on the plot. Eq 1) solve: In(x) - 5x+7 0 Eq2) solve: -x*+10x3-100 x2 500 x 100 0 Eq3) solve: sin"(x)-5 cos(2x) + 0.4 = 0 For each equation 1. that finds a root. Clearly specify Write a script where the initial guess is specified, or if you are writing a function, tell us what needs to be input and in what order. 2. Use "fzero" to solve the equation 3. Use "fsolve" to solve the equation 4. Write a script (.m file) that uses fplot to plot the function. Separately, plot the function, and mark the solution on the plot and save it as a pdf. please upload all relevant files (scripts ) that perform the above-specified tasks. Also, please upload one pdf (or .m file) that includes your description of what files you are uploading and how each of them works, along with any other relevant information. Finally, upload a pdf file of the plot for each equation with the solution annotated.

Explanation / Answer

Please refer to the following matlab code,

%Solve ln(x)-5x+7=0
f =@(x) log(x)-5*x+7;
df =@(x) 1/x-5;
%1. Using Newton-Raphson to solve
%Since even for large x ln(x) is comparitively small, for initial guess let
%-5x+7=0
x = 7/5;
for i=1:30
x1 = x-(f(x)/df(x));
x = x1;
end
fprintf("The root of the equation as calculated by the Newton-Raphson method is %f ",x);
%2. Using fzero function
x0 = 7/5;
x = fzero(f,x0);
fprintf("The root of the equation as calculated by the fzero function is %f ",x);
%3. Using fsolve function
x0 = 7/5;
x = fsolve(f,x0);
fprintf("The root of the equation as calculated by the fsolve function is %f ",x);
%4. Plot the function
fplot(f,'Linewidth',2);
hold on
plot(x,subs(f,x),'b*')

clear x;

%Solve -x^4+10x^3-100x^2+500x+100=0
f =@(x) -x^4+10*x^3-100*x^2+500*x+100;
df =@(x) -4*x^3+30*x^2-200*x+500;
%1. Using Newton-Raphson to solve
%Let the initial guess be arbitrarily 2
x = 2;
for i=1:30
x1 = x-(f(x)/df(x));
x = x1;
end
fprintf("The root of the equation as calculated by the Newton-Raphson method is %f ",x);
%2. Using fzero function
x0 = 2;
x = fzero(f,x0);
fprintf("The root of the equation as calculated by the fzero function is %f ",x);
%3. Using fsolve function
x0 = 2;
x = fsolve(f,x0);
fprintf("The root of the equation as calculated by the fsolve function is %f ",x);
%4. Plot the function
fplot(f,'--or');
hold on
plot(x,subs(f,x),'g*')

clear x;

%Solve sin^2(x)-5cos(2x)+0.4=0
f =@(x) (sin(x))^2-5*cos(2*x)+0.4;
df = @(x) sin(2*x)+10*sin(2*x);
%1. Using Newton-Raphson to solve
%Let the initial guess be arbitrarily pi/4
%*Note that for x=0,pi/2,pi etc 2*x=n*pi for which df is 0. Hence f/df would
%not be defined.
x = pi/4;
for i=1:30
x1 = x-(f(x)/df(x));
x = x1;
end
fprintf("The root of the equation as calculated by the Newton-Raphson method is %f ",x);
%*Note that the solution to this function is the Principal Value from
%[0,pi/2]
%2. Using fzero function
x0 = pi/4;
x = fzero(f,x0);
fprintf("The root of the equation as calculated by the fzero function is %f ",x);
%3. Using fsolve function
x0 = pi/4;
x = fsolve(f,x0);
fprintf("The root of the equation as calculated by the fsolve function is %f ",x);
%4. Plot the function
fplot(f,'-.*c');
hold on
plot(x,subs(f,x),'r*')
hold off

It plots the funtions and reports solution. The data points of the solutions to 1), 2), 3) are in purple green and red respectively. Display the legend and edit as needed and save as pdf. Attach the script and describe the working of the script (mostly explained in the comments in the script.)