Re: Fitting the solution of a differential equation to a data set

*To*: mathgroup at smc.vnet.net*Subject*: [mg113310] Re: Fitting the solution of a differential equation to a data set*From*: Achilleas Lazarides <achilleas.lazarides at gmx.com>*Date*: Sat, 23 Oct 2010 07:05:17 -0400 (EDT)

Hi, something like Clear@stFit; stFit[in_] :== Module[ {modFit, soly, data == Table[{t, Exp[-in*t]}, {t, 0, 10, .01}] }, modFit[omega_?NumberQ] :== modFit[omega] == (y /. First@NDSolve[{y'[x] + omega*y[x] ==== 0, y[0] ==== 1}, y, {x, 0, 10}]); FindFit[data, modFit[a][x], a, x] ] should work. This just does the obvious thing: it defines modFit which, given a number omega returns the numerical solution to the ode y'[x]+omega*y[x]====0 (ie, Exp[-omega*t]). It then fits it to the data I've generated in the beginning. Since FindFit will call modFit many times with the same omega (use Sow and Reap to see that), memoization speeds this up immensely. Where precisely had you gotten stuck? It's easy to look at the mess I posted and get confused (it's written in a hurry and without much thought), so perhaps you could be more specific. On Oct21, 2010, at 1:01 PM, Timm Florian Gloger wrote: > Hi list, > > given a set of data (e.g. {x,y} pairs) and a theoretical model described by > a differential equation (with some free parameters) that cannot be solved analytically, I am searching for > a way to somehow use Mathematica to fit the numerical solution of the equation > to the data set. > > Unfortunately I failed to utilize FindFit and NDSolve on this behalf (which might very well be due to my lack > of experience with Mathematica...). > Any suggestions on how to do this? > > Kind regards, > Timm