フィルターのクリア

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

1 回表示 (過去 30 日間)
siscovic
siscovic 2017 年 11 月 11 日
回答済み: Star Strider 2017 年 11 月 11 日
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

採用された回答

Star Strider
Star Strider 2017 年 11 月 11 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by