Use the Newton’s method to find the root for ex+1 = 2 + x, over [?2,...

Free

80.2K

Verified Solution

Question

Advance Math

Use the Newton’s method to find the root for ex+1 = 2+ x, over [?2, 2]. Can you find a way to numerically determinewhether the convergence is roughly quadratic using error producedat each iteration? Include your answers as Matlab code comments

Answer & Explanation Solved by verified expert
4.1 Ratings (602 Votes)

clc;
clear all;
format short

f=@(x)exp(x+1) - 2 - x; %function

f1=@(x)exp(x+1)-1; %derivative of function

x(1)=1; %initial value
tol=1e-7; % tolernece
erorr=0.1;
n=1;
Max_iter=18; % Maximum iteration

while(erorr>tol&n
x(n+1)=x(n)-(2*f(x(n))/f1(x(n))); %newton method
  
%x=x1;
erorr(n)=abs((x(n)-x(n+1)));
n=n+1;

end
disp('_____________________________________________________________')

disp('n x(n)) f(x(n)) error ')
disp('____________________________________________________________')

for i=1:n-1
fprintf('%d %15f %20f %20f ',i ,x(i),f(x(i)),erorr(i))
end

for i=2:n-2
r(i-1)=log(erorr(i+1)/erorr(i))/log(erorr(i)/erorr(i-1));
end
disp('Rate of convergence')
r'
disp('Root of function is')
y=x(end)

disp('Number of iteration to converge the root')
n-1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

_____________________________________________________________
n x(n)) f(x(n)) error   
____________________________________________________________
1   1.000000    4.389056    1.373929
2   -0.373929    0.244177    0.561166
3   -0.935095    0.002153    0.064203
4   -0.999298    0.000000    0.000702
5   -1.000000    0.000000    0.000000
Rate of convergence

ans =

2.4212
2.0830
2.0003

Root of function is

y =

-1.0000

Number of iteration to converge the root

ans =

5

>>


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students