| 
September 25th, 2009, 09:44 AM
| | Newbie | | Join Date: Sep 2009
Posts: 8
Country: Thanks: 0
Thanked 3 Times in 3 Posts
| | Mathematica FindFit - proper format question Hi everyone,
Thanks in advance for your help. I'm trying to fit a system of coupled ODEs to some experimental data; currently executing my code results in the function returning itself. The documentation claims this means that there is no syntax errors but Mathematica doesn't know what to do with my input (i.e. I'm doing something wrong, but it isn't blatant to Mathematica).
I'm new to Mathematica so without errors to guide me (and without finding anything helpful on the web), I'm at a loss.
The system of ODEs is somewhat complicated, so here is a simple example that does the same thing: Code: system={y1'[t]==A,y2'[t]==B};
pars={A,B};
vars={y1[t],y2[t]};
expvalues={{0,0,0},{1,5,10},{2,10,Null}};
FindFit[expvalues,system,pars,vars]
Obviously this is a trivial example; I'm trying to fit y1=A*y1 and y2=B*y2 to some sample data where A=5 and B=10.
I put "Null" in to the second set of experimental values because in my actual system I have some blanks in my experimental values (e.g. at time=10 I have input for 3 of the 5 variables, and at time=20 I have input for a different 3 of the 5 variables). I'm not sure if that is the correct way to put an "empty" value in to the list (and it does seem that you have to have something for each variable at each time point you're giving data), but if you replace the Null with a "20" in the code you get the same error, so that isn't the only issue with what I've done.
Thanks again! | 
September 25th, 2009, 03:37 PM
| | Super Member | | Join Date: Aug 2008
Posts: 836
Country: Thanks: 54
Thanked 338 Times in 298 Posts
| | I don't think you can do multiple equation fits with FindFit. Can you not call FindFit for each equation? The general format is:
FindFit[data, expres, param,varab]
The "expres" is a single expression and I don't think it can have derivative specifiers in it like you have above with the primes. It can have multiple variables and multiple parameters but still it's for a single fit function.
__________________ "I am beset by the ironies in my life" | 
September 26th, 2009, 10:10 AM
| | Newbie | | Join Date: Sep 2009
Posts: 8
Country: Thanks: 0
Thanked 3 Times in 3 Posts
| | Thanks for the response - I suspect you may be right, but I can't just fit each one separately since in my actual system the equations are interrelated. If anyone has ideas as to how to go about fitting a system of equations, I'm all ears! This was the best approach I've been able to find so far.... | 
September 26th, 2009, 11:26 AM
| | Super Member | | Join Date: Aug 2008
Posts: 836
Country: Thanks: 54
Thanked 338 Times in 298 Posts
| | How many equations do you have?
After re-reading your post, I think you are trying to fit the "solutions" of the DE system to your experimental data. That's not the same as using FindFit to fit an equation to a set of data points.
Say I have a set of first-order equations in n variables and a set of experimental data that should correspond to the solution of this system. If they are simple enough for the function DSolve to solve explicitly, then I'd solve it and then determine the best values for the arbitrary constants that are created during the solution that fits the experimental data.
More likely they are not simple so you have to numerically integrate the system via NDSolve. But in this case you must supply initial conditions for each variable before you run NDSolve. That's more difficult. There is no Mathematica program that would allow you to find the best initial conditions to use that would best fit the experimental data but you can determine that to some level of success programatically: try any initial conditions, obtain the solutions by NDSolve, inspect them for fit, change the initial conditions and keep doing this to manually determine the best initial conditions to use that best fits the data.
__________________ "I am beset by the ironies in my life" | 
September 26th, 2009, 12:06 PM
| | Newbie | | Join Date: Sep 2009
Posts: 8
Country: Thanks: 0
Thanked 3 Times in 3 Posts
| | Yes, the data is being fit to the solution of the equations (there are 5). I know the initial variable conditions, so that doesn't add any additional complexity. What I don't know are the parameter values - I have done manual changes to the parameters to determine a reasonable fit (using another language), and I'm hoping to do an automated search to optimize them further.
So you're suggesting I run NDSolve with my system of equations (DSolve won't do it, as you suggest), and input the results into FindFit? | 
September 26th, 2009, 12:24 PM
| | Super Member | | Join Date: Aug 2008
Posts: 836
Country: Thanks: 54
Thanked 338 Times in 298 Posts
| |
__________________ "I am beset by the ironies in my life"
Last edited by shawsend; September 26th, 2009 at 01:09 PM.
Reason: just simplified it
| 
September 26th, 2009, 03:51 PM
| | Newbie | | Join Date: Sep 2009
Posts: 8
Country: Thanks: 0
Thanked 3 Times in 3 Posts
| | They're first order but nonlinear and not autonomous, as in:
I forget the exact form of the others (they're not with me at home over the weekend  ), but they're similar in general form; for instance the most complicated term in all of them is  . The initial conditions are all integer values.
By parameters I mean non-variables, so the "a" terms as opposed to the "x" terms above.
Thanks again for your continuing help! | 
September 26th, 2009, 05:42 PM
| | Super Member | | Join Date: Aug 2008
Posts: 836
Country: Thanks: 54
Thanked 338 Times in 298 Posts
| | Ok. I've thought about it and now feel this is not at all easy. Consider just a 2x2 system with four parameters:
That's already a very complicated system when you consider all possibilities of the eigenvalues and further, the cases are qualitatively different. It's an interesting concept and I would approach it by first studying the 2x2 system to see if it's even possible to determine effectively, then maybe scale-up to a 3x3 system. But I wouldn't start with your 5x5 system.
__________________ "I am beset by the ironies in my life" | 
September 27th, 2009, 07:59 AM
| | Newbie | | Join Date: Sep 2009
Posts: 8
Country: Thanks: 0
Thanked 3 Times in 3 Posts
| | Ok, thanks very much! | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -7. The time now is 06:55 AM. | | |