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

In summary, the conversation is about solving a mass spring motion equation with different values for the damping constant. The conversation also discusses predicting motion and amplitude for different cases. The speakers also mention using MATLAB and Mathematica for solving the equation.
  • #1
gob71
3
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
  • #2
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:
 
  • #3
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
 
  • #4
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.
 
  • #5
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.
 
  • #6
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
 
  • #7
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)
 
  • #8
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: 538
  • 02.JPG
    02.JPG
    7.4 KB · Views: 566
  • 03.JPG
    03.JPG
    5.8 KB · Views: 540
Last edited:

Question 1: How can I solve an ODE in MATLAB for different values of b and a given function k(t)?

To solve an ODE for different values of b and a function k(t) in MATLAB, you can use the ode45 function. This function takes in the ODE, initial conditions, and a vector of values for b, and returns the solution for each value of b. You can then use a loop to iterate through the values of b and plot the solutions.

Question 2: What does the b=0, b=2, b=8, b=10 in the ODE represent?

The b values in the ODE represent a parameter that affects the behavior of the system. In this case, it could represent a constant in the ODE or a coefficient in the function k(t). By solving the ODE for different values of b, you can observe how this parameter affects the solution.

Question 3: What is the significance of the function k(t)=16e^-LT in the ODE?

The function k(t)=16e^-LT in the ODE represents a time-dependent external input or forcing function. This could represent an external force, temperature, or any other variable that affects the behavior of the system and varies with time. By including this function in the ODE, you can observe how the system responds to changes in this input over time.

Question 4: Can I solve this ODE for other values of b and k(t)?

Yes, you can solve this ODE for any values of b and k(t) that you want using the ode45 function. You can also change the ODE itself to include other parameters or functions. MATLAB allows for flexibility in solving ODEs and gives you the ability to explore different scenarios and parameters.

Question 5: How accurate are the solutions obtained from solving this ODE with MATLAB?

The accuracy of the solutions will depend on the accuracy of the ODE, initial conditions, and the step size used in the ode45 function. Generally, MATLAB's ODE solvers are quite accurate and can handle a wide range of ODEs. However, it is always recommended to check the accuracy of the solutions by comparing them to known analytical solutions or by varying the step size.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
17
Views
277
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Introductory Physics Homework Help
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top