How can I take the time derivative of a function?

조회 수: 8 (최근 30일)
Dorian Grey-Angeles
Dorian Grey-Angeles 2020년 4월 30일
답변: Guru Mohanty 2020년 5월 8일
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.

답변 (1개)

Guru Mohanty
Guru Mohanty 2020년 5월 8일
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)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by