Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have a vector equation:




where "rhs[Y[t]]" is a black box function which numerically calculates a N-length vector given a N-length vector Y[t].

How can I solve such an equation in "NDSolve" ?

Update: Say my rhs is :

share|improve this question
An example of exactly this kind of equation is in my answer to "I'd like to display field lines for a point charge in 3 dimensions". The equation for a field line is exactly of the type you mention. If you need more details on what I did there, let me know. – Jens Jul 6 '12 at 5:00
Many Thanks. It would be great if you let me know more. Let me tell you what I am not looking for, – user1505725 Jul 6 '12 at 5:26
I just added an answer with the relevant parts of my earlier link, applied to a simple example rhs. The added ingredient here is to use Array to generate the vectors. – Jens Jul 6 '12 at 5:32
Sorry that I did not make my question clear. I want to know if rhs[Y[t]] does not have a symbolic form. That is what I meant by "numerically calculates". – user1505725 Jul 6 '12 at 5:47
Hello & welcome! If you register for this site you will be able to access more features, for example voting. – Vitaliy Kaurov Jul 6 '12 at 5:49

This is a classic example from documentation center. I will modify this slightly, to make it more complex.

A = RandomReal[{0, 1}, {5, 5}];

Now you can actually mix scalar and vector functions - 'NDSolve' will understand it:

fs = x /.First[NDSolve[{x'[t] == 1 - Norm[x[t]] A.Sin[x[t]], 
      x[0] == RandomReal[1, 5]}, x, {t, 0, 23}]];

Visualize typically:

Plot[fs[t], {t, 0, 23}, ColorFunction -> Hue, PlotStyle -> Thick, 
 Frame -> True, FillingStyle -> Opacity[0.05], Filling -> 0]

enter image description here

Or visualize in an interesting way:

ParametricPlot3D[ fs[t][[#1 ;; #2]] & @@@ {{1, 3}, {2, 4}, {3, 5}}, {t, 0, 23}, 
  PlotRange -> All, PlotStyle -> Thick, ColorFunction -> Hue, 
  ImageSize -> 450] /. Line[pts_, rest___] :> Tube[pts, 0.1, rest]

enter image description here

share|improve this answer
It works perfectly, – user1505725 Jul 6 '12 at 5:52
Many thanks it works. – user1505725 Jul 6 '12 at 5:55

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.