필터 지우기
필터 지우기

how to work with a variable as a function of time?

조회 수: 39 (최근 30일)
Imanol Fernandez de arroyabe Zabala
댓글: Walter Roberson 2023년 1월 14일
I know you can set a variable as a function of other variable and differentiate it by doing the following:
syms theta(t)
diff(sin(theta),t)
ans(t) = 
However, I still have three questions:
  • Why is it being shown as a partial derivative even though I set the variable as a single-variable function?
  • Is there any way to change the notation so that it shows up like this:
  • Can I work with the differentiated variable? (assign a solution to it, etc...)
Thanks in advance

채택된 답변

Walter Roberson
Walter Roberson 2023년 1월 14일
Changing the notation:
syms theta(t)
dtheta = diff(theta,t)
dtheta(t) = 
derivative = diff(sin(theta),t)
derivative(t) = 
syms theta_dot(t)
subs(derivative, dtheta, theta_dot)
ans(t) = 
However, MATLAB has lost any connection between diff(theta,t) and theta_dot . If you were to construct
syms theta_ddot(t)
d2theta = diff(dtheta,t)
d2theta(t) = 
eqn = 2*d2theta - 5*dtheta == 1
eqn(t) = 
pretty_eqn = subs(eqn, {d2theta, dtheta}, {theta_dot, theta_ddot})
pretty_eqn(t) = 
Here, pretty_eqn might look nice, but dsolve() will not know that the two functions are related
  댓글 수: 2
Imanol Fernandez de arroyabe Zabala
편집: Imanol Fernandez de arroyabe Zabala 2023년 1월 14일
Thanks!
I asked this because I'm doing a physics project and I need to work with angular positions and accelerations. Do you know if I can then use the solve function in order to get the values for the differentiated theta? (angular velocity and acceleration that is). And let me clarify: I wouldn't want the program to solve the differential equation, but rather to treat the differentiated theta as a new variable and for the program to give me a symbolic answer.
Walter Roberson
Walter Roberson 2023년 1월 14일
solve() will not solve with respect to a function. You would need to substitute a variable for the function and then solve() for the variable.
syms theta(t)
dtheta = diff(theta,t)
dtheta(t) = 
derivative = diff(sin(theta),t)
derivative(t) = 
syms theta_dot theta_ddot
d2theta = diff(dtheta,t)
d2theta(t) = 
eqn = 2*d2theta - 5*dtheta == 1
eqn(t) = 
pretty_eqn = subs(eqn, {d2theta, dtheta}, {theta_dot, theta_ddot})
pretty_eqn(t) = 
sol = solve(pretty_eqn, theta_ddot)
sol = 
%pretty, but of limited value, you have to switch back to get anywhere
dsolve(d2theta == subs(sol, theta_dot, dtheta))
ans = 

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

추가 답변 (1개)

John D'Errico
John D'Errico 2023년 1월 14일
편집: John D'Errico 2023년 1월 14일
Why MATLAB shows a partial derivative there, and not an ordinary derivative?
syms theta(t)
dTdt = diff(theta,t)
dTdt(t) = 
Technically, a partial derivative is just a superset of ordinary differentiation. While it tends to imply that theta is a function of other variables too, it costs nothing to write only the one operator there, and it saves them some extra work in coding, since then the display is simpler.
Is there a way to use the over-dot notation? No. That is not an option. Again, it would just add complexity, creating the possibility of bugs, and increase development time. There are way more important things I would want to see them invest their available person-years on than giving the user multiple ways to show exactly the same thing.
Can you assign something to a differentiated variable? Not really in any useful way, at least not if you want to use it as a container, but also have MATLAB know where it came from. For example, we see that dTdt initially contains the derivative of theta. But suppose you now decide to do this:
dTdt(t) = 3*t
dTdt(t) = 
As you can see, MATLAB now sees dTdt is just a simple function of t, but it no longer thinks or remembers that it was also the derivative of theta. That connection to theta has been lost.
Can you use the derivative in an ODE, so maybe what you are asking? Yes, but I don't think that was at all your question.
ODE = diff(theta) == 3*t
ODE(t) = 
dsolve(ODE,theta(0) == 2)
ans = 
But that is not really assigning something to the derivative expression.
So I'm not really sure what you are hoping to do in your third question.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by