Re: how use NDSolve with an ODE having parameters

*To*: mathgroup at smc.vnet.net*Subject*: [mg39708] Re: [mg39691] how use NDSolve with an ODE having parameters*From*: Reza Malek-Madani <research at usna.edu>*Date*: Mon, 3 Mar 2003 04:25:36 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Dear Murray: Is this along the lines of what you're looking for? f[omega_, a_, b_] := NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - 0.1*y[t] + Cos[omega t], x[0] == a, y[0] == b}, {x, y}, {t, 0, 10}] sol = f[6, 1, 1]; newx[t_] = First[x[t] /. sol[[1]]]; Print[NIntegrate[(newx[t])^2, {t, 0, 10}]]; g[omega_] := Block[{sol}, sol = f[omega, 1, 1]; newx[t_] = x[t] /. sol; First[newx[3]]] Plot[g[omega], {omega, 0.1, 3}] This solves the usual pendulum equation with omega and initial conditions as parameters, computes the L^2 norm of x for a specific set of parameters, and plots the x value at t=3 as omega varies. Rez ------------------------------------------------------------------------- Reza Malek-Madani Director of Research Research Office, MS 10m Phone: 410-293-2504 (FAX -2507) 589 McNair Road DSN: 281-2504 U.S. Naval Academy Nimitz Room 17 in ERC Annapolis MD 21402-5031 Email: research at usna.edu -------------------------------------------------------------------------- On Sat, 1 Mar 2003, Murray Eisenberg wrote: > This is a simplification of a question asked by a colleage. He wants to > use as the model function argument to NonlinearRegress (from > Statistics`NonlinearFit1) a solution of an initial-value problem for a > differential equation, where the differential equation depends on a > parameter. > > The catch is that the differential equation cannot be solved explicitly, > so he has to resort to solving the initial-value problem by means of > NDSolve. Of course, NDSolve will not do anything if the differential > equation involves symbolic parameters. Thus the IDEA of what he wants > to do is to use the "resulting function" from something like > > y[t]/.First@NDSolve[{y'[t] == a y[t] + b, y[0] == 1.}, y[t], {t, 0., 1.}] > > -- where two parameters a and b are involved -- as the model. Of course > if NDSolve above is changed to DSolve, no difficulty. But in the ACTUAL > problem at issue, with a much more complicated differential equation, > DSolve does nothing. > > Is there some way to make this work? > > There are evidently two difficulties: > > (1) How to deal with NDSolve when the differential equation involves > parameters (perhaps there's something regarding use of Hold that will > help?); and > > (2) For each pair of particular values of the parameters, the result > from NDSolve is an InterpolatingPolynomial object and NOT the sort of > "expression in the variable" that seems to be required for the model > argument to NonlinearRegress. How should the InterpolatingPolynomial > object be massaged to allow it to be used as an ordinary expression in > the variable? > > -- > Murray Eisenberg murray at math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street > Amherst, MA 01375 > >

**Re: how use NDSolve with an ODE having parameters**

**Re: how use NDSolve with an ODE having parameters**

**Re: how use NDSolve with an ODE having parameters**

**Re: how use NDSolve with an ODE having parameters**