How can I take the time derivative of a function?

8 views (last 30 days)
I'm trying to solve a 1 DOF second order differential equation for theta(t),
theta_dd(t) = -(m1*g*sin(theta)+T2*sin(theta+beta)+m1*x_dd(t))/(m1*l1)
where beta and T2 are both function of theta, and x_dd(t) is a forcing function.
beta = @(theta) asin((l1/l2)*sin(theta));
T2 = @(theta) (m2*ydd+c*yd+k1*y+m2*g)./cos(beta(theta));
T2 is dependent on ydd(t), yd(t), y(t), and beta, again all of which are dependent of theta(t). My question is are how I can use matlab to define the first and second derivative of y(t).
y = @(theta) l1*(1-cos(theta))+l2*(1-cos(beta(theta)));
yd = @(theta) ...;
ydd = @(theta) ...;
I'm going to run this on simulink but i need to provide a function for T2.
Some have recommended using the symbolic toolbox but I'm not sure where to start.

Answers (1)

Guru Mohanty
Guru Mohanty on 8 May 2020
Symbolic toolbox can be used in your case. To do this you need to do the following steps.
  1. Declare the variables using syms.
  2. Build the expression.
  3. For derivative use diff function.
Here is a sample code for it.
syms theta
beta = asin((11*sin(theta))/12);
y = 11*(1-cos(theta))+12*(1-cos(beta))
yd = diff(y ,theta)
ydd = diff(yd ,theta)

Categories

Find more on Symbolic Math Toolbox 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!