Re: Re: Fitting parameters of nonlinear diff equation system

*To*: mathgroup at smc.vnet.net*Subject*: [mg81549] Re: [mg81303] Re: Fitting parameters of nonlinear diff equation system*From*: "Paul Thomas" <paul.pgt at gmail.com>*Date*: Wed, 26 Sep 2007 21:48:43 -0400 (EDT)*References*: <fcnl8h$s85$1@smc.vnet.net> <200709181002.GAA04068@smc.vnet.net>

Hi Szabolcs, A couple things, thanks for your reply! Replacing f with f[t] in fun[] does seem to return a function. I tested this by just running fun with a given a,b,c and with the f[t] syntax it produces an interpolating function (as NDSolve should)--it doesn't with just f as I think it doesn't know what "f" is in that case--the output of just using "f" is literally just "f" with no function associated. On the /@ priority issue, I actually changed one other thing, which maybe is a problem too. Instead of using "/@" there I used "/."--that I think does require the parentheses. I kept getting an error using "/@" and "/." seemed to fix it. The error would say that essentially a non-numerical equation was resulting from the /@ and it would write it out--it did seem to be doing the wrong equation, but it looks like the right one with /. Now it seems to be doing exactly what you designed it to do. Once the parameters are fit I feed them back into "fun" and check the work essentially of the process and plot the optimization over time. For example, once I've done a particular fit: g[t_]:=fun[1,2,3] {pretending 1,2,3 were our best a,b,c fits} g[t] is now my best fit function and matches the findminimum minimum at the particular t points I have. The curves also look generally as they should. Do you think I have an error in this? Thanks for all your help with it, like I said, it seems like a very powerful approach at least for the types of things that I've been trying to do--very flexible! Paul On 9/25/07, Szabolcs Horv=E1t <szhorvat at gmail.com> wrote: > > Hi Paul, > > I am writing to warn you that something *might* have gone wrong with > the calculations. (Let's hope that it is just a misunderstanding). > > On 24/09/2007, Paul Thomas <paul.pgt at gmail.com> wrote: > > Hi everyone, > > > > Just wanted to follow up with this. The e-mail below from Szabolcs was > very > > helpful and it did work, with just a minor syntax change. He suggested > the > > following code for fitting a system of differential equations with > multiple > > parameters: > > > > fun[a_, b_, c_] := > > First[ > > f /. NDSolve[ > > deq /. {b1 -> a, h -> b, r -> c}, > > {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, f} , > > {t, 0, 10} (* dummy values *) > > ]] > > > > opt[a_?NumericQ, b_?NumericQ, c_?NumericQ] := > > Norm[fun[a, b, c] /@ tvals - fvals] > > > > Now use FindMinimum on 'opt', like this: > > > > FindMinimum[opt[a,b,c], {{a,1.}, {b,2.}, {c,3.}}] > > > > One change I had to make was in the "fun[a_,b_,c_]" equation--instead of > > "f/.NDSolve" it should be "f[t]/.NDSolve" etc etc. > > While I admit that I did not test these commands thoroughly (as I did > not have access to the data), something seems to be wrong with these > modifications. I meant fun[] to return a function, not a number (note > that we later map this function to a list) ... if f is changed to > f[t], then the return value will not be a function. > > > The other change I had to make was in the opt equation. I just needed to > put > > parentheses around the "(fun[a, b, c] /@ tvals)" term--otherwise it > thinks > > the "/@" Map command is being applied to tvals-fvals. > > Something seems to be wrong here too, as /@ has a higher precedence than - > . > > Example: > > In[1]:= > a={1,2,3}; > b={4,5,6}; > > In[3]:= f/@a-b > Out[3]= {-4+f[1],-5+f[2],-6+f[3]} > > > I want to thank everyone for their comments, I'm so pleased with this > > technique now. I think it works very much like the documentation says > > FindFit works, but it is much more flexible in terms of the data you can > > input for the fit and also allows a whole system to be solved with data > only > > from a single equation. To me, those are both huge advantages. Thanks! > > > > Paul > > Szabolcs >

**References**:**Re: Fitting parameters of nonlinear diff equation system***From:*Szabolcs Horvát <szhorvat@gmail.com>