Páginas

newton raphson optimizacion nro 10

clc
clear all
syms x y
f=-((x-2)^2)-x-y^2
dfx=diff(f,x);
dfy=diff(f,y);
dfxx=diff(dfx,x);
dfxy=diff(dfx,y);
dfyx=diff(dfy,x);
dfyy=diff(dfy,y);
grad=[dfx; dfy];
hess=[dfxx dfxy;dfyx dfyy];
sol=[x y]'-inv(hess)*grad;
tol=0.001;
error =20;
x=1;
y=1;
fprintf(' x0= %15.5f y0 = %15.5f \n',x,y)


disp(' x y error ')
disp('-----------------------------------------------------')
while error>tol
x1=eval(sol(1));
y1=eval(sol(2));
f1=-((x1-2)^2)-x1-y1^2
error=abs(f1)-abs(eval(f);
fprintf(' %15.5f %15.5f %15.5f\n',x1,y1,error)
x=x1;
y=y1;
end

No hay comentarios.:

Publicar un comentario