How can i find out the gradient of a function with two variables? I have created a symbolic polynomial expression of order two but the gradient function works only on matrices apparently. Is there a two variable equivalent function for sym2poly?

3 ビュー (過去 30 日間)
Say the polynomial is f= x^2+y^2-2*x*y+10 with sym var x and y.
  2 件のコメント
Abhishek Pandey
Abhishek Pandey 2016 年 8 月 11 日
I am using MATLAB 2007B and using gradient function with the exact line of code generates an error message..'Error using zeros, trailing string input must be a valid numeric class name'. Jacobian works perfectly though.. Thank you.
Star Strider
Star Strider 2016 年 8 月 11 日
My pleasure.
If my Answer solved your problem, please Accept it.

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

回答 (1 件)

Star Strider
Star Strider 2016 年 8 月 10 日
I am not certain what result you want. Both the gradient and jacobian functions will work for you:
syms x y
f = x^2 + y^2 - 2*x*y + 10;
Gf = gradient(f, [x y])
Jf = jacobian(f, [x y])
Gf =
2*x - 2*y
2*y - 2*x
Jf =
[ 2*x - 2*y, 2*y - 2*x]

カテゴリ

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