Regula Falsi Modified Code(Latest)

Regula Falsi Modified Code

clc;clear all;close all;
x(1)=input('Enter first value:');
x(2)=input('Enter second value:');
n=100;
if f(x(1))*f(x(2))<0
for i=2:n
    x(i+1)=(x(i-1)*f(x(i))-x(i)*f(x(i-1)))/(f(x(i))-f(x(i-1)));
    if abs(f(x(i+1))-f(x(i)))<0.0001
        break
    end
end
fprintf('x=%f',x(i+1));
else
    fprintf('Wrong input')
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