Académique Documents
Professionnel Documents
Culture Documents
//Half-Interval Method
disp('HALF-INTERVAL METHOD');
e=input('Error tolerance:');
clear;clc;format(12);
//Regula-Falsi Method
disp('REGULA-FALSI METHOD');
e=input('Error tolerance:');
xL=input('Lower Limit:');
xU=input('Upper Limit:');
while(f(xL)*f(xU)>0)
disp('The limits do not enclose the root. Enter new limits.')
xL=input('Lower Limit:');
xU=input('Upper Limit:');
end;
xr=xL-(f(xL)*(xL-xU))/(f(xL)-f(xU));
n=1;//initialize the iteration counter n
IT=[n,xL,xU,xr,f(xr)];//initialize the iteration table IT
while (abs(f(xr))>e)
if f(xL)*f(xr)<0 then
xU=xr;
else
xL=xr;
end;
xr=xL-(f(xL)*(xL-xU))/(f(xL)-f(xU));
n=n+1;
IT=[IT;n,xL,xU,xr,f(xr)];
end;
IT
xr
clear;clc;format(12);
format(6)
//Function for evaluating f(x)
function fv=f(x)
fv=exp(0.5*x)-x-4;
endfunction;
//Newton Method
disp('NEWTON METHOD');
e=input('Error tolerance:');
xr=input('First trial root:');
if abs(f(xr))>e then
disp('No root found.Rerun the program and try a new initial trial
root');
else
//display the iteration table and computed root
IT
xr
end;
function fv=f(x)
fv=exp(0.5*x)-x-4;
endfunction
function gv=g(x)
gv=(log(x+4))/0.5;
endfunction
if abs(f(xr))>e then
disp('No root found.')
disp(' Try a new initial trial root or change g(x)');
else
IT
xr
end