Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

NDSolve and NumericQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116309] NDSolve and NumericQ
  • From: Simon Pearce <Simon.Pearce at nottingham.ac.uk>
  • Date: Thu, 10 Feb 2011 05:24:34 -0500 (EST)

Hi Mathgroup,

I have a differential equation in terms of y[S] which contains several complicated piecewise functions inside the ODE. I currently then use NDSolve in order to find a solution for y. This works, but takes  about 10 seconds to solve.
I'd like to speed this up, and I'm wondering if NDSolve is trying to differentiate the piecewise function explicitly, as has been mentioned before in the group (http://forums.wolfram.com/mathgroup/archive/2008/Sep/msg00458.html). The solution given there is to use ?NumericQ to prevent evaluation without supplying the value, common enough (and an entirely separate issue on the group - can't we have an option in FindRoot and related functions so we can turn this off?). But I'm having trouble in doing this and using NDSolve, the method I'm trying to use currently .

So a test problem:

AA[y_, S_?NumericQ] := Sin[y[S]] + y'[S]/S
NDSolve[{AA[y, S] == 0, y[0] == 1}, y, {S, 0, 1}]

Giving the error "NDSolve::dvnoarg: The function y appears with no arguments", as it tries to evaluate for a general S. It works if I take the ?NumericQ out of the definition, but that isn't what I'm trying to do.

As an example of a function which doesn't work if we take the ?NumericQ out of the definition:

BB[y_, S_?NumericQ] :=  Sin[y[S]] + y'[S]/S + NIntegrate[(Sqrt[t] + Sin[t]), {t, 0, S}]
NDSolve[{BB[y, S] == 0, y[0] == 1},y, {S, 0, 1}]
Same error again.

CC[y_, S_] :=  Sin[y[S]] + y'[S]/S + NIntegrate[(Sqrt[t] + Sin[t]), {t, 0, S}]
NDSolve[{CC[y, S] == 0, y[0] == 1},y, {S, 0, 1}]
This gives errors on the NIntegrate which suggest to me that NDSolve is doing something to the equation before putting values in for S. The result is correct, but isn't immediate.

Anyone have any idea how to do this?

Thanks,
Simon Pearce
University of Nottingham

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.   Please do not use, copy or disclose the information contained in this message or in any attachment.  Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.  This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.


  • Prev by Date: Re: Polygon projection in CountryData incorrect?
  • Next by Date: Re: Using Mathematica for text mining
  • Previous by thread: Re: Apply a rule to an expression only once
  • Next by thread: Re: NDSolve and NumericQ