Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

NDSolve with Numeric Function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100190] NDSolve with Numeric Function
  • From: Hugh Goyder <h.g.d.goyder at cranfield.ac.uk>
  • Date: Wed, 27 May 2009 04:09:45 -0400 (EDT)

Please could someone explain why my NDSolve examples below don't work?
In the first case I think it fails because NDSolve attempts to
evaluate the function RHS symbolically.
The second case should remain unevaluated and signal to NDSolve to go
numerical but this fails why?
 In the third case a similar check to the second works. Why?

 Many thanks
 Hugh Goyder

ClearAll[RHS];
RHS[x_, v_, f_] := Module[{x1, y1, x2, y2, x1v, y1v, x2v, y2v},
  {x1, y1, x2, y2} = x;
  {x1v, y1v, x2v, y2v} = v;
  -{{1, 2, 3, 5}, {3, 2, 1, 2}, {5, 7, 1, 1}, {3, 2, 4, 5}}.{x1, y1,
      x2, y2} + 3 {x1v, y1v, x2v, y2v}
  ]

sol = NDSolve[{x''[t] == RHS[x[t], x'[t], 1], x[0] == {-1, 0, 1, 0},
   x'[0] == {0, 0, 0, 0}}, x, {t, 0, 2}]

ClearAll[RHS];
RHS[x_ /; NumericQ[x[[1]]], v_, f_] :=
 Module[{x1, y1, x2, y2, x1v, y1v, x2v, y2v},
  {x1, y1, x2, y2} = x;
  {x1v, y1v, x2v, y2v} = v;
  -{{1, 2, 3, 5}, {3, 2, 1, 2}, {5, 7, 1, 1}, {3, 2, 4, 5}}.{x1, y1,
      x2, y2} + 3 {x1v, y1v, x2v, y2v}
  ]

sol = NDSolve[{x''[t] == RHS[x[t], x'[t], 1], x[0] == {-1, 0, 1, 0},
   x'[0] == {0, 0, 0, 0}}, x, {t, 0, 2}]

ClearAll[RHS];
RHS[x_ /; Head[x] == List, v_, f_] :=
 Module[{x1, y1, x2, y2, x1v, y1v, x2v, y2v},
  {x1, y1, x2, y2} = x;
  {x1v, y1v, x2v, y2v} = v;
  -{{1, 2, 3, 5}, {3, 2, 1, 2}, {5, 7, 1, 1}, {3, 2, 4, 5}}.{x1, y1,
      x2, y2} + 3 {x1v, y1v, x2v, y2v}
  ]

sol = NDSolve[{x''[t] == RHS[x[t], x'[t], 1], x[0] == {-1, 0, 1, 0},
   x'[0] == {0, 0, 0, 0}}, x, {t, 0, 2}]


  • Prev by Date: Re: Shade area between two polar curves
  • Next by Date: Re: Keep Slider Consistent With a Slow Graph
  • Previous by thread: Re: simultaneous equations for chemical speciation
  • Next by thread: Re: NDSolve with Numeric Function