フィルターのクリア

how i can have gradient of a multivariate function like f(x,y) in a single function?

6 ビュー (過去 30 日間)
i define multivariate function f by syms order and wish have gradient f in especial point like x0 and i can not use from for loop
for example :
syms f(x,y)
f(x,y)=x^2+y^2,x0=(1,1)
i wish have
g=f'(x,y)
then
g(1,1)=[2,2]

採用された回答

Brendan Hamm
Brendan Hamm 2015 年 7 月 10 日
編集済み: Brendan Hamm 2015 年 7 月 10 日
If you want this for a specific function you can just create the function directly:
>> g = @(x,y) [2*x,2*y];
>> g(1,1)
ans =
2 2
Using the symbolic toolbox you can do the following:
syms x y
f = x^2 + y^2;
g = gradient(f,[x y]);
subs(g,[x y],[1,1])
or if you really wanted this in a single function:
syms x y
f = x^2 + y^2;
g = @(x0,y0) subs(gradient(f,[x y]),[x y],[x0 y0]);
  1 件のコメント
xosro
xosro 2015 年 7 月 10 日
編集済み: xosro 2015 年 7 月 10 日
tank you about your answer but my new problem is i do not know number of variables f because f is my input of my code then i can not write if x=[1;1]; g(x)

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by