how to work with a variable as a function of time?
Show older comments
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
Accepted Answer
More Answers (1)
John D'Errico
on 14 Jan 2023
Edited: John D'Errico
on 14 Jan 2023
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.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

