Nonlinear regression not working

2 visualizzazioni (ultimi 30 giorni)
Sameer Kulkarni
Sameer Kulkarni il 22 Set 2022
Commentato: Sameer Kulkarni il 22 Set 2022
I want to find the parameters of a nonlinear function based on experimental data. The function involves an integral whose upper limit is the independent variable I'm passing in. I'm trying the nlinfit and lsqcurvefit functions, but both functions don't seem to optimize the guess for some reason. If anyone could help me trying to figure out why it isn't working properly I would really appreciate it. Thanks a lot in advance!
My function
Below is my code.
clc;
clear all;
input0= [160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121
0 0.00077053 0.0030894 0.006968 0.012418 0.019451 0.028057 0.038074 0.049486 0.062734 0.078769 0.098834 0.12418 0.15593 0.19477 0.2407 0.29315 0.35117 0.41346 0.47835 0.5437 0.60717 0.6667 0.72101 0.76954 0.81205 0.84846 0.87886 0.90338 0.92262 0.93791 0.95072 0.96188 0.97165 0.98013 0.98719 0.99274 0.99674 0.99918 1
];
input0=input0';
T= input0(:,1);
t = zeros(length(input0),1);
for i=1:length(input0)
t(i)=(T(1)-T(i))./50;
end
alp = input0(:,2);
% X, Y data
g = [t alp];
% guess
x0=[2.4; 140.7; 44.94];
% Fitting the constants
fun12 = @(constant,time) constant(1)*exp((-4*log(2)*((-time*50+ 160)-constant(2)).^2)/constant(3).^2);
fun11 = @(constant,t) 1-exp(-(arrayfun(@(t) integral(@(t)fun12(constant,t),0,t),t)).^3) ;
constant_new = nlinfit(g(1),g(2),fun11,x0)
Warning: Rank deficient, rank = 0, tol = 0.000000e+00.
Warning: The model is overparameterized, and model parameters are not identifiable. You will not be able to compute confidence or prediction intervals, and you should use caution in making predictions.
constant_new = 3×1
2.4000 140.7000 44.9400
%constant_new = lsqcurvefit(fun11,x0,g(1),g(2)) % this is not working either
% Plotting experimental data
plot (t,alp,'ko','Linewidth',1.5)
hold on;
% Plotting the fit
plot(t,fun11(constant_new,t),'Linewidth',1.5);
legend('Input data','Fit')
set(gca,'FontSize',14,'FontName', 'Verdana');
grid on;

Risposta accettata

Torsten
Torsten il 22 Set 2022
clc;
clear all;
input0= [160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121
0 0.00077053 0.0030894 0.006968 0.012418 0.019451 0.028057 0.038074 0.049486 0.062734 0.078769 0.098834 0.12418 0.15593 0.19477 0.2407 0.29315 0.35117 0.41346 0.47835 0.5437 0.60717 0.6667 0.72101 0.76954 0.81205 0.84846 0.87886 0.90338 0.92262 0.93791 0.95072 0.96188 0.97165 0.98013 0.98719 0.99274 0.99674 0.99918 1
];
input0=input0';
T= input0(:,1);
t = zeros(length(input0),1);
for i=1:length(input0)
t(i)=(T(1)-T(i))./50;
end
alp = input0(:,2);
% X, Y data
g = [t, alp];
% guess
x0=[2.4; 140.7; 44.94];
% Fitting the constants
fun12 = @(constant,time) constant(1)*exp((-4*log(2)*((-time*50+ 160)-constant(2)).^2)/constant(3).^2);
fun11 = @(constant,t) 1-exp(-(arrayfun(@(t) integral(@(t)fun12(constant,t),0,t),t)).^3) ;
constant_new = nlinfit(g(:,1),g(:,2),fun11,x0)
constant_new = 3×1
2.6316 140.6281 48.6762
%constant_new = lsqcurvefit(fun11,x0,g(1),g(2)) % this is not working either
% Plotting experimental data
plot (t,alp,'ko','Linewidth',1.5)
hold on;
% Plotting the fit
plot(t,fun11(constant_new,t),'Linewidth',1.5);
legend('Input data','Fit')
set(gca,'FontSize',14,'FontName', 'Verdana');
grid on;

Più risposte (0)

Categorie

Scopri di più su Optimization in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by