Obtaining uncertainty in parameters fitting discrete data points with component data, using "\" or "mldivide"
Show older comments
I'm not too familiar with the statistics behind least-square fitting, but please bear with me.
I would like to fit a data set ("Result") with linear combinations of component data sets ("a", "b"). I'm currently using the "\" command, which is equivalent to mldivide:
x =[a;b]'\Result'

A linear combination of the red and yellow curve creates the blue curve that fits the blue curve.
For example, a result would be:
x =
0.9796
0.2119
However, is there any way I can obtain uncertainty/error from doing this? Thanks.
Accepted Answer
More Answers (1)
Walter Roberson
on 9 Jul 2017
0 votes
curvefit() is the only related call that returns r-squared directly. https://www.mathworks.com/help/curvefit/fit.html#outputarg_gof
2 Comments
Jonas Yeung
on 9 Jul 2017
Edited: Jonas Yeung
on 9 Jul 2017
Walter Roberson
on 9 Jul 2017
%create some input data.
%replace this section with reading in your a, b, and c
t = linspace(0,1,50);
a = exp(-(t-1/2).^2);
b = tan(t);
x1 = randn(); x2 = randn();
c = a*x1 + b*x2; %x1 and x2 will need to be recovered
%create the fitting type
ft = fittype('a*x1+b*x2', 'coeff', {'x1','x2'}, 'indep', {'a','b'});
%guess an initial solution to keep it quiet
x0 = [.5 .5]
%do the fitting
[x, gof] = fit( [a(:), b(:)], c(:), ft, 'StartPoint', x0 )
%how good was it?
gof.rsquare
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!