Error using ode45 for spring pendulum

4 views (last 30 days)
Mathew Amador
Mathew Amador on 3 Apr 2020
Commented: darova on 4 Apr 2020
Hello there, I was developing an example for class of a spring pendulum that was to utilize the ode45 command on MATLAB. Problem is, that somehow the ode45 keep encountering errors and I can't seem to figure out why this is the case. Anyone have any insight?
  3 Comments
Mathew Amador
Mathew Amador on 4 Apr 2020
Edited: Mathew Amador on 4 Apr 2020
"Solve for the EOMs of a spring pendulum system, then integrate the EOM for 10 seconds starting at rest with the radial position at and . The spring is unstretched at . Then, integrate the EOM for 120 seconds starting at rest with a variety of initial conditions with in meters and in degrees."
Goal: Plot the initial position of the mass using a blue line with 'x' markers and the final position of the mass using a black line with 'x' markers.
Step 1:
clear variables
clc
m = 0.1416; % kg
k = 7.1; % N/m
g = 9.81; % m/s^2
r_0 = 9; % cm
r = 29; % cm
theta = 30; %degrees
Step 2:
List variables:
m: mass,
k: spring constant,
r: radius,
r_0 : unstretched radius,
theta : Initial angular displacement,
g: gravity,
r_m: linear displacement of mass in the r-direction, state variable
r_mddot: accelerations (EOMs) of the mass in the r-direction
theta_m: displacement of mass in the -direction, state variable
theta_mddot: accelerations (EOMs) of the mass in the -direction
Step 3:
syms m l r
syms thetadot thetaddot rdot rddot
eqn(1) = m*thetaddot == m*((l+r)*thetaddot+2*rdot*thetadot);
eqn(2) = m*rddot == m*(rddot-(l+r)*thetadot^2);
Step 4:
Find Unknown variables
theta double dot, and r double dot : accelerations in the theta and r directions, respectively
2 equations, 2 unknowns
Step 5:
unknowns = solve(eqn, rddot, thetaddot)
accelEOMs = solve(eqn,rddot,thetaddot);
accelEOMs = struct2cell(accelEOMs);
Step 6:
Solve equation of motion (EOM)
[T,S] = ode45(@(t,s)eom(m, k, r, r_0, theta, g),linspace(0,10,100),[0,0]);

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!