How to find theta and theta dot in a simple pendulum simulation in MATLAB.

21 views (last 30 days)
I am simulating a simple pendulum and trying to find the theta value and angular velocity value at a certain time. Here is my code as of right now:
t = 10; %seconds
L = 10; %meters
g = 9.81; %m/s^2
m = 1; %kg
syms m a g theta(t)
eqn = m*a == -m*g*sin(theta);
syms L
eqn = subs(eqn,a,L*diff(theta,2));
eqn = isolate(eqn,diff(theta,2));
syms omega_0
eqn = subs(eqn,g/L,omega_0^2);
syms x
approx = taylor(sin(x),x,'Order',2);
approx = subs(approx,x,theta(t));
eqnLinear = subs(eqn,sin(theta(t)),approx);
syms theta_0 theta_t0
theta_t = diff(theta);
cond = [theta(0) == theta_0, theta_t(0) == theta_t0];
assume(omega_0,'real')
thetaSol(t) = dsolve(eqnLinear,cond)
omega_0Value = sqrt(g/L);
T = 2*pi/omega_0Value;
theta_0Value = 0.1*pi; % Solution only valid for small angles.
theta_t0Value = 0; % Initially at rest.
vars = [omega_0 theta_0 theta_t0];
values = [omega_0Value theta_0Value theta_t0Value];
thetaSolPlot = subs(thetaSol,vars,values);
I am having trouble having the code actually spit out a theta and theta dot value. Is my coding approach way off to solve this problem? If so, what changes do I need to make to get the correct answer. Attached below is the problem I am trying to solve.

Answers (1)

Jim Riggs
Jim Riggs on 12 Feb 2020
I'm not sure at all what your system equations are.
The first rule of dynamics is where you have translational modes of motion you use linear equations of motion, and where you have angular modes of motion, you use rotational dynamic equations (this makes life much easier). So, the pendulum problem should be specified using rotary dynamics.
Matlab Answers 20200211.JPG
Note that the angular acceleration is in the opposite direction to the angle, therefore it has the minus sign. The differential equation governing this system may be written (from the preceeding) as;
Matlab Answers 20200211a.JPG
This should be your starting point.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!