Matlab: Fitting to two functions simultaneously

Click For Summary
SUMMARY

This discussion focuses on fitting two data sets to two different functions, F1 and F2, in Matlab while sharing the same coefficients. The user initially struggled with the lsqcurvefit function but found success in Sigmaplot by combining data sets and using conditional statements. A proposed solution involves formulating the problem as a matrix minimization rather than relying solely on lsqcurvefit. Additionally, Origin 8 is mentioned as a capable tool for complex fitting tasks.

PREREQUISITES
  • Understanding of Matlab programming and syntax
  • Familiarity with curve fitting techniques, specifically lsqcurvefit
  • Knowledge of matrix operations and minimization problems
  • Experience with data manipulation and conditional logic in programming
NEXT STEPS
  • Explore Matlab's matrix operations for solving least squares problems
  • Learn about Matlab's surface fitting tool for multi-function fitting
  • Investigate Origin 8's capabilities for complex fitting
  • Review documentation on conditional statements in Matlab for data fitting
USEFUL FOR

Researchers and engineers conducting data analysis, Matlab users looking to perform simultaneous curve fitting, and anyone interested in advanced fitting techniques using Origin 8.

Sonolum
Messages
39
Reaction score
0
Okay, here's a problem that I've been struggling with for a few weeks.

I'm conducting a series of measurements, where I get two sets of data, i.e. one xdata value gives me two ydata values. I want to curve fit the two data sets to two different functions, F1 and F2, that depend on the same coefficients. By fitting ydata1 to F1 and ydata2 to F2, I hope to extract the coefficients that best fits to both data sets.

While I can fit to F1 or F2 separately, I can't seem to fit to both at once. The curve-fitting tool doesn't seem capable of this, and I've been playing around with lsqcurvefit but with no success. I haven't found any other functions that seem able to do what I want.

The thing is, I was able to set this fit up in a graphing program called Sigmaplot. In that program, I combined my data sets into one by copying one after the other, and then created another variable d which I defined as 0 for all the ydata1 points and 1 for all ydata2 points--

i.e. xdata=[xdata , xdata]; ydata=[ydata1 , ydata2]; d=[0,...,0,1,...,1]

Then I added an if statement in my fitting model, saying "if d==0, fit to F1, else fit to F2".

It works, but it's a pain because I have to manually enter the data and set up the fits and initial guess values by hand. I was hoping to use Matlab to set everything up automatically, but my attempts to do something similar haven't worked. Any suggestions would be greatly appreciated.
 
Physics news on Phys.org
Seems a little odd that both functions would have the same parameters, but if that's the case, I think the least squares problem would be:

[ATA + BTB]z = ATy1 + BTy2

Can't you just assemble the matrices A & B and perform the calculations with Matlab to solve for z? Maybe I'm looking at this too simplistically.
 
I think you may be onto something here!

I have been trying to write an if/else loop to create the two functions to fit to, which MatLab seems to vehemently dislike. Phrasing the problem in the manner you've suggested makes it a minimization of a matrix problem, instead of an lsqcurvefit problem, which (hopefully) MatLab will like a bit better.

Thank you, I will give it a try and see if it'll work this way, I really appreciate it! However, if it's all fail, then I'll be back to prod the internet community's collective brain for additional assistance. In the meantime, thank you again!
 
I also have same problem for fitting my data, help me toooooooooo
 
Soooooo... I think we might have a solution, though I'm still working out all the details on Matlab...

We're trying to use the surface fitting tool to fit to both functions.

I will update this thread as soon as I get it working with better instructions!

Best wishes, and if you figure this out before I do, please let me know!
 
I found!

Origin 8 can do this. We can do complex fitting also.

try...
http://wiki.originlab.com/~originla/howto/index.php?title=Tutorial:Fitting_Complex_Function
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 6 ·
Replies
6
Views
6K