Reputation: 11830
If I've got a second-order differential equation in terms of a first-order differential that describes a mass-spring-damper system, how can I use Euler's method to plot this equation when I don't know the first-order differential? I'm wanting to do this in MatLab. This is a homework question so I haven't posted any code.. I just want a brief outline of how you're meant to do it.
The second-order derivative is d2(t+1) = (-1/m)*(c*d1+k*y) where c, m, k are constants, y is initially 1 and d1 is the first-order differential that starts at 0 and t is the time.
Any ideas?
Thanks :).
Upvotes: 1
Views: 3381
Reputation: 5595
There is an analytic solution of the form (x(t),x'(t)) = exp(A t)*(x(0), x'(0)), where A is a 2x2 matrix. If you aren't required to use matlab's ODE solver, this is the right way to find the time evolution of the system.
To find A, write your system in this form
so here A = [0 1; -k/m -c/m]
setting k/m = 1, and c/m = 0.1, we can write
t = linspace(0,20, 1000);
A = [0 1; -1 -0.1];
for j = 1:length(t); x(j,:) = expm([0 1; -1 -0.1]*t(j))*[1;0]; end
plot (t,x)
legend ('position', 'velocity');
title ('underdamped spring starting at y = 1; y'' = 0')
Upvotes: 1
Reputation: 4811
The 2nd order eqn can be converted to a system of first order differential equations.
function dy = ex(y)
dy = zeros(2,1);
dy(1) = y(2);
dy(2) = -c/m*y(2) - k/m*y(1);
From this you can use Matlab's in-built solver. ode23s
would work just fine:
[t,y] = ode23s(@ex, y0, tspan)
Upvotes: 3
Reputation: 9592
A system of first order differential equations could look like this whereas y1 = y
. '
is used to indicate the time derivative.
y1' = y2
y2' = -c/m*y2 - k/m*y1
Upvotes: 2
Reputation: 25052
Rewrite the second order equation as a system of first order equations. The unknowns correspond to position and velocity.
Upvotes: 3