Implicit derivative with Matlab symbols

1 view (last 30 days)
Is it possible to have MATLAB do implicit differentiation with its symbols? I have the following code
syms x;
y = symfun(sym('y(x)'), sym('x'));
yPrime = symfun(sym('y+(2*x)-1'), [sym('x'), sym('y')]);
diff(yPrime, x, 1)
From this I get
ans(x, y) =
2
but what I want to get (in some form) is
ans(x, y) =
dy/dx + 2
Is that possible?
  3 Comments
Vyas Ramasubramani
Vyas Ramasubramani on 12 Nov 2015
I figured out the problem, it was not related to the version. My issue twofold: first, when I create yPrime I'm declaring it as a function of sym('y'), which redeclares y as a different variable from the prior y(x); and second, in my actual function definition I needed to make it y(x)+2*x-1 instead of just y+(2*x)-1
Walter Roberson
Walter Roberson on 12 Nov 2015
The MATLAB version does matter because the way to write your code cleanly would depend upon how old your MATLAB is.

Sign in to comment.

Answers (1)

Vyas Ramasubramani
Vyas Ramasubramani on 12 Nov 2015
I figured out the problem, it was not related to the version. My issue twofold: first, when I create yPrime I'm declaring it as a function of sym('y'), which redeclares y as a different variable from the prior y(x); and second, in my actual function definition I needed to make it y(x)+2*x-1 instead of just y+(2*x)-1

Community Treasure Hunt

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

Start Hunting!