2

Suppose I have a vector equation:

Y'[t]==rhs[Y[t]] 

and

Y[0]==ConstantArray[0,n]

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 :

rhs[{x_?NumberQ,y_?NumberQ]={x,y}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
user1505725
  • 148
  • 5

1 Answers1

7

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

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355