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

19 次查看(过去 30 天)
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...

采纳的回答

Rishav
Rishav 2024-9-17
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 个评论
Torsten
Torsten 2024-9-17
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by