Question: Problem with the movement for spring -mass

 

Hello,

I am trying to modify Maple code so I have a vertical spring with a mass starting at (0,0). The spring with the mass should move right and left along x. My vertical spring move up instead of down while the mass move to the right .

Any Idea about how I can get the right movement of the spring?

 

Please ignore the equation eq since I am only trying to have an animation spring with a mass.

 Thank you

 

Maple code:

>restart; with(plots); with(DEtools); with(plottools);

>mass_spring := proc (m, r, k, x1, x2, x0, xp0, tk, f, n)

local mass, eq, init, sol, xk, xu, plt1, plt2, plt, base, spring, spring1;

spring := proc (x1, x2, n)

local p1, p2, pn_1, pn, p;

p1 := [x1, 0];

 p2 := [x2, 0];

 p := proc (i) options operator, arrow; [(-1)^(i+1)*.5, x2+.25+(x1-x2-.5)*i/n] end proc;

plot([p1, p2, seq(p(i), i = 1 .. n-1)], thickness = 2, color = aquamarine)

end proc;

spring1 := proc (x1) options operator, arrow; spring(x1, x2, 45) end proc; mass := proc (x1) options operator, arrow; rectangle([x1, -.5], [x1+1, .5], color = red) end proc;

eq := m*(diff(x(t), `$`(t, 2)))+r*(diff(x(t), t))+k*x(t) = f(t);

init := x(0) = x0, (D(x))(0) = xp0;

sol := dsolve({eq, init}, x(t));

xk := unapply(rhs(sol), t);

base := plot(-1.1, t = -10 .. 10, color = brown, thickness = 4);

plt1 := proc (x) options operator, arrow; translate(display(spring1(x1+x), mass(x1+x), base), 0, -7) end proc;

plt := proc (i) options operator, arrow;

display(plt1(i)) end proc;

display(seq(plt(i), i = 0 .. n), insequence = true)

end proc;

> mass_spring(1, 0, 1, 0, 0, 2, 0, 14, 0, 10, scaling = constrained);

Please Wait...