Calculating gradient of f in point A?

조회 수: 3 (최근 30일)
ABCDEFG HIJKLMN 2021년 11월 22일
댓글: Star Strider 2021년 11월 22일
Hello! I am trying to calculate the gradient of a function in a point, but I can't seem to do it.
I have calculated the gradient through the functions diff and gradient. Now I am trying to replace x1 and x2 by 5 and 6, respectively, to calculate the gradient in this point (called A) through any of the gradient functions, but MATLAB does not allow it.
Any help? Thanks in advance!
syms x1 x2
f = x1 + x2^2;
A = [5, 6];
f_grad_diff = [diff(f, x1), diff(f, x2)];

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider 2021년 11월 22일
Create them as functions —
syms x1 x2
f = x1 + x2^2;
A = [5, 6];
f_grad_diff(x1,x2) = [diff(f, x1), diff(f, x2)];
x1s = sym(5);
x2s = sym(6);
diff_evaluated =
The jacobian function is also an option.)
Are these the desired results?
.
댓글 수: 2없음 표시없음 숨기기
ABCDEFG HIJKLMN 2021년 11월 22일
These are exactly the desired results. Thank you!
Star Strider 2021년 11월 22일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by