solving a system of non-linear equations using Fixed point method

This is my question
Implement the Fixed-point method for solving a system of non-linear equations from scratch in MAT LAB and walk me through your thought process in constructing the code. Additionally, demonstrate that your implementation works by applying it to the following system. x^2 +y^2 +z^2 = 14, x^2−y^2= 2, x +y+z =4.
%ingredients
g = input(' Enter your function ');
x0 = input(' Enter initiak guess '); %x0=0
e = input(' Enter tolerance '); %10^(-4)
n = input(' Enter number of iterations '); %n=20
for i=1:n
x1 = g(x0);
fprintf(' x%d = %.4f\n ' ,i,x1)
if abs (x1-x0)<e
break
end
x0 = x1;
end
This is my code related to this question. Is this correct Please kindly pointout my mistakes...

2 Comments

What is the function you want to apply the fixed-point method to ? You didn't specify it in your code.

Sign in to comment.

 Accepted Answer

Hi Kumuthu,
The original code snippet was designed for a single equation, not a system of equations.
For the system of equations you have shared, we need to express each variable in terms of the others to use the Fixed-point iteration.
We can reformulate the shared equations to isolate each variable:
  • x = sqrt (2 + y^2)
  • y = sqrt (x^2 - 2)
  • z = 4 - x - y
Please refer to the following implementation for the same:
function fixed_point_method()
% Define 'g' for the system of equations
g = @(x) [sqrt(2 + x(2)^2); sqrt(x(1)^2 - 2); 4 - x(1) - x(2)];
% Example initial guess
x0 = [0; 0; 0];
% Tolerance and maximum number of iterations
e = 1e-4;
n = 20;
% Fixed-point iteration
for i = 1:n
x1 = g(x0);
fprintf('Iteration %d: x = %.4f, y = %.4f, z = %.4f\n', i, x1(1), x1(2), x1(3));
% Check for convergence
if norm(x1 - x0) < e
fprintf('Converged to solution: x = %.4f, y = %.4f, z = %.4f\n', x1(1), x1(2), x1(3));
break;
end
% Update the guess
x0 = x1;
end
% If did not converge
if i == n
fprintf('Did not converge within %d iterations.\n', n);
end
end
To know more about '@x', please refer to the following MATLAB Answers post:

3 Comments

@Rishav Please do not do a student's entire homework assignment for them. At most, when a student made no effort at all, give them some hints.
You are not helping the student by doing so. In fact, too many posters have been helping this student, and now this student is just posting every assignent they get with no effort made.
You do not help the forum, as it then urns the forum into a place where we are expected to continue to do homework assignments.
You do not help the student, who now thinks there is always some suckler out there, willing to do their homework for them.
@Rishav thank you very much and I got my mistakes.
For the system of equations you have shared, we need to express each variable in terms of the others to use the Fixed-point iteration.
That's not necessary. If you have a system of equations F(x) = 0, write it as x = F(x) + x, and you can apply fixed-point iteration. Whether it converges is a second question.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 17 Sep 2024

Commented:

on 17 Sep 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!