How do I derive a parametric slope symbolically?

조회 수: 7 (최근 30일)
William Kett
William Kett 2020년 8월 14일
댓글: William Kett 2020년 8월 14일
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.
William Kett
William Kett 2020년 8월 14일
I see. Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (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