You are on page 1of 2

REGULA-FALSI METHOD

clc

clear all

f=@(x)(x^2-32);

b=input(‘Value of b = ‘);

a=input(‘Value of a = ‘);

while f(a)*f(b)>0

b=input(‘Value of b = ‘);

a=input(‘Value of a = ‘);

end

for n=1:20

c=(a*f(b)-b*f(a)/f(b)-f(a));

if f(a)*f(c)<0

b=c;

else

a=c;

end

fprintf(‘The root is %f\t after iteration %f\n’,c,n)

end

fprintf (‘The root of the equation is %3.9f\n’,c)

SECANT METHOD
clc

clear all

a=input(‘Value of a = ‘);

b=input(‘Value of b = ‘);

tol=le-4;

f=@(x)(cos(x)-x*exp(x));
while abs (b-a)>tol

c=(a*f(b)-b*f(a))/(f(b)-f(a));

a=b;

b=c;

fprintf (‘New integer (%f,%f)\n’,a,b)

end

fprintf (‘Error is %f\t’,abs(b-a))

fprintf (‘New approximation %3.9f\n’,c)

fprintf (‘The root is %3.9f\n’,c)

NEWTON RAPHSON METHOD


clc

clear all

tol=le-3;

error=1;

n=1;

%change here for different function

f=@(x)(x*exp(x)-cos(x));

%this is the derivative of the above function

df=@(x) )(x*exp(x)+exp(x)+sin(x));

x=input (‘Initial Approximation = ‘);

while error>tol

y=x-(f(x)/df(x))

error=abs (y-x);

x=y;

n=n+1

end

You might also like