How to fit two data sets, y1 and y2, to different functions with shared parameters.
2 views (last 30 days)
Show older comments
The two data vectors, y1(x) and y2(x), have a common x vector (dimension ~30) and common fit parameters, a=[a1,a2,a3,a4] The two fitting equations are biexponentials:
y1 = a1+[a2*exp(-x/a3)] + [(1-a2)*exp(-x/a4)] and
y2 = a1+[a2*exp(-x/a4)] + [(1-a2)*exp(-x/a3)].
0 Comments
Answers (1)
Star Strider
on 16 Mar 2020
y1 = rand(10,1); % Create Data
y2 = rand(10,1); % Create Data
x = 0:9; % Create Data
objfcn = @(a,x) [a(1)+a(2).*exp(-x./a(3)) + (1-a(2)).*exp(-x./a(4));
a(1)+a(2).*exp(-x./a(4)) + (1-a(2)).*exp(-x./a(3))];
a0 = rand(4,1); % Use Appropriate Initial Parameter Estimates
B = lsqcurvefit(objfcn, a0, x(:).', [y1(:) y2(:)].'); % Forced Column Vectors & Transpositions Force Data To Conform To Objective Function Size
It does not matter of the data are row or column variables, since the code forces them to fit the ‘objfcn’ dimensions.
0 Comments
See Also
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!