How can I run this code for Fixed point iteration with given functions?

function x = FixedPtSys(G, x0, tol, maxit)
disp([0 x0]); y = feval(G, x0);
xnew = y'; % the next solution
dif = norm(xnew - x0);
if dif <= tol
x = xnew; return;
else
xold = xnew;
end
disp( [1 xnew dif ]);
iter = 2;
while (iter <= maxit)
y = feval(G, xold); xnew = y'; dif = norm(xnew - xold);
if dif <= tol
x = xnew;
disp(' Fixed-point iteration converged'); return;
else
xold = xnew;
end
disp( [ iter xnew dif ]);
iter = iter + 1;
end
disp(' Fixed-point iteration did not converge')
x = xold
Given functions:
f(x,y,z) = x^2 + 20x + y^2 + z^2 -20 = 0
g(x,y,z) = x^2 + 20Y + z^2 - 20 = 0
h(x,y,z) = x^2 + y^2 -40z = 0

Réponses (1)

funs = @(x,y,z) ...
[x.^2 + 20*x + y.^2 + z.^2 - 20;
x.^2 + 20*y + z.^2 - 20;
x.^2 + y.^2 - 40*z];
FixedPtSys(@(xyz) funs(xyz(1), xyz(2), xyz(3), .......)

2 commentaires

please show me how you run the code.
funs = @(x,y,z) ...
[x.^2 + 20*x + y.^2 + z.^2 - 20;
x.^2 + 20*y + z.^2 - 20;
x.^2 + y.^2 - 40*z];
G = @(xyz) funs(xyz(1), xyz(2), xyz(3));
x0 = rand(1,3);
tol = 1e-8;
maxiter = 20;
x = FixedPtSys(G, x0, tol, maxiter);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by