Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a problem with command NDSolve in mathematica. If we have simple second order differential equation, it is easy to write code in mathematica. But if we have matrix problem (for example 4 unknown functions 4x1 matrix to display it) and also rather than simple constants, we have matrices 4x4. Can I type simple in matrix form this equation and then apply NDSolve without expanding the system. Short code attached here:


Kind regards and thank you in advance,

share|improve this question

1 Answer 1

For the homogeneous case as in your file this will do:

qu[t_] = {qu1[t], qu2[t], qu3[t], qu4[t]};
share|improve this answer
Thank you very much Andrew. –  George Sep 8 '11 at 0:57
Dear Andrew, I followed your code to solve now three equations but non linear. So if I have non linear system with three additional matrices (K2n, K3n, K4n) which are also functions of q, something wrong. Also you putted #==0 before, but in this case my second equation should be equal to matrix S, or if I want to change initial conditions, how to do that?sendspace.com/file/uqxgzf –  George Sep 8 '11 at 1:35
Some equations' lhs are equal to zero, and 0==0 gives True. So the system is overdetermined. It wouldn't be solved by DSolve[] even after deleting such cases. As for initial conditions here simplified example. As for the initial conditions here is a simplified example: func = {x[t], y[t]}//Flatten; system = {x'[t], y'[t]}//Flatten; rhs = {3 t, 2 t}//Flatten; incond = {x[0], y[0]}//Flatten; indata = {1, 3}//Flatten; NDSolve[#[[1]] == #[[2]] & /@ (Transpose[{Flatten[{system, incond}], Flatten[{rhs, indata}]}]), func, {t, 0, 1}] –  Andrew Sep 8 '11 at 7:46
Dear Mr Andrew, I got your suggestions and it is very good for initial conditions. In older system I used * instead . for matrix, now this is correct in new code, and also I wrote in second equation -S, (because it should be eq1=0, eq2=S, eq3=0), so it is clear. And also I wrote K2n=..,K3n=..,K4n=..(not K2n:=..because K2n, K3n and K4n are also functions only of qp) with same initial conditions, but code doesn`t work again.sendspace.com/file/h5xcge Message: NDSolve::dsfun: {qu1[t],qu2[t],qu3[t],qu4[t]} cannot be used as a function. >> –  George Sep 8 '11 at 12:19
The functions list should be a one-level list, I specially have written it above as func = {x[t], y[t]}//Flatten; though flattening is not required in this case. Here {qu1[t],qu2[t],qu3[t],qu4[t]}//Flatten instead of {qu1[t],qu2[t],qu3[t],qu4[t]} should do. –  Andrew Sep 8 '11 at 12:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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