Regula Falsi Method Coding in Matlab
clc;
close all;
clear all;
x1=input('Enter first value:');
x2=input('Enter second value:');
n=input('Enter no of iteration:');
fx1=f(x1);
fx2=f(x2);
c = x2 - ((f(x2)*(x2-x1))/(f(x2) - f(x1)));
fc=f(c);
if fx1*fx2<0
for i=1:n
if fc<0
x1=c;
fx1=f(x1);
c = x1 - (fx1*(x1-x2)/(fx1-fx2));
fc = f(c);
else
x2=c;
fx2=f(x2);
c = x2 - (fx2*(x2-x1)/(fx2-fx1));
fc = f(c);
end
end
fprintf('Root :%f',c);
else
fprintf('wrong choice of bracket values');
end
function fx = f(x)
fx = x*2.71828^x - cos(x);
%fx =6*x^5-41*x^4+97*x^3-97*x^2+41*x-6;
return;
end
Comments
Post a Comment