How can I run this code for Fixed point iteration with given functions?
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 30 Nov 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 Comments
Walter Roberson
on 30 Nov 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);
See Also
Categories
Find more on Preprocessing Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!