Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
siscovic
siscovic le 11 Nov 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

Réponse acceptée

Star Strider
Star Strider le 11 Nov 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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by