フィルターのクリア

Calculating gradient of f in point A?

5 ビュー (過去 30 日間)
ABCDEFG HIJKLMN
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)];
f_grad_gradient = gradient(f);

採用された回答

Star Strider
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)];
f_grad_gradient(x1,x2) = gradient(f);
x1s = sym(5);
x2s = sym(6);
diff_evaluated = f_grad_diff(x1s,x2s)
diff_evaluated = 
gradient_evaluated = f_grad_gradient(x1s,x2s)
gradient_evaluated = 
The jacobian function is also an option.)
Are these the desired results?
.
  2 件のコメント
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN 2021 年 11 月 22 日
These are exactly the desired results. Thank you!
Star Strider
Star Strider 2021 年 11 月 22 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops 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