MATLAB: Finding gradient in MATLAB

MATLABoptimization

If the gradient of
100*(y - x^2)^2 + (1 - x)^2
is,
[-400*(y - x^2)*x - 2*(1 - x); 200*(y - x^2)]
what would be the gradient of
(1 - x + a)^2 + 100*(y - b - (x-a)^2)^2;

Best Answer

syms a b x y
J = jacobian( (1 - x + a)^2 + 100*(y - b - (x-a)^2)^2, [x,y])
G = gradient( (1 - x + a)^2 + 100*(y - b - (x-a)^2)^2, [x,y])
J =
[ 2*x - 2*a - 200*(2*a - 2*x)*(b - y + (a - x)^2) - 2, 200*y - 200*b - 200*(a - x)^2]
G =
2*x - 2*a - 200*(2*a - 2*x)*(b - y + (a - x)^2) - 2
200*y - 200*b - 200*(a - x)^2
Related Question