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

1. (a) Use Newton\'s Method to approximate the fixed point of the function f(e t

ID: 3282982 • Letter: 1

Question

1. (a) Use Newton's Method to approximate the fixed point of the function f(e to an accuracy of 10-4. Choose any starting value for x0 that gives convergence. Recall, a function has a fixed point at x whenever f(x) = x, so the above function will need to be rearranged accordingly (i.e.you are NOT solving e0). (b) Repeat the problem above using the Secant Method. Use the same x0 from Newton's methood in 1(a) and choose a nearby x1. Compare the output of both methods and write your thoughts as comments

Explanation / Answer

a)

clc;
clear all;

format long
f=@(x)exp(-x)-x; %function
df=@(x)-exp(-x)-1;% derivative of function

x=1; %initial value
x1=x;
tol=1e-4;
ebs=0.1;
n=1;
max_iter=30;
disp('_____________________________________________________________________________________')

disp('n x(n)) f(x(n)) error')
disp('_____________________________________________________________________________________')
while(ebs>tol&n<max_iter)

x(n+1)=x(n)-(f(x(n))/df(x(n))); %newton method
x1(n+1)=x1(n)+f(x1(n));
  
%x=x1;
ebs=abs((f(x(n))/df(x(n))));
erorr(n)=ebs;

y=df(x(n));

fprintf('%d %15f %15f %15f ',n ,x(n),f(x(n)),erorr(n))
n=n+1;
end

%%%% Solution %%%%

_____________________________________________________________________________________

n x(n)) f(x(n)) error

_____________________________________________________________________________________

1 1.000000 -0.632121 0.462117

2 0.537883 0.046100 0.029104

3 0.566987 0.000245 0.000156

4 0.567143 0.000000 0.000000

>>

b)

clc;
clear all;


f=@(x) exp(-x)-x;
x(1)=0;
x(2)=1;
n=1;


tol=1e-4;
iteration=0;
i=2;
eps = 1e0;


%secont method
while (abs(eps) > tol & i<=100)
x(i+1)=x(i)-f(x(i))*(x(i)-x(i-1))/(f(x(i))-f(x(i-1)));
eps (i)= abs(x(i+1)-x(i));
i = i+1;
x(i);
  
end
i;
x(end); %root
c=x(end);


disp('______________________________________________________________')
disp( 'itertion x_value error')
disp('______________________________________________________________')
for j=1:i-1
fprintf('%f %15f %15f ',j,x(j),abs(eps(j)))
end
disp('Root of function is')


x(end) %roots of three functions

%%%%Solution

______________________________________________________________

itertion x_value error

______________________________________________________________

1.000000 0.000000 1.000000

2.000000 1.000000 0.387300

3.000000 0.612700 0.048861

4.000000 0.563838 0.003332

5.000000 0.567170 0.000027

Root of function is

ans =

0.567143306604963

>>