Submitted By: 18BCM0135 (Atmadeep Dutta) Date: 28.7.2020
Submitted By: 18BCM0135 (Atmadeep Dutta) Date: 28.7.2020
Date : 28.7.2020
Faculty: Dr. Monash Purushothaman.
Experiment 2
Develop a MATLAB code to identify the difference between
regula falsi and modified regula falsi numerical method for the
expression f(x) = x10-1 between the limits 0and 1.3. Compare
the number of iteration involved and give justification for the
obtained result.
Code
clc;
clear;
disp ('Name: Atmadeep Dutta');
disp ('Reg No 18BCM0135');
disp('Experiment 2');
fx=input('Enter te function', 's');
xl=input('Enter the lower limit: ');
xu=input('Enter the upper limit: ');
x=xl; fxl=eval(fx);
x=xu; fxu=eval(fx);
if (fxl*fxu) <0
disp('Atleast one root');
n=100; es=0.01;
il=0; iu=0;
for i=1:n
xm=(xl+xu)/2;
x=xm; fxm=eval(fx);
if (fxl*fxm)<0
xu=xm; fxu=fxm;
il=il+1;
iu=0;
if il>=2
fxl=fxl/2;
end
elseif (fxu*fxm)<0
xl=xm; fxl=fxm;
iu=iu+1;
il=0;
if iu>=2
fxu=fxu/2;
end
end
if i>1
ea=abs((xm-xmold)/xm)*100;
if ea<=es
fprintf('Root = %f\t Iteretation involved =
%d\n', xm, i);
break;
end
end
xmold=xm;
end
else
disp('No roots between the limits. return the program
with new initial guesses');
end
Output