Using Matlab, find an approximation by the method of false position for the root of function f(x) = ex −x2 + 3x−2 accurate to within 10−5 (absolute error) on the interval [0,1]. Please answer and show code.
Pseudo Code for Method of False Position:
Given [a,b] containing a zero of f(x);
tolerance = 1.e-7; nmax = 1000; itcount = 0; error = 1;
while (itcount <=nmax && error >=tolerance)
itcount = itcount + 1;
x= a - ((b-a)/(f(b)-f(a)))f(a)
error =abs(f(x));
If f(a)*f(x) < 0
then b=x;
else a=x;
end while.
clc;
clear all;
format short
f=@(x)exp(x)-x^2 + 3*x-2 ; %function
a=0;b=1; % interval
% checking sign
if(f(b)<f(a))
m=a;
a=b;
b=m;
end
n=1;
err=0.1;
tol=1e-5;
while((err>tol))
c=(a*f(b)-b*f(a))/(f(b)-f(a));% false method formula
if ( f(c) == 0 )
break;
elseif ( f(a)*f(c) < 0 )
b = c;
else
a = c;
end
err=abs(f(c)); % error
n=n+1; % update next iteration
end
disp('root of function')
c
disp('number of iteration')
%%%%%%%%%%%%%%%%% Answer
root of function
c =
0.2575
number of iteration
n =
5
>>
Get Answers For Free
Most questions answered within 1 hours.