how to work with a variable as a function of time?
56 次查看(过去 30 天)
显示 更早的评论
Imanol Fernandez de arroyabe Zabala
2023-1-14
评论: 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)
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
0 个评论
采纳的回答
Walter Roberson
2023-1-14
Changing the notation:
syms theta(t)
dtheta = diff(theta,t)
derivative = diff(sin(theta),t)
syms theta_dot(t)
subs(derivative, dtheta, theta_dot)
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)
eqn = 2*d2theta - 5*dtheta == 1
pretty_eqn = subs(eqn, {d2theta, dtheta}, {theta_dot, theta_ddot})
Here, pretty_eqn might look nice, but dsolve() will not know that the two functions are related
2 个评论
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)
derivative = diff(sin(theta),t)
syms theta_dot theta_ddot
d2theta = diff(dtheta,t)
eqn = 2*d2theta - 5*dtheta == 1
pretty_eqn = subs(eqn, {d2theta, dtheta}, {theta_dot, theta_ddot})
sol = solve(pretty_eqn, theta_ddot)
%pretty, but of limited value, you have to switch back to get anywhere
dsolve(d2theta == subs(sol, theta_dot, dtheta))
更多回答(1 个)
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)
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
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
dsolve(ODE,theta(0) == 2)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!