This homework will require i) solving an equation using the Newton-Raphson metho
ID: 2074749 • Letter: T
Question
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, ili) 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*+10x-100x 500x+100 Eq3) solve: sin2(x)-5 cos(2x) + 0.4-0 0 For each equation- 1. Write a script (or a function-the choice is up to you) that finds a root. Clearly specify where the initial guess is specified, or if you are writing a function, tell us what needs to be input and in what order. Use "fzero" to solve the equation Use "fsolve" to solve the equation 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 2. 3. n WyoCourses, please upload all relevant files (scripts or functions) 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
%I am solving for equation 1. you just change the equation in all the code to get the result.
%1
clc
clear all
close all
clc
% Change here for different functions
f=@(x) (log(x)/log(exp(1)))-(5*x)+7;
%this is the derivative of the above function
df=@(x) (1/x)-5;
% initial guess
a=-10;
x=a;
for i=1:1:100
x1=x-(f(x)/df(x));
x=x1;
end
sol=x;
fprintf('Approximate Root is %.15f',sol)
a=0;
x=a;
er(5)=0;
for i=1:1:5
x1=x-(f(x)/df(x));
x=x1;
er(i)=x1-sol;
end
%2
clc
clear all
close all
% Change here for different functions
f=@(x) (log(x)/log(exp(1)))-(5*x)+7;
t=-10; % initial point
a= fzero(f,t);
%3
clc
clear all
close all
% Change here for different functions
f=@(x) (log(x)/log(exp(1)))-(5*x)+7;
t=-10; % initial point
a= fsolve(f,t);
%4.
clc
clear all
close all
% Change here for different functions
f=@(x) (log(x)/log(exp(1)))-(5*x)+7;
fplot(f,[-10 10])
% Equation 2 f=@(x) (-x^4)+(10*x^3)-(100*x^2)+(500*x)+100;
% Equation 3 f=@(x) (sin(x))^2- 5*cos(2*x) +0.4;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.