How do I derive a parametric slope symbolically?

9 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 14 Ago 2020
Modificato: Walter Roberson il 14 Ago 2020
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 Commenti
Walter Roberson
Walter Roberson il 14 Ago 2020
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.
William Kett
William Kett il 14 Ago 2020
I see. Thank you for your help!

Accedi per commentare.

Più risposte (1)

KSSV
KSSV il 14 Ago 2020
Modificato: KSSV il 14 Ago 2020
syms x(t) y(t)
slope = diff(y,t)/diff(x,t) % simple diff(y) can also be used
  2 Commenti
William Kett
William Kett il 14 Ago 2020
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.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by