Fitting multiple datasets with unique parameters using lsqcurvefit to a normalized function and constraints between datasets.

2 visualizzazioni (ultimi 30 giorni)
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:
  1. A - a constant that is extracted from each individual y(x), 'A' looks like [A1, A2, A3]
  2. B - a fitting parameter unique to each y(x)
  3. C - a fitting parameter applied to all y(x)
  4. D - a constraint variable dependent on A and B applied to all y(x)
So the set looks something like:
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.
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.

Risposte (1)

Torsten
Torsten il 8 Ago 2024
Modificato: Torsten il 8 Ago 2024
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 Commenti
Torsten
Torsten il 8 Ago 2024
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.
Nolan Miller
Nolan Miller il 8 Ago 2024
For the first part, it is because each y(x) corresponds to a specific A#, B#. There is a constraint equation that , so this goes back to running all datasets for C and D or individual datasets. Ultimately, I want to extract best fit parameters C and D because those must be the same across fitting all y(x) to p(t).
With my current code, I'm getting the output you suggest by ignoring the D constraint where I use specific A# and B# to fit y(x) to p(t), but then between different y(x) I get different C and D values (which should not be the case).
In regards to the constants, I suppose it would be more precise to say that they are not "constants" with respect to lsqcurvefit, but rather that each A value does not change with respect to fitting lsqcurvefit to its own y(x) and only changes with respect to fitting different y(x).
Thank you for your help

Accedi per commentare.

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by