[Date Index]
[Thread Index]
[Author Index]
Re: NIntegrate in NDSolve?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg23] Re: [mg89038] NIntegrate in NDSolve?
*From*: danl at wolfram.com
*Date*: Sun, 25 May 2008 02:03:48 -0400 (EDT)
*References*: <200805240754.DAA20848@smc.vnet.net>
> Hello, This is my first Mathematica question ... of many to come, I'm
> sure. My question is, can you use NIntegrate within NDSolve? My attempts
> lead to this error:
>
> NIntegrate::inum : Integrand is non - numerical etc.
>
> Here is a simple example:
> NDSolve[{y'[t] == NIntegrate[z y[t], {z, 0, 1}], y[0] == 1}, y[t], {t, 0,
> 1}]
>
> As far as I can tell, Mathematica does not believe that y[t] is a number.
> But shouldn't the numerical solver give y[t] as a number to NIntegrate?
>
> Obviously, Mathematica can do this problem easily enough using Integrate
> instead of NIntegrate, but it cannot integrate the messier double integral
> in the actual system of ODE's I want to solve. Thanks for suggestions.
This type of thing can sometimes be done by treating the function as an
explicit "black box", for purposes of numerical evaluation at intermediate
steps. This in turn can be done by defining an auxiliary function that
only evaluates for explicit numerical input, and using that in NDSolve. In
this example:
f[y_Real] := NIntegrate[z*y , {z, 0, 1}]
NDSolve[{y'[t] == f[y[t]], y[0] == 1}, y[t], {t, 0, 1}]
You can also treat t as an independent variable, say, using
f[t_Real,y_Real] := NIntegrate[z*y , {z, 0, t}]
Daniel Lichtblau
Wolfram Research
Prev by Date:
**Re: NIntegrate in NDSolve?**
Next by Date:
**Re: NIntegrate in NDSolve?**
Previous by thread:
**NIntegrate in NDSolve?**
Next by thread:
**Re: NIntegrate in NDSolve?**
| |