## Symbolic matlab: how to set a variable as a function of time?

### Sebastian D'Amico (view profile)

on 15 Feb 2012
Latest activity Answered by sharara rehimi

### sharara rehimi (view profile)

on 16 Aug 2018
Hello to all! I'm trying to set a symbolic variable as a function of "t". This is because I need to obtain something like this:
K>> diff(sin(theta),t)
ans = diff(theta,t)*cos(theta)
or
ans= theta_dot*cos(theta)
but how to tell Matlab that variable theta is a function of time "t"?
Thank you!

Ezequiel Garcia

### Ezequiel Garcia (view profile)

on 18 Apr 2017
You need to declare t as a "symbolic"
syms t;

### Wayne King (view profile)

on 15 Feb 2012

Hi Sebastian, do you know the expression for theta(t)?
syms theta t;
theta(t) = t^2;
diff(cos(theta),t)

### Sebastian D'Amico (view profile)

on 15 Feb 2012

Wayne, thank you for your answer! I don't have the expression of theta because I don't need it. This is the reason I need to tell Matlab that theta is a function of "t" so, when derivate is computed, it should consider that, for example, diff(sin(theta),t) is equal to diff(theta,t)*cos(theta). But, how to set it?
Seabstian

Wayne King

### Wayne King (view profile)

on 15 Feb 2012
Do you really need that if you do not know the expression for theta(t), you know df(theta)/dt = df/dtheta*dtheta/dt

### Walter Roberson (view profile)

on 15 Feb 2012

syms theta t
diff(sin(theta(t)),t)

Walter Roberson

### Walter Roberson (view profile)

on 19 Apr 2017
In newer versions of MATLAB, you can use
syms theta(t)
diff(sin(theta),t)