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

Using MatLab 2. Use Newton\'s method in a script to solve the following (you may

ID: 3168157 • Letter: U

Question

Using MatLab

2. Use Newton's method in a script to solve the following (you may have to experiment a bit with starting values). Check all your answers with fzero. Check the answers involving polynomial equations with roots. (Hint: use fplot to get an idea of where the roots are, e.g., fplot ("X^3-8*x^2-17tx-10,, [03]) The Zoom feature also helps. In the figure window select the Zoom In button magnifying glass) and click on the part of the graph you want to magnify a) x4-x = 10 (two real roots and two complex roots) b) e-x = sin(x) (infinitely many roots) c) x3-8x2 + 17x-10 = 0 (three real roots) d) log x= e) x4-5x3 os 12x2 + 76-79-0 (four real roots)

Explanation / Answer

%%%% Matlab function %%%%

function [ ] = NR_roots ( f,x0,tol )
% % % % N-R Method

s(1)=x0;
for n=1:100
l1=subs(f,s(n));
l2=subs(diff(f),s(n));
s(n+1)=s(n)-l1/l2;
e=abs(s(n+1)-s(n));
if (e < tol)
break;
end
end
fprintf('Roots of function with initial guess x0= %f is %f ', s(1),s(end) );
end

a)

%%% Main code %%%

syms x
f= x^4-x-10;
t=linspace(-4,5 ,1000);
y=subs(f,t);
plot(t,y);
hold on ;
plot(t,zeros(size(y)),'r');
tol=0.000001;
NR_roots(f,-2,tol);
NR_roots(f,2,tol);

OUTPUT:

Roots of function with initial guess x0= -2.000000 is -1.697472
Roots of function with initial guess x0= 2.000000 is 1.855585

B)

%%% Main code %%%

syms x
f= exp(-x)-sin(x);
t=linspace(-4,5 ,1000);
y=subs(f,t);
plot(t,y);
hold on ;
plot(t,zeros(size(y)),'r');
tol=0.000001;
NR_roots(f,0,tol);
NR_roots(f,3,tol);

OUTPUT:

Roots of function with initial guess x0= 0.000000 is 0.588533
Roots of function with initial guess x0= 3.000000 is 3.096364

c)

%%%% Main code %%%

syms x
f= x^3-8*x^2+17*x-10;
t=linspace(-4,5 ,1000);
y=subs(f,t);
plot(t,y);
hold on ;
plot(t,zeros(size(y)),'r');
tol=0.000001;
NR_roots(f,0,tol);
NR_roots(f,3,tol);
NR_roots(f,6,tol);

OUTPUT:

Roots of function with initial guess x0= 0.000000 is 1.000000
Roots of function with initial guess x0= 3.000000 is 2.000000
Roots of function with initial guess x0= 6.000000 is 5.000000

d)

%%% Main code %%%

syms x
f= log10(x)-cos(x);
t=linspace(-4,5 ,1000);
y=subs(f,t);
plot(t,y);
hold on ;
plot(t,zeros(size(y)),'r');
tol=0.000001;
NR_roots(f,-2,tol);
NR_roots(f,2,tol);

OUTPUT:

Roots of function with initial guess x0= -2.000000 is -1.414668
Roots of function with initial guess x0= 2.000000 is 1.418406

e)

%%% Main code %%%

syms x
f= x^4-5*x^3-12*x^2+76*x-79;
t=linspace(-10,10 ,1000);
y=subs(f,t);
plot(t,y);
hold on ;
plot(t,zeros(size(y)),'r');
tol=0.000001;
NR_roots(f,-6,tol);
NR_roots(f,0,tol);
NR_roots(f,1,tol);
NR_roots(f,6,tol);

OUTPUT:

Roots of function with initial guess x0= -6.000000 is -3.996909
Roots of function with initial guess x0= 0.000000 is 1.768387
Roots of function with initial guess x0= 1.000000 is 1.768387
Roots of function with initial guess x0= 6.000000 is 4.987534

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote