New Reply

Matlab: Fitting to two functions simultaneously

 
Share Thread
Nov12-10, 04:12 PM   #1
 

Matlab: Fitting to two functions simultaneously


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.
PhysOrg.com science news on PhysOrg.com

>> City-life changes blackbird personalities, study shows
>> Origins of 'The Hoff' crab revealed (w/ Video)
>> Older males make better fathers: Mature male beetles work harder, care less about female infidelity
Nov12-10, 05:33 PM   #2
 
Recognitions:
Homework Helper Homework Help
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.
Nov15-10, 12:13 PM   #3
 
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!
Jan3-11, 12:51 AM   #4
 

Matlab: Fitting to two functions simultaneously


I also have same problem for fitting my data, help me toooooooooo
Jan3-11, 06:57 PM   #5
 
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!!
Jan4-11, 10:10 AM   #6
 
I found!!!!!!!!!!!

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

try......
http://wiki.originlab.com/~originla/...mplex_Function
New Reply

Similar discussions for: Matlab: Fitting to two functions simultaneously
Thread Forum Replies
solving four ordinary dif equations simultaneously using ode45 matlab Math & Science Software 12
curve fitting using matlab Engineering, Comp Sci, & Technology Homework 1
MATLAB Curve Fitting Question? Introductory Physics Homework 1
Curve fitting in Matlab Math & Science Software 1
curve fitting using Matlab Math & Science Software 0