How to tell matlab that y is a function of x; not a constant

2 ビュー (過去 30 日間)
Ayan PATSA
Ayan PATSA 2021 年 5 月 7 日
コメント済み: Star Strider 2021 年 5 月 8 日
I have a function z such that z=xy(x) , [i.e. y is a function of x]. So if I differentiate z with respect to x, I shoud get dz/dx= y+x*(dy/dx). However if I use diff(z,x) in matlab, I get only y [matlab treats y as a constant]. What should I do to define y as a function of x?
syms x y z
z=x*y;
diff(z,x)
ans =
y

採用された回答

Star Strider
Star Strider 2021 年 5 月 7 日
In the initial syms call, declare ‘y(x)’ instead of ‘y’
syms x y(x) z
z=x*y;
Dz = diff(z,x) % Create Assignment
Dz(x) = 
Note that now ‘Dz’ is also a funciton of ‘x’, as it should be.
  2 件のコメント
Ayan PATSA
Ayan PATSA 2021 年 5 月 8 日
Thank you..It works.
Star Strider
Star Strider 2021 年 5 月 8 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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