How do I derive a parametric slope symbolically?

8 次查看(过去 30 天)
I want to have matlab derive a parametric slope symbolically.
In other words, given x and y depend on some parameter, let's say t, if I want the parametric slope, I should get dy/dx = (dy/dt)/(dx/dt). I tried the following below to get this to work:
syms t x(t) y(t)
x = x(t)
y = y(t)
ParametricSlope = diff(y,x)
output:
Error using sym/diff (line 70)
Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
What do I need to change/add to get this to work?

采纳的回答

Walter Roberson
Walter Roberson 2020-8-14
编辑:Walter Roberson 2020-8-14
I wanted to know if Matlab is able to take the argument diff(y,x) given that x and y are functions of t, and derive and then output the equation diff(y,t)/diff(x,t) on its own. Can Matlab do that?
NO
MATLAB cannot take derivatives with respect to a function. Normal calculus cannot take derivative with respect to a function; you need Calculus of Variations for that.
It is often suggested to substitute a variable for the function, take the derivative with respect to the variable, and then substitute back the function for the variable in the result. However, in order for that to work, the two parts have to be independent, and that is something that you cannot guarantee when you do not know what the functions are.
The closest you can get is to take the hypothesis that the functions are independent, and do the substitution, derivative, substitution route, figure out what the function is, and then go back and test to see whether the derivative holds true.
At some point I posted a specific example of where the technique failed, but unfortunately I have long lost track of that example.
syms X
subs(diff(subs(f, x, X),X),X,x) %change function to symbol, take derivative, subs back
Reminder: this can give incorrect answers if the parts are not truly independent.
  3 个评论
Walter Roberson
Walter Roberson 2020-8-14
MATLAB's diff() cannot symbolically take the deriviative of a function with respect to a function, and there is no special function that might handle slopes of parametric curves .
The sequence I showed with subs is only valid some of the time; it works based on a hypothesis, and the hypothesis really should be re-validated once more information is known.
... Sort of like if you did a calculation on an expression that included a division, and you multiply through by the denominator as part of the processing, and solve, then you really should go back later and verify that the denominator was not zero.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2020-8-14
编辑:KSSV 2020-8-14
syms x(t) y(t)
slope = diff(y,t)/diff(x,t) % simple diff(y) can also be used
  2 个评论
William Kett
William Kett 2020-8-14
Thank you for getting back to me so quickly!
I think there might have been a misunderstanding. I wanted to know if Matlab is able to take the argument diff(y,x) given that x and y are functions of t, and derive and then output the equation diff(y,t)/diff(x,t) on its own. Can Matlab do that?
P.S. I am new to Matlab and am primarily using it as a CAS to perform symbolic derivations.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by