Curve Fitting with multiple Y data point for each X
Show older comments
Hi I would like to fit a Gaussian curve to some data. The data are from 3 subjects and there are 7 x data points.
x = [-90 -45 -22.5 - 22.5 45 90] y = [0.3099 0.4806 0.5899 0.6836 0.6635 0.5841 0.2969; 0.2096 0.5600 0.2403 0.7877 0.8406 0.6927 0.2095; 0.1274 0.1973 0.1632 0.5383 0.6522 0.4410 0.1696];
I think I can do the fitting if I average across subjects first but I want to do the fit across all subjects 'at the same time'.
How can I do that??
Thanks for you help,
Pat
Accepted Answer
More Answers (1)
Matt J
on 28 Mar 2013
0 votes
I think I can do the fitting if I average across subjects first but I want to do the fit across all subjects 'at the same time'
The 2 results would be equivalent.
1 Comment
The fitted curve would be the same. If you fit "all the data" you are minimizing the following cost function with respect to x
sum_{i=[1,2,3]} [norm(F(x,xdata)-y_i)^2]/3
= sum_i [norm(F(x,xdata))^2 + 2*dot(F(x,xdata),y_i)]/3 + constant
= norm(F(x,xdata))^2 + 2*dot(F(x,xdata), sum_i y_i/3) + constant
= norm(F(x,xdata)-sum_i y_i/3)^2 +constant
This shows that minimizing the original curve fitting function is equivalent to minimizing
norm(F(x,xdata)-sum_i y_i/3)^2
which is the same as fitting the average of the data sum_i y_i/3.
I though I'd have more info if I run it at the same time across all the subjects!
You will have more info. The average over y_i will reflect that additional information.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!