You are on page 1of 1

Bisection Method on Mathlab for sin(x)-x^3

xl=0.5;
xu=1;
f=@ (x) sin(x)-x.^3; % inline definition of function
xr=(xl+xu)/2;
ea=100;
es=2;
hold=0; % holdes old value of xr for the computation of approximation error
while (ea>es)
hold=xr;
if f(xr)*f(xl) <0
xu=xr;
elseif f(xr)*f(xu)<0
xl=xr;
end
xr=(xu+xl)/2;
ea=abs(((xr-hold)/xr)*100);
end
disp(ea);
disp(xr);
Newton Rapson method for 8*e^-x *sin(x)-1
f= @ (x) 8*exp(-x)*sin(x)-1; % inline function defnition,(exp) evaluates e^x
fd=@ (x) 8*exp(-x)*cos(x)-8*exp(-x)*sin(x);
% inline function
defnition.../The derivative of the function
x=0.3;
ea=100;
es=1;
hold=0;
while (ea>es)
hold=x; % hold is for relative approximation error estimation
x=x-f(x)/fd(x); %formula for newton method
ea=abs(((x-hold)/x)*100);
end
disp(x);

You might also like