How to solve spring-mass ODE in rotating frame (without symbolic toolbox)

Hi,
I am trying to solve the ODE of a spring & mass in the rotating frame.
The equations of motion are as follows:
mx'' = -kx + 2my'w + m(x + e)w^2
my'' = -ky - 2mx'w + myw^2
here the "eccentric mass" is aligned with the x axis.
Given a set of initial conditions - what tool can i use in MATLAB to solve for x(t), y(t)?
Any help would be greatly appreciated!!!
Thanks!

 Accepted Answer

Start off trying the ode45 function. Use the "Solve Nonstiff Equation" and "ODE with Time-Dependent Terms" examples on that documentation page as a model for writing your own ODE function and pass a function handle to that ODE function into ode45 as the first input argument.
If ode45 doesn't work or takes too long, try a stiffer solver from the table in the Basic Solver Selection section on this documentation page.

3 Comments

Thank you for the direction!
I have pout together the following:
function [t,y] = SDRF(k, m, w, e, initialRad, initialRadVel, initialAngle, ti, tf) % ‘SDRF’ for ‘Spring-Mass Rotating Frame’
% Physical Parameters
% k = 1; % stiffness, lbf/in
% m = 5; % mass, lbm
% w = 0.007; % rotational speed, rad/s
% e = 2; % mass eccentricity
% Initial Conditions
%initialRad = 1.3;
%initialRadVel = 0;
%initialAngle = pi/4;
initialAngleVel = w;
%ti = 0;
%tf = 120;
% initial X, initial X', initial Y, initial Y'
ic = [initialRad; initialRadVel; initialAngle; initialAngleVel];
tspan = [ti tf];
% Equations of motion
% y(1) = X1
% y(2) = X2 = X1'
% y(3) = Y1
% y(4) = Y2 = Y1'
[t,y] = ode45(@odefun, tspan, ic);
function dydt = odefun(t,y)
dydt = zeros(4,1);
dydt(1) = y(2);
dydt(2) = -(k/m)*y(1)+2*y(4)+(y(1)+e)*w^2;
dydt(3) = y(4);
dydt(4) = -(k/m)*y(3)+2*y(2)+y(3)*w^2;
end
%plot(t,y,'-o')
end
I am not quite getting what i want out of the output - but can you confirm that the function was set up properly as intended per original post? if that is set up properly i can fiddle with the rest!
Thanks so much!
It looks like you are missing a w in your odefun for the 2my'w and 2mx'w terms. Also the sign of one of the terms looks incorrect. Try this:
dydt(2) = -(k/m)*y(1) + 2*y(4)*w + (y(1)+e)*w^2;
:
dydt(4) = -(k/m)*y(3) - 2*y(2)*w + y(3)*w^2;
Thank you! You are right, i was missing the w, and the sign was wrong on the 2nd term of the 4th dydt eqn.

Sign in to comment.

More Answers (0)

Products

Release

R2010b

Asked:

on 31 May 2018

Commented:

on 31 May 2018

Community Treasure Hunt

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

Start Hunting!