You are on page 1of 2

(a)

f_x = @(x)8 * sin(x)*exp(-x) - 1

figure(1)

ezplot(f_x)

grid on

hold on

%(b)

% Newton Ralphson Formula

% x_i+1 = x_i - (f(xi)/f'(xi))

% first find dx

d_f = @(x) -8*cos(x)*-exp(-x)

nr_x = .3 %our guess of xi

for i = 1:3

nr_x_i = nr_x - f_x(nr_x)./(d_f(nr_x));

nr_x = nr_x_i;

plot(nr_x,f_x(nr_x) , '*b')

end

%(c)

%Secant Method

figure(2)

ezplot(f_x)

grid on

hold on

x1 = 0.5;

x2 = 0.4;

for itter = 1:5,

xn = x2 - f_x(x2) * (x1-x2)/(f_x(x1)-f_x(x2))
x1= x2

x2=xn

plot(xn,f(xn),'*r')

end

%(d)

%Modified Secant Method

figure(3)

ezplot(f_x)

hold on

grid on

ep = 0.01;

adf_x = @(x) (f_x(x+ep)- f_x(x))/ep; %modified secant method

x = .3

xa = .3

for itter = 1:3,

x = x - f_x(x)/ df_x(x);

plot(x,f_x(x),'*r')

xa = xa - f_x(xa)/adf_x(xa);

plot(xa,f_x(xa),'*g')

end

You might also like