# how to solve matrix differential equation using Mathematica

I have to solve $$[m]x''+[c]x'+[k]x=[p]$$ where x is function of $$t$$ after defining $$[m],[c],[k]$$ and $$[p]$$ in mathematica and x[t_]={x1[t],x2[t],x3[t]}

I am using NDSolve as

NDSolve[m.x''[t]+c.x'[t]+k.x[t]==p,x[t],{t,0,10}]


but I am not getting its solution even I tried

NDSolve[{m.x''[t]+c.x'[t]+k.x[t]==p,x==0,x'==0},x[t],{t,0,10}


can somebody help me to solve the initial equation?

• You could take a look at 240947 for some hints on setting up a matrix differential equation. Jun 16, 2021 at 18:10
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Jun 16, 2021 at 18:37

When dealing with matrix equations, I personally use Map[] to turn a matrix or a vector into a list of equations. Example below.

m = {{1, 2},{3, 4}};
c = {{5, 6},{7, 8}};
p = {1, 2};
x[t_] := {x1[t], x2[t]};

equation = m . x'[t] + c . x[t] - p;

NDSolve[
Flatten[{
Map[# == 0 &, equation],
Map[# == 0 &, x]
}]
, x[t], {t, 0, 10}]