Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Math Resources > Mathematics Software Discussion
Reply
 
Thread Tools Display Modes
  #1  
Old September 25th, 2009, 09:44 AM
Newbie
 
Join Date: Sep 2009
Posts: 8
Country:
Thanks: 0
Thanked 3 Times in 3 Posts
Lujan is on a distinguished road
Default 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!
Reply With Quote
Advertisement
 
  #2  
Old September 25th, 2009, 03:37 PM
Super Member
 
Join Date: Aug 2008
Posts: 836
Country:
Thanks: 54
Thanked 338 Times in 298 Posts
shawsend is just really niceshawsend is just really niceshawsend is just really niceshawsend is just really nice
Default

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"
Reply With Quote
  #3  
Old September 26th, 2009, 10:10 AM
Newbie
 
Join Date: Sep 2009
Posts: 8
Country:
Thanks: 0
Thanked 3 Times in 3 Posts
Lujan is on a distinguished road
Default

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....
Reply With Quote
  #4  
Old September 26th, 2009, 11:26 AM
Super Member
 
Join Date: Aug 2008
Posts: 836
Country:
Thanks: 54
Thanked 338 Times in 298 Posts
shawsend is just really niceshawsend is just really niceshawsend is just really niceshawsend is just really nice
Default

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"
Reply With Quote
  #5  
Old September 26th, 2009, 12:06 PM
Newbie
 
Join Date: Sep 2009
Posts: 8
Country:
Thanks: 0
Thanked 3 Times in 3 Posts
Lujan is on a distinguished road
Default

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?
Reply With Quote
  #6  
Old September 26th, 2009, 12:24 PM
Super Member
 
Join Date: Aug 2008
Posts: 836
Country:
Thanks: 54
Thanked 338 Times in 298 Posts
shawsend is just really niceshawsend is just really niceshawsend is just really niceshawsend is just really nice
Default

Ok. That's a start. When you say parameters, you mean in the differential equations themselves? Are they first order and linear (and autonomous)? Do they look like:

x_1'=a_1 x_1+a_2 x_2+a_3 x_3+a_4 x_4+a_5 x_5,\quad x_1(0)=k_1

x_2'=b_1 x_1+b_2 x_2+b_3 x_3+b_4 x_4+b_5 x_5,\quad x_2(0)=k_2

x_3'=c_1 x_1+c_2 x_2+c_3 x_3+c_4 x_4+c_5 x_5,\quad x_3(0)=k_3

x_4'=d_1 x_1+d_2 x_2+d_3 x_3+d_4 x_4+d_5 x_5,\quad x_4(0)=k_4

x_5'=f_1 x_1+f_2 x_2+f_3 x_3+f_4 x_4+f_5 x_5,\quad x_5(0)=k_5

Can you post your equations?
__________________
"I am beset by the ironies in my life"

Last edited by shawsend; September 26th, 2009 at 01:09 PM. Reason: just simplified it
Reply With Quote
  #7  
Old September 26th, 2009, 03:51 PM
Newbie
 
Join Date: Sep 2009
Posts: 8
Country:
Thanks: 0
Thanked 3 Times in 3 Posts
Lujan is on a distinguished road
Default

They're first order but nonlinear and not autonomous, as in:
x_1'=a_1x-(a_2 x_1/(x_1+a_3))(x_2+x_3+x_4+x_5)

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 x_1/(x_1+a_3). 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!
Reply With Quote
  #8  
Old September 26th, 2009, 05:42 PM
Super Member
 
Join Date: Aug 2008
Posts: 836
Country:
Thanks: 54
Thanked 338 Times in 298 Posts
shawsend is just really niceshawsend is just really niceshawsend is just really niceshawsend is just really nice
Default

Ok. I've thought about it and now feel this is not at all easy. Consider just a 2x2 system with four parameters:

x'=ax+by

y'=cx+fy

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"
Reply With Quote
  #9  
Old September 27th, 2009, 07:59 AM
Newbie
 
Join Date: Sep 2009
Posts: 8
Country:
Thanks: 0
Thanked 3 Times in 3 Posts
Lujan is on a distinguished road
Default

Ok, thanks very much!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 06:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.