Fitting multiple datasets with unique parameters using lsqcurvefit to a normalized function and constraints between datasets.
조회 수: 4 (최근 30일)
이전 댓글 표시
Thank you for taking the time to help. I will do my best to be clear and concise.
I have 3 sets of data (atttached), each with x and y data - not necesarilly the same length.
Each y(x) function can be normalized into p(t) using 4 parameters:
- A - a constant that is extracted from each individual y(x), 'A' looks like [A1, A2, A3]
- B - a fitting parameter unique to each y(x)
- C - a fitting parameter applied to all y(x)
- D - a constraint variable dependent on A and B applied to all y(x)
So the set looks something like: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1748869/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1748869/image.png)
I would like to use lsqcurvefit to fit my data to my function p(t) and output the unique (C and D) values.
I have a final constraint to increase the accuracy of lsqcurvefit:
, where D is another global constant like C.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1748874/image.png)
Where I'm at now, I want to adjust C and D to fit my function p(t) to y(x), but I don't know how to also include the unique A values for each y(x).
I've pasted my current code below where I am able to get an individual fit for each y(x) but without consistent C and D parameters.
%% Data analysis
Results = NaN(3,2); % Result [C,D] for each individual fitting
for t = 1:3
%TL is summary matrix of all y(x) for the 3 experiments, NaN fills in
%where some y(x) are shorter than others.
x = TL(~isnan(TL(:,2*t-1)),2*t-1); %extracts x values from TL
y = TL(~isnan(TL(:,2*t)),2*t); %extracts y values from TL
%P = parameters: P(1) = C | P(2) = D
%fun below is the normalization for p(t)
fun = @(P,x)A(t)*(1-1/(2*(1-P(1))))*(1.304*exp(-(P(2)*x/(r/1000)^2).^0.5)-0.304*exp(-0.254*P(2)*x/(r/1000)^2))+1/(2*(1-P(1)));
P0 = [0.4, 1*10^-9]; %Initial parameters
lb = [0.1, 1*10^-10]; %Lower bound
ub = [0.5, 1*10^-8]; %Upper bound
Results(t,:) = lsqcurvefit(fun,P0,x,y,lb,ub); %Result consolidation for individual fitting
subplot(3,1,t)
plot(x,y,'ko',x,fun(Results(t,:),x),'b-')
end
From looking at other posts on using lsqcurvefit with multiple datasets, I think my obstacle has come down to whether I should (1) run lsqcurvefit on all y(x) and somehow input the unique A constants or (2) run lsqcurvefit on individual y(x) and somehow correlate C and D to match between each fitting.
I hope this is presented clearly, looking forward to your thoughts and discussion - Thanks.
댓글 수: 0
답변 (1개)
Torsten
2024년 8월 8일
편집: Torsten
2024년 8월 8일
If your model functions share common parameters, you must run "lsqcurvefit" on all yi with all parameters present (in your case eight as far as I can see).
Since the computation of the simulated values is more complex than it can be done in a one-liner by a function handle, you should write a separate function for this.
댓글 수: 3
Torsten
2024년 8월 8일
I see where you get the 8 parameters, but A and B are dependent on D.
Why do you define D at all as a fitting parameter if it can be replaced by A1/B1 ?
Is there a way to run lsqcurvefit varying two parameters and taking in a set of constants?
You don't need to "take constants in", you can just define them in the function where you supply the simulated yi.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!