# How do I implement formulas within matrices? [closed]

I'm learning Mathematica through examples given in Engineering Vibrations by Daniel J. Inman. However, there is a huge mistake given in this bit of code offered:

M = {{4, 0}, {0, 9}};
K = {{30, -5}, {-5, 5}};
f = {{0.235*Sin[ω*t]}, {2.97922 Sin[ω*t]}};
ω = 2.75655;
x = {{x1[t]}, {x2[t]}};
xdd = {{x1''[t]}, {x2''[t]}};
system = m.xdd + k.x;

num = NDSolve[
{system[] == f[],
x1' == 0,
x1 == 0,
system[] == f[],
x2 == 0,
x2' == 0},
{x1[t], x2[t]},
{t, 0, 20}
];

Plot[
{Evaluate[x1[t] /. num], Evaluate[x2[t] /. num]},
{t, 0, 20},
PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]},
PlotLegends -> {"x1[t]", "x2[t]"}
]


If I am to represent the matrix of time-dependent formulas for distance and acceleration, how am I suppose to do it?

• You start with upper case M and then use a lower case m. Same with K and k. Those seems to be the only issues. – Suba Thomas Oct 3 '19 at 20:08

Few edits, then the code will run!

m = {{4, 0}, {0, 9}};
k = {{30, -5}, {-5, 5}};
f = {{0.235*Sin[\[Omega]*t]}, {2.97922*Sin[\[Omega]*t]}}; \[Omega] = 2.75655;
x = {{x1[t]}, {x2[t]}};
xdd = {{Derivative[x1][t]}, {Derivative[x2][t]}};
system = m . xdd + k . x;
num = NDSolve[{system[] == f[], Derivative[x1] == 0, x1 == 0,
system[] == f[], x2 == 0, Derivative[x2] == 0}, {x1[t], x2[t]},
{t, 0, 20}];
Plot[{Evaluate[x1[t] /. num], Evaluate[x2[t] /. num]}, {t, 0, 20},

PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}, PlotLegends -> {"x1[t]", "x2[t]"}] • Damn, I didn't realize it was a simple syntax error. Thanks. – TexMexDex Oct 3 '19 at 20:13
• it happens a lot for everyone – Alrubaie Oct 3 '19 at 20:49