MATLAB Diff EQ Help: Solve ODE for b=0, b=2, b=8, b=10 & k(t)=16e^-LT

  • Context: MATLAB 
  • Thread starter Thread starter gob71
  • Start date Start date
  • Tags Tags
    Diff eq Matlab
Click For Summary

Discussion Overview

The discussion revolves around solving an ordinary differential equation (ODE) related to mass-spring motion using MATLAB. Participants explore various cases of damping (no damping, underdamping, critical damping, and overdamping) and the effect of a time-dependent spring constant on the motion of the mass. The scope includes theoretical analysis, numerical methods, and MATLAB coding challenges.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant outlines the ODE governing mass-spring motion and specifies initial conditions for different damping scenarios.
  • Another participant questions the initial conditions, suggesting that a small initial velocity is necessary for the mass to move.
  • Participants express difficulties in implementing MATLAB code to solve the ODE, particularly with undefined variables and global parameters.
  • There is a discussion about the relationship between the parameter L and the behavior of the spring constant over time, with some suggesting that increasing L leads to larger oscillations.
  • One participant provides a MATLAB code snippet to help solve the ODE, while another shares a Mathematica solution as a comparison.
  • Frustration with MATLAB's complexity is expressed, with some participants preferring other software like Mathematica or Maple for such tasks.

Areas of Agreement / Disagreement

Participants generally agree on the need to solve the ODE for various damping scenarios and the effect of a time-dependent spring constant. However, there is disagreement regarding the initial conditions and the effectiveness of MATLAB as a tool for this problem. The discussion remains unresolved regarding the best approach to implement the solution in MATLAB.

Contextual Notes

Some participants mention specific issues with MATLAB code, such as undefined variables and the use of global parameters, which may limit the ability to test different values of L effectively. The discussion also highlights the potential for different software tools to yield solutions more easily.

gob71
Messages
3
Reaction score
0
I am new to MATLAB and need help with a problem. we have tried
several different methods and each time can't make sense of what is going on wrong

" A mass spring motion is governed by the ordinary differential
equation m(dx^2/dt^2) + b(dx/dt) + kx=F(t) , where m is the mass, b
is the damping constant, k is the spring constant, and F(t) is the
external force."
Assume the following m=1 kg, k= 16 N/m, and F(t)=0, x(0)=0, x'(0)=0.
Solve the ODE on the interval [0,20] for the following cases.

a). b=0 -no damping
b). b=2- under damping
c). b=8 - critical damping
d). b=10 - over damping

2.
Set the damping constant equal to 0, b=0, and consider an agiing spring whose spring constant depends on time as follows

k(t)=16e^-LT

Predict the motion of the mass, i.e. show time plots and phase plots and discuss your results for the following cases.

a. L=0
b. L=0.1
c. L=0.3



3.
Set b = 1/5 k=1/5 and assume a forcing F(t) = coswt,

a. Use ODE45-solver to obtain the solution curves for several values of w between .5 and 2. Plot the solutions and estimate the amplitude A of the steady response in each case.

b. Using the data from part (a) plot the graph of A vs. w. For what frequency W is the amplitude greatest?
 
Physics news on Phys.org
gob71 said:
I am new to MATLAB and need help with a problem. we have tried
several different methods and each time can't make sense of what is going on wrong

" A mass spring motion is governed by the ordinary differential
equation m(dx^2/dt^2) + b(dx/dt) + kx=F(t) , where m is the mass, b
is the damping constant, k is the spring constant, and F(t) is the
external force."
Assume the following m=1 kg, k= 16 N/m, and F(t)=0, x(0)=0, x'(0)=0.
Solve the ODE on the interval [0,20] for the following cases.

a). b=0 -no damping
b). b=2- under damping
c). b=8 - critical damping
d). b=10 - over damping

Hey Gob, you got to push that spring dude. Think about it: You have a mass on a spring sitting there. It has no external force, you don't displace it, and you don't give it an initial velocity. It's not going anywhere, i.e. the only solution is y(x)=0. Are you sure you have the initial conditions right? How about just a little push, say y'(0)=0.1. That'll get it going. :smile:
 
