Fitting multiple datasets with unique parameters using lsqcurvefit to a normalized function and constraints between datasets.
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:
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.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:
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. 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:
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. lsqcurvefit, curve fitting, optimization MATLAB Answers — New Questions