calculate the gradient f=@(x) (x(1)-2)^4+(x(1)-2)^2*x(2)^2+(x(2)+1)^2
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!