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

6 visualizaciones (últimos 30 días)
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

Respuestas (1)

Walter Roberson
Walter Roberson el 30 de Nov. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 30 de Nov. de 2015
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);

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by