saltydog said:
Hey Gob, you got to push that spring dude. Think about it: You have a mass on a spring sitting there. It has no external force, you don't displace it, and you don't give it an initial velocity. It's not going anywhere, i.e. the only solution is y(x)=0. Are you sure you have the initial conditions right? How about just a little push, say y'(0)=0.1. That'll get it going. :smile:
your right, the intial conditions are x(0)=1, x'(0)=0


the first answer is solved...we are having problems with #2

or m file looks something like this

function out=spring2(t,u)
global l m b k
out(1)= u(2);
out(2)= 16 exp(-l*t)
out=out';

trying to run it it gives us u is undefined and we can't figure out what is wrong, and we can't even get to the global part to where we can sub in our different l values
 
gob71 said:
your right, the intial conditions are x(0)=1, x'(0)=0


the first answer is solved...we are having problems with #2

or m file looks something like this

function out=spring2(t,u)
global l m b k
out(1)= u(2);
out(2)= 16 exp(-l*t)
out=out';

trying to run it it gives us u is undefined and we can't figure out what is wrong, and we can't even get to the global part to where we can sub in our different l values

Sorry, can' help with MatLab. I use Mathematica.
 
You know Gob, it makes sense: as you increase the value of L, the rate at which the spring constant decreases, increases right for:

[tex]k(t)=e^{-Lt}[/tex]

and with no dampening, as the spring "constant" decreases, the oscillations will get larger, quicker for increasing L. That's what it looks like to me anyway. Can't you just do a numerical solve of the three ODEs with the three values of L in MatLab and plot the results?. In Mathematica it's a breeze.
 
saltydog said:
You know Gob, it makes sense: as you increase the value of L, the rate at which the spring constant decreases, increases right for:

[tex]k(t)=e^{-Lt}[/tex]

and with no dampening, as the spring "constant" decreases, the oscillations will get larger, quicker for increasing L. That's what it looks like to me anyway. Can't you just do a numerical solve of the three ODEs with the three values of L in MatLab and plot the results?. In Mathematica it's a breeze.

matlab blows a big one, heck i even like maple more...this thing is killin me and we are about to go nuts
 
gob71 said:
matlab blows a big one
Blasphemy!

I don't really understand the MATLAB code you provided. Is that your function for the ode solver? If you could post anything else you have or more specific problems it may help.


A quick starter for you
Code:
% PF for gob71
% x(t) is position, y(t)=dx/dt=velocity
clear all;

dt = 0.0005; % Time step size
t = 0:dt:20; % Vector of time values

% Constants & Parameters
m = 1; k = 16; b = 0; w = 0; F = 0; L = 0.0;
y(1)=0; yold = y(1); % Initial Velocity
x(1)=1; xold = x(1); % Initial Position

% Real men write their own ODE solvers
for i = 2:length(t)
    k = exp(-L*t(i));
   % F = cos(w*i);
    x(i) = (m*xold/dt^2 + b*xold/dt + m*yold/dt + F) / (m/dt^2 + b/dt + k);
    y(i) = (x(i)-x(i-1))/dt;
    xold = x(i); yold = y(i);
end

%figure;plot(t,x,t,cos(1*t))
figure;plot(t,x)

A few quick checks for your solution.
x'' + b/m*x' + k/m*x = F/m
If b=F=0 and m=1, then when k=16, x(t)=cos(4t), and when k=exp(0*t), x(t)=cos(1*t)
 
Why, when you can do this: 1,2,3, done . . .
Code:
L=0.1
sol1 = NDSolve[{x''[t] + 16 e^{-L t} x[t] == 0, 
      x[0] == 1, x'[0] == 0}, x, {t, 0, 20}]
f[t_] := Evaluate[x[t] /. Flatten[sol1]];
Plot[f[u], {u, 0, 20}]

The plots are for L=0.1, 0.2, 0.3 respectively.
 

Attachments

  • 01.JPG
    01.JPG
    8.3 KB · Views: 635
  • 02.JPG
    02.JPG
    7.4 KB · Views: 673
  • 03.JPG
    03.JPG
    5.8 KB · Views: 621
Last edited:

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K