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

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

回答(1 个)

Walter Roberson
Walter Roberson 2015-11-30
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 个评论
Walter Roberson
Walter Roberson 2015-11-30
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by