Re: NIntegrate in NDSolve?

*To*: mathgroup at smc.vnet.net*Subject*: [mg7] Re: [mg89038] NIntegrate in NDSolve?*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Sun, 25 May 2008 02:06:25 -0400 (EDT)*Reply-to*: hanlonr at cox.net

Use symbolic solution sol1 = y[t] /. DSolve[{y'[t] == Integrate[z y[t], {z, 0, 1}], y[0] == 1}, y[t], t][[1]] E^(t/2) Plot[sol1, {t, 0, 1}] Or use symbolic solution for intermediate step sol2 = y[t] /. NDSolve[{y'[t] == Integrate[z y[t], {z, 0, 1}], y[0] == 1}, y[t], {t, 0, 1}]; Plot[sol2, {t, 0, 1}] Or restrict the numerical integration to evaluate only with numerical arguments. f[a_, t_?NumericQ] := NIntegrate[z a, {z, 0, 1}]; sol3 = y[t] /. NDSolve[{y'[t] == f[ y[t], t], y[0] == 1}, y[t], {t, 0, 1}]; Plot[sol3, {t, 0, 1}] Bob Hanlon ---- EcoTheory <carroll.ian at gmail.com> wrote: > 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. >