Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fitting the solution of a differential equation to a data set

306 views
Skip to first unread message

Timm Florian Gloger

unread,
Oct 21, 2010, 7:01:47 AM10/21/10
to
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

Achilleas Lazarides

unread,
Oct 23, 2010, 7:05:10 AM10/23/10
to
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.

Timm Florian Gloger

unread,
Oct 23, 2010, 7:03:54 AM10/23/10
to
Many thanks to all of you.
All the answers provided useful ideas and interesting points for further reading.
As always (... unfortunately ...), the most direct way to a solution of my problem was a kind "RTFM"
(Thank you, J=F6rg ;-) ).

So this thread can be considered as "solved".

Kind regards
Timm

On 21.10.2010, at 17:49, Joerg Roesgen wrote:

> Hi Timm,
>
> you can use FindFit. Under FindFit in the documentation you have Applications -> Differential Equations. This is probably what you want to read.
>
> Best,
> J=F6rg


>
> On Oct 21, 2010, at 7:01 , 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 solve d analytically, I am searching for

0 new messages