You are on page 1of 2

%Example of false position method =

F = inline('x^3 - x^2 - 10*x - 8'); % %Define a function using


inline
xl =
xu =
imax
es =
xr =

3.75;
5;
= 20;
0.5;
0; % Dummy value for xr.

Fl=F(xl);
Fu=F(xu);
if Fl*Fu > 0

% Define all initial value

% Define lower and upper function


% Positive value

disp('Error: The function has the same sign at


points xl and xu.')
else
fprintf('-------------------------------------\n');
fprintf(' i
xl
xu
xr
Fr
ea\n');
fprintf('-------------------------------------\n');
for i = 1:imax
xrold = xr;
xr = xu-((Fu*(xu - xl))/(Fu-Fl));

% False Position
Equation

Fr=F(xr);
ea=abs((xr-xrold)/xr)*100;

% Error calculation

fprintf('%3i %11.4f %11.4f %11.4f %10.4f


%10.4f\n',i, xl, xu, xr, Fr, ea)

if Fr == 0
fprintf('An exact solution x =%11.6f was
found',xr)

end

break

if ea < es
break
end
if i == imax
fprintf('Solution was not obtained in %i
iterations',imax)
break
end
if Fl*Fr
xu =
else
xl =
Fl =
end

< 0
xr;
xr;
Fr;

end
fprintf('The approximate solution is x = %8.4f \n ',xr)
end

ANSWER
------------------------------------------------------------i
xl
xu
xr
Fr
ea
------------------------------------------------------------1
3.7500
5.0000
3.9248
-2.1942
100.0000
2
3.9248
5.0000
3.9782
-0.6493
1.3419
3
3.9782
5.0000
3.9937
-0.1874
0.3895
The approximate solution is x =
3.9937

You might also like