minimum using Newton method (matlab)

1.2k Views Asked by At

I am given this function: $$f(x,y)=\frac { 1 }{ 2 } { (x-1) }^{ 2 }+\frac { 1 }{ 2 } { (10(y−{ x }^{ 2 })) }^{ 2 }+\frac { 1 }{ 2 } { y }^{ 2 }$$ and I tried to write the code below to find the minimum using Newton method, but it doesn't seem to work. I think it can not assign the new value of variables but I don't know why.

syms a;

syms b;

g=gradient(vrosenbrock(a,b));

x=-1;

y=-1;

z=0;

i=1;

H=hessian(vrosenbrock(a,b));

while norm(subs(g,[a,b],[x,y])) > 10e-3

z=[x,y]-((subs(inv(H),[a,b],[x,y]))*((subs(g,[a,b],[x,y])))).' ;
x=z(1); y=z(2);
i=i+1;

end

[x y]

And as function I've saved this already:

function z = vrosenbrock(x,y)

FUN = 1;

if FUN == 1

z = 0.5*(10*(y - x.^2)).^2 + 0.5*(1-x).^2 + 0.5*y.^2;

elseif FUN == 2

z = (10*(y - x.^2)).^2 + (1-x).^2;

end

end