In this tutorial, we are going to solve the following two algebraic equations iteratively.
X₁ = X₂ - 1
X₂ = 2.5 X₁ - 0.5
Using fixed point iterative method and taking initial assumptions according to the question as, X₁ = X₂ = 0, the solutions do not converge with this present arrangement of equations. However, if we rearrange these equations in the following forms, the solutions indeed converge.
X2 = X1 + 1
X₁ = X₂ / 2.5 + 0.2
A MATLAB program has been developed to solve the modified equations iteratively by creating a user defined function called "iterative". This function may be used to solve other equations iteratively which is the essence of the user defined function. The previous forms of equations from the question are also fed into the program to see the solutions, but the program indicates divergence.
The following MATLAB program written in “m-file” subsequently enlightens essential commands in the program by additional notes.
MATLAB Codes:
% Definition of a function "iterative" to
solve equations iteratively
function [x1, x2, ea1, ea2] = iterative(X1, X2, etol1, etol2)
% Input X1=0, X2=0, etol1, etol2=Tolerance definition
for errors
% Output x1, x2=Solutions of equations, ea1, ea2=
Calculated errors in loop
% Program Initialization
solution1 = 0;
solution2 = 0;
% Iterative Calculations
while (1)
solutionprevious1 = solution1;
solutionprevious2 = solution2;
solution2 =
X1+1; % Problem equation 1
solution1 =
(X2/2.5)+0.2; % Problem equation 2
X1=solution1;
X2=solution2;
if solution1~=0 && solution2~=0
% Approximate percent relative errors
ea1=abs((solution1 - solutionprevious1)/solution1)*100;
ea2=abs((solution2 - solutionprevious2)/solution2)*100;
end
if ea1<=etol1 && ea2<=etol2, % Conditions to meet specified error tolerances
break,
end
x1 = solution1;
x2 = solution2;
end
% Display of output parameters
disp(x1);
disp(x2);
disp(ea2);
end
Outputs:
>> iterative (0,0,1e-5,1e-5) %
Command input at the MATLAB command prompt
1.0000
2.0000
3.4360e-06
8.5899e-06
Therefore, the solutions obtained from the program are X₁ = 1 and X₂ = 2. And, the approximate percent relative errors for finding X₁, X₂ are 3.4360e-06 and 8.5899e-06 respectively which also satisfy the condition mentioned in the program.