You are on page 1of 1

Archivo de Newton2D

% Iteracion de Newton 2D
clear, fprintf('\n')
dx = 0.01; dy = 0.01;
x = input('Estimacion inicial de x? ');
y = input('Estimacion inicial de y? ');
for n=1:50
s = [x,y];
xp = x + dx;
yp = y + dy;
J(1,1) = (f_f1(xp, y) - f_f1(x,y))/dx;
J(1,2) = (f_f1(x, yp) - f_f1(x,y))/dy;
J(2,1) = (f_f2(xp, y) - f_f2(x,y))/dx;
J(2,2) = (f_f2(x, yp) - f_f2(x,y))/dy;
f(1) = f_f1(x,y);
f(2) = f_f2(x,y);
ds = - J\f';
x = x + ds(1);
y = y + ds(2);
fprintf('n=%2.0f, x=%12.5e, y=%12.5e,', n,x,y)
fprintf('f(1)=%10.2e, f(2)=%10.2e\n', f(1), f(2))
if (abs(f(1))<1.0e-9 & abs(f(2))<1.0e-9), break; end
end

Archivo f_f1

function f = f_f1(x,y)
f = (sin(y)/2)*((1-2*x)+(x-1)*cos(y));

Archivo f_f2

function f = f_f2(x,y)
f = ((1-x)/2)*(x*cos(y)+((1-x)/2)*cos(2*y));

You might also like