ここにあなたが望むことをするいくつかのコードがあります.すべての説明はコメントにあります.
%// Firstly you need to define a function `f` in terms of `x` and `y`.
syms x y;
f = y^3*sin(x)+cos(y)*exp(x);
%// Then you need to tell Matlab that y is a function of x,
%// you do this by replacing y with y(x)
yOfx = sym('y(x)');
f_yOfx = subs(f, y, yOfx);
%// Then you need to differentiate with respect to x
df = diff(f_yOfx, x);
%// df will have diff(y(x), x) terms in it,
%// we want to solve for this term,
%// to make it easier we should first replace it with a variable
%// and then solve
syms Dy;
df2 = subs(df, diff(yOfx, x), Dy);
dyOver_dx = solve(df2, Dy);
%// Finally if we do not want all of the y(x) terms,
%// then replace them with y
dyOver_dx = subs(dyOver_dx, yOfx, y)
もちろん、ちょっとした紙の仕事を気にしないのであれば、dy/dx = -(partial f/partail x)/(partial f/partial y)
そこからはるかに短いコードを取得することができます
%// Implicit differentiation identity
also_dyOver_dx = -diff(f, x)/diff(f, y);
ここでは、2 つの答えが同じであることを確認します。
simplify(dyOver_dx - also_dyOver_dx) %// == 0