Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

LabTask

The document describes the implementation of the False Position method for finding the root of a function. It includes a loop that iteratively calculates the root approximation and displays the results for each iteration until the error tolerance is met. The final output indicates an approximate root of negative infinity and the corresponding function value at that root is also negative infinity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

LabTask

The document describes the implementation of the False Position method for finding the root of a function. It includes a loop that iteratively calculates the root approximation and displays the results for each iteration until the error tolerance is met. The final output indicates an approximate root of negative infinity and the corresponding function value at that root is also negative infinity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

%Lab Task

xl = 0;
xu = 5;

xr_prev = 0;
ea = 100;
tol = 1e-6;

fprintf('False position method:\n');

False position method:

fprintf('%5s %10s %10s %10s %10s\n', 'Iteration', 'xl', 'xu', 'xr', 'ea(%)');

Iteration xl xu xr ea(%)

iteration = 0;

while ea> tol


xr= xu-((xu^3- 4*xu^2 + 6)*(xl-xu))/ ((xl^3-4*xl^2+6)-(xu^3- 4*xu^2+ 6));

ea= abs((xr-xr_prev)/xr)*100;

if (xl^3-4*xl^2+ 6)*(xr)<0
xu= xr;
elseif (xl^3-4*xl^2 +6)*(xr)>0
xl= xr;
else
break;
end

xr_prev = xr;
iteration = iteration + 1;

fprintf('%5d %10.6f %10.6f %10.6f %10.6f\n', iteration, xl, xu, xr, ea);
end

1 0.000000 -1.200000 -1.200000 100.000000


2 0.000000 -0.961538 -0.961538 24.800000
3 0.000000 -1.257674 -1.257674 23.546313
4 0.000000 -0.907380 -0.907380 38.604999
5 0.000000 -1.347449 -1.347449 32.659377
6 0.000000 -0.832707 -0.832707 61.815371
7 0.000000 -1.490968 -1.490968 44.149880
8 0.000000 -0.732882 -0.732882 103.439041
9 0.000000 -1.729783 -1.729783 57.631561
10 0.000000 -0.605371 -0.605371 185.739331
11 0.000000 -2.152113 -2.152113 71.870861
12 0.000000 -0.453171 -0.453171 374.901203
13 0.000000 -2.973172 -2.973172 84.758007
14 0.000000 -0.289402 -0.289402 927.352048
15 0.000000 -4.833411 -4.833411 94.012479
16 0.000000 -0.140530 -0.140530 3339.416313
17 0.000000 -10.311606 -10.311606 98.637167
18 0.000000 -0.040657 -0.040657 25262.362038
19 0.000000 -36.522681 -36.522681 99.888680

1
20 0.000000 -0.004054 -0.004054 900790.973129
21 0.000000 -369.624626 -369.624626 99.998903
22 0.000000 -0.000043 -0.000043 850757893.538002
23 0.000000 -34524.841053 -34524.841053 100.000000
24 0.000000 -0.000000 -0.000000 685702026469225.875000
25 0.000000 -Inf -Inf NaN

fprintf('\nApproximate root: %.6f\n', xr);

Approximate root: -Inf

fprintf('Function value at root: f(x) = %.6f\n', xr^3-4*xr^2+ 6);

Function value at root: f(x) = -Inf

You might also like