2
$\begingroup$

I'll preface this with the fact that I have no idea what I'm doing. I'm new to Mathematica, I've only used it to solve simple ODEs with NDsolve. I'm trying to solve a 2DOF system now with with matrices instead of constants in the eqn of motion. Thanks for any help in advance.

m = {{2, 0}, {0, 1}};
c = {{3, -.5}, {-.5, .5}};
k = {{4, -1}, {-1, 1}};
initu = u[0] == {{0}, {.1}};
initv = u'[0] == {{1}, {0}};
u[t_] := {{u1[t]}, {u2[t]}};
sol = 
 NDSolve[{m.u''[t] + c.u'[t] + k.u[t] == {{Sin[2 t]}, {Sin[2 t]}}, 
   initu, initv}, u, {t, 0, 100}]
{{u -> u}}
{{u -> u}}
Plot[Evaluate[u[t] /. sol], {x, 0, 100}]
{{u -> u}}
$\endgroup$
  • $\begingroup$ Could you tell me how to do that? $\endgroup$ – MMNewbie Nov 28 '14 at 17:11
  • $\begingroup$ use this command reference.wolfram.com/language/ref/Quit.html (in separate cell) $\endgroup$ – Nasser Nov 28 '14 at 17:15
  • $\begingroup$ Ok I think I that part fixed. Now my solution doesn't look right. I edited in the original post, getting "u->u" $\endgroup$ – MMNewbie Nov 28 '14 at 17:19
  • $\begingroup$ I'd be happy to, I don't see where to do that though $\endgroup$ – MMNewbie Nov 28 '14 at 22:36
3
$\begingroup$

Change u to u[t] in the call to NDSolve

m = {{2, 0}, {0, 1}};
c = {{3, -.5}, {-.5, .5}};
k = {{4, -1}, {-1, 1}};
initu = u[0] == {{0}, {.1}};
initv = u'[0] == {{1}, {0}};
u[t_] := {{u1[t]}, {u2[t]}};
sol = NDSolve[{m.u''[t] + c.u'[t] + k.u[t] == {{Sin[2 t]}, {Sin[2 t]}}, 
    initu, initv}, u[t], {t, 0, 100}]

Mathematica graphics

Now M sees that u[t] is {{u1[t]}, {u2[t]}} otherwise it did not know that.

Or you can simplify things little:

m = {{2, 0}, {0, 1}};
c = {{3, -.5}, {-.5, .5}};
k = {{4, -1}, {-1, 1}};
initu = u[0] == {{0}, {.1}};
initv = u'[0] == {{1}, {0}};
u[t_] := {u1[t], u2[t]};
sol = First@NDSolve[{Thread[m.u''[t] + c.u'[t] + k.u[t] == {Sin[2 t], Sin[2 t]}],
   initu, initv}, u[t], {t, 0, 100}];
Plot[{u1[t] /. sol, u2[t] /. sol}, {t, 0, 100}, PlotTheme -> "Detailed"]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.