How can I run this code for Fixed point iteration with given functions?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 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 Kommentare
Walter Roberson
am 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);
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!