Borrar filtros
Borrar filtros

calculate the gradient f=@(x) (x(1)-2)^4​+(x(1)-2)^​2*x(2)^2+(​x(2)+1)^2

1 visualización (últimos 30 días)
siscovic
siscovic el 11 de Nov. de 2017
Respondida: Star Strider el 11 de Nov. de 2017
Hello, how to calculate the gradient, Hessian matrix, of this function.Thank you
f=@(x) (x(1)-2)^4+(x(1)-2)^2*x(2)^2+(x(2)+1)^2

Respuesta aceptada

Star Strider
Star Strider el 11 de Nov. de 2017
With the Symbolic Math Toolbox:
syms x1 x2
% f=@(x) (x(1)-2)^4+(x(1)-2)^2*x(2)^2+(x(2)+1)^2;
f = (x1-2)^4+(x1-2)^2*x2^2+(x2+1)^2;
Hf = hessian(f);
HF1 = matlabFunction(Hf, 'Vars', [x1 x2]);
HF2 = matlabFunction(Hf, 'Vars', {[x1 x2]});
The ‘HF1’ result returns a function of (x1,x2). The ‘HF2’ result returns a function of ‘in1’, where ‘in(:,1)=x1’ and ‘in(:,2)=x2’. Note that ‘in1’ is a row vector.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by