# Issues using DSolve to solve system of differential equations

I know there are a lot of similar questions to this, but I am relatively new to this and the answers don't make a ton of sense to me. I am trying to use DSolve to get harmonic motion in three dimensions, but I can't seem to get the function to evaluate. I've done the analogous 1 dimensional problem and it worked fine, but when I tried bringing it to three dimensions I can't seem to get it right.

The following code represents a mass beginning with 0 velocity at the position (1.5, 1.5, 1.5), and tethered to the origin. Each coordinate in time should move the same (all solutions should be cosines). I've set the mass (m), stiffness (k), and natural length (l) to unity for simplicity.

k = 1;
l = 1;
m = 1;
(*some constants of the system*)

Mag[vector_] := Sqrt[vector . vector]
(*I'm using this to find the magnitude of a vector. This is necessary to examine the distance between the mass and the origin*)

r4[t] = {x4[t], y4[t], z4[t]};
(*position of the mass in time*)

force4 = - k (Mag[r4[t]] - l) r4[t]/Mag[r4[t]];
(*force acting on tethered mass. typical spring force, last term provides unit vector to the mass.*)

eq4 = force4 == m r4''[t] // Thread;
vel4 = r4'[0] == 0 // Thread;
pos4 = r4[0] == 1.5 // Thread;
(*the equations of motion. first one is just f=ma. second two lines are the initial velocity and position to use as boundary conditions.*)

DSolve[Join[eq4, vel4, pos4], r4[t], t]
(* The problem child. This should return r4[t] showing a cosine function for each of the three dimensions (x,y,z), but it doesn't evaluate*)


Any help would be greatly appreciated! I would like to abstract this even further once it starts working so I can examine two masses tethered to each other in arbitrary positions.

Thanks!

• As a first step, do ClearAll[r4] and use r4[t_]:={x4[t],y4[t],z4[t]} or r4=Function[t,{x4[t],y4[t],z4[t]}]. For a numerical solution, you could use something like With[{tmax=5}, NDSolveValue[Join[eq4,vel4,pos4],r4[t],{t,0,tmax}]]. Jul 26, 2022 at 18:31
• Thanks for the suggestions! I just tried the code for the numerical solution and it seems to work! This being said, my system of equations should have an analytic solution so I'm still puzzled as to why that DSolve isn't working Jul 26, 2022 at 18:48
• With your initial conditions, there will be a solution of the form f[t]*{1,1,1} and if you help Mathematica bit and write down the equation for the single unknown f, then it will solve it. Solving a nonlinear equation in many variables automatically is probably tricky... but it is not the kind of thing I know much about. Jul 26, 2022 at 18:59
• For a start position of {1.5,1.5,1.5} the spring is extended to 2.6. The mass has then enough energy to swing through the origin. At this point the unit vector changes sign and your formula is wrong. Jul 26, 2022 at 20:20
• @DanielHuber Thanks! I guess I wasn't thinking when I set the initial position so far away. I moved it closer to (1,1,1) which shouldn't pass through the origin. Unfortunately the analytical solution still does not compute. Jul 26, 2022 at 20:28

With the following changes:

k = 1;
l = 1;
m = 1;

r4[t_] = {x4[t], y4[t], z4[t]};
Mag[vector_] := Sqrt[vector . vector];
force4 = -k (Mag[r4[t]] - l) r4[t]/Mag[r4[t]];
eq4 = force4 == m r4''[t] // Thread;
vel4 = r4'[0] == 0 // Thread;
pos4 = r4[0] == 1 // Thread;
eq = Join[eq4, vel4, pos4];

sol = DSolve[eq, {x4[t], y4[t], z4[t]}, {t, 0, 15}]


DSolve solve returns unevaluated. However NDSolve gives cosine like solutions:

sol = NDSolve[eq, {x4[t], y4[t], z4[t]}, {t, 0, 15}]

Plot[Evaluate[{x4[t], 0.4227 Cos[t] + 0.57736} /. sol], {t, 0, 10}]


And the difference between the hand fitted cosine and the solution:

Plot[Evaluate[{x4[t] - ((0.4227 Cos[t] + 0.57736))} /. sol], {t, 0, 10}]


So it looks like NDSolve is returning the expected cosine like solutions but DSolve is not able to find it.

I think this is an interesting question and I encourage you to report this to [email protected] and subsequently post the answer here,