estimation of parameters by using lsqnonlin for system of differential equations
Afficher commentaires plus anciens
1 36456
2 33761
3 38309
4 36638
5 36111
6 32272
7 27107
8 32067
9 26357
10 34666
11 30034
12 30354
13 27336
14 21941
15 26401
16 18164
17 26762
18 26991
19 26834
20 24589
21 19174
22 23886
23 24236
24 23924
25 22350
26 18574
27 20333
28 16072
29 20529
30 21957
31 19046
32 19522
33 19460
34 18938
35 18967
36 18591
37 18381
38 18252
39 18008
40 18105
41 18020
42 17478
43 17191
44 17297
45 16348
46 15877
47 15338
48 15034
49 14678
50 14376
51 14128
52 13959
53 13840
54 13818
55 13714
56 13588
57 13437
58 12905
59 13535
60 13354
61 13094
62 12850
63 12776
64 12529
65 12724
66 11794
67 11602
68 11459
69 11496
70 11515
71 11477
72 11422
73 10986
74 11047
75 11066
76 11054
77 11107
78 11230
79 11276
80 11831
81 12085
82 12331
83 12699
84 12900
85 13198
86 13780
87 14260
88 14638
89 15050
90 15241
91 15495
92 15682
93 15753
94 15785
95 16037
96 16311
97 16745
98 17185
99 17596
100 18371
101 19296
102 20228
103 21147
104 22270
105 23567
106 25138
107 26994
108 29335
109 31629
110 34295
111 37223
112 39537
113 42161
114 44673
115 47444
116 50497
117 53185
118 56213
119 58430
120 59287
121 61958
122 65145
123 68966
124 73304
125 78388
126 84160
127 93028
128 100766
129 107977
130 115974
131 124484
132 133929
133 143114
134 153113
135 163586
136 175723
137 188437
138 203913
139 218937
140 232675
141 248257
142 264852
143 281380
144 297279
145 309865
146 321233
147 330155
148 339945
149 349038
150 356787
151 364870
152 371115
153 373320
154 378505
155 381353
156 386099
157 390029
158 390727
159 392331
160 391812
161 388058
162 383159
163 376017
164 342794
165 354315
166 341022
167 328934
168 319438
169 307822
170 295473
171 283507
172 273656
173 263676
174 255247
175 245652
176 237330
177 228090
178 217638
179 205750
180 194948
181 185028
182 175174
183 142207
184 153274
185 145609
186 137948
187 130692
188 123236
189 117368
190 111601
191 105864
192 100068
193 94942
194 90090
195 85775
196 82090
197 77722
198 73923
199 69721
200 66320
201 63190
202 60615
203 58140
204 56512
205 54658
206 53118
207 51404
208 50151
209 49229
210 48427
211 47754
212 46939
213 46242
214 45588
215 44614
216 43704
217 43269
218 42963
219 42548
220 42080
221 41862
222 41643
223 41286
224 40827
225 40306
226 39743
227 39110
228 38461
229 38431
230 38527
231 38328
232 38587
233 38577
234 37975
235 38173
236 38031
237 38009
238 38209
239 38330
240 38541
241 39942
242 40227
time = data(:,1);
A_data= data(:,2);
beta0 = 0.5;
alpha0 = 0.004;
gamma0 = 0.1;
upsilon0 = 0.13;
epsilon0= 0.07;
lamda0= 0.1;
sigma0= 0.07;
kappa0= 0.03;
nu0 = 0.0001;
xi0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
B0 = [beta0; alpha0; gamma0; upsilon0; epsilon0; lamda0; sigma0; kappa0; nu0; xi0 ];
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@Kinetics,B0,time,A_data,lb,ub,options );
disp(B)
function Av = Kinetics(B,time);
plot(time,A_data,time,Av)
function A = Kinetics(B, t)
x0 = [1217378052,100,3,2,1,1,1,1];
[T,Av] = ode45(@DifEq, t, x0);
function dA = DifEq(t, x)
N = 1390000000;
pi = 70000;
zeta = 0.1;
eta = 0.2;
theta = 0.3;
iota = 0.3;
delta = 0.1;
rho = 0.5;
mu = 0.0000425;
beta = B(1);
alpha =B(2);
gamma = B(3);
upsilon =B(4);
epsilon = B(5);
lamda = B(6);
sigma = B(7);
kappa = B(8);
nu = B(9);
xi = B(10);
xdot = zeros(8,1);
xdot(1) = pi -beta*(zeta*x(3)+eta*x(4)+theta*x(5)+iota*x(6))*(x(1)/N) -mu*x(1);
xdot(2) = beta*(zeta*x(3)+eta*x(4)+theta*x(5)+iota*x(6))*(x(1)/N) -(delta+mu)*x(2);
xdot(3) = rho*delta*x(2)-(lamda+gamma+nu+mu)*x(3);
xdot(4) = (1-rho)*delta*x(2)-(sigma+kappa+mu)*x(4);
xdot(5) = lamda*x(3) + sigma*x(4)-(alpha+upsilon+mu)*x(5);
xdot(6) = alpha*x(6) + kappa*x(4)- (epsilon+xi+mu)*x(6);
xdot(7) = gamma*x(3) + upsilon*x(5) + epsilon*x(6);
xdot(8) = nu*x(3) + xi*x(6);
dA = xdot;
end
A = Av(:,1);
end
i got an error;
Error using lsqnonlin (line 190)
Invalid datatype. Options argument must be created with OPTIMOPTIONS.
Error in error_14bmodel (line 19)
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@Kinetics,B0,time,A_data,lb,ub,options );
i am fresher of matlab .i requesting you sir please help anyone how to resolve this error
if possible please refer some covid 19 or malaria,dengue hepities b models sir
thank you sir
Réponses (4)
Torsten
le 2 Avr 2022
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@Kinetics,B0,time,A_data,lb,ub,options );
This is not the correct call to lsqnonlin, but to lsqcurvefit.
3 commentaires
mallela ankamma rao
le 2 Avr 2022
Torsten
le 2 Avr 2022
You modify this by calling lsqcurvefit instead of lsqnonlin:
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@Kinetics,B0,time,A_data,lb,ub,options );
mallela ankamma rao
le 2 Avr 2022
I recognise my code.
It should have the correct lsqcurvefit call, so all you need to do is substitute your differnetial equations and data into it.
An updated version of that code is:
t=[0.1
0.2
0.4
0.6
0.8
1
1.5
2
3
4
5
6];
c=[0.902 0.06997 0.02463 0.00218
0.8072 0.1353 0.0482 0.008192
0.6757 0.2123 0.0864 0.0289
0.5569 0.2789 0.1063 0.06233
0.4297 0.3292 0.1476 0.09756
0.3774 0.3457 0.1485 0.1255
0.2149 0.3486 0.1821 0.2526
0.141 0.3254 0.194 0.3401
0.04921 0.2445 0.1742 0.5277
0.0178 0.1728 0.1732 0.6323
0.006431 0.1091 0.1137 0.7702
0.002595 0.08301 0.08224 0.835];
theta0=rand(6,1);
[theta,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kinetics,theta0,t,c,zeros(size(theta0)));
fprintf(1,'\tRate Constants:\n')
for k1 = 1:length(theta)
fprintf(1, '\t\tTheta(%d) = %8.5f\n', k1, theta(k1))
end
tv = linspace(min(t), max(t));
Cfit = kinetics(theta, tv);
figure
hd = plot(t, c, 'p');
for k1 = 1:size(c,2)
CV(k1,:) = hd(k1).Color;
hd(k1).MarkerFaceColor = CV(k1,:);
end
hold on
hlp = plot(tv, Cfit);
for k1 = 1:size(c,2)
hlp(k1).Color = CV(k1,:);
end
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend(hlp, compose('C_%d',1:size(c,2)), 'Location','N')
function C=kinetics(theta,t)
c0=[1;0;0;0];
[T,Cv]=ode45(@DifEq,t,c0);
%
function dC=DifEq(t,c)
dcdt=zeros(4,1);
dcdt(1)=-theta(1).*c(1)-theta(2).*c(1);
dcdt(2)= theta(1).*c(1)+theta(4).*c(3)-theta(3).*c(2)-theta(5).*c(2);
dcdt(3)= theta(2).*c(1)+theta(3).*c(2)-theta(4).*c(3)+theta(6).*c(4);
dcdt(4)= theta(5).*c(2)-theta(6).*c(4);
dC=dcdt;
end
C=Cv;
end
.
37 commentaires
mallela ankamma rao
le 2 Avr 2022
Star Strider
le 2 Avr 2022
Do not use lsqnonlin. Use lsqcurvefit just as in my code.
If you absolutely must use lsqnonlin, the objective function to use with it is:
fun = @(theta)norm(kinetics(theta,t) - c);
That is the ‘fun’ argument to it in the lsqnonlin documentation.
This references my code. Make approriate changes to use it with your data and your ‘kinetics’ function.
.
Torsten
le 2 Avr 2022
I think the function to be supplied for lsqnonlin is
fun =@(theta) kinetics(theta,t) -c
to make the objective equal to the one for lsqcurvefit.
mallela ankamma rao
le 2 Avr 2022
mallela ankamma rao
le 2 Avr 2022
Star Strider
le 3 Avr 2022
Try this —
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(theta) kinetics(theta,t) - c, B0,time,A_data,lb,ub,options );
@Torsten — Correct. I rarely use lsqnonlin (and have not in years). The objective function needs to return an array of differences.
.
mallela ankamma rao
le 3 Avr 2022
Star Strider
le 3 Avr 2022
My pleasure!
mallela ankamma rao
le 4 Avr 2022
The list of inputs for your function "immanuel" (Kant ?) must coincide in the call to lsqnonlin and in the function itself.
In your first attempt
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(B)immanuel(B,A_data,tspan,x0),B0,lb,ub,options );
disp(B)
function A = immanuel(B,tspan,x0)
you tell MATLAB that the list of inputs to "immanuel" is
@(B)immanuel(B,A_data,tspan,x0)
but the function itself is defined as
function A = immanuel(B,tspan,x0)
Thus the argument "A_data" in the second position is missing.
In your second attempt where the initial values are returned, you make a similar mistake.
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(B)immanuel(A_data,tspan,x0),B0,lb,ub,options );
disp(B)
function A = immanuel(B,tspan,x0)
Do you see the difference in the input lists
@(B)immanuel(A_data,tspan,x0)
and
immanuel(B,tspan,x0)
?
Furthermore, since you use lsqnonlin and not lsqcurvefit,
A = A_data - Av(:,2)
and not
A = Av(:,2)
is the return parameter from "immanuel" if your experimental data are to be compared with the second solution variable of the ODE integrator.
mallela ankamma rao
le 5 Avr 2022
Star Strider
le 5 Avr 2022
Our pleasure!
mallela ankamma rao
le 5 Avr 2022
A = Av(:,2); % column of Av that corresponds to your measurement data
instead of
A = Av;
Star Strider
le 5 Avr 2022
The problem is that as written, ‘A’ returns a matrix. You are only fitting one column with the output, so choose whatever column that is, for example:
A = Av(:,1); % Return Only One Column To Fit A Column Vector
Thsi arbitrarily chooses the first column, however that may not be correct. Choose the correct column and the code should run with out error and give a reasonable fit (if everything else is coded correctly).
x = [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346];
t = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
x = x(:);
t = t(:);
beta0 = 0.5;
alpha0 = 0.004;
gamma0 = 0.1;
upsilon0 = 0.13;
epsilon0= 0.07;
lamda0= 0.1;
sigma0= 0.07;
kappa0= 0.03;
nu0 = 0.0001;
xi0 = 0.0002;
B0 = [beta0; alpha0; gamma0; upsilon0; epsilon0; lamda0; sigma0; kappa0; nu0; xi0 ];
options = optimoptions('lsqcurvefit', 'Display', 'iter','Algorithm', 'levenberg-marquardt','UseParallel', false,'StepTolerance', 1e-6);
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@Kinetics, B0,t,x, zeros(size(B0)), [], options);
disp(B)
Av = Kinetics(B,t);
plot(t,x,t,Av)
function A = Kinetics(B, t)
x0 =[1217378,12173,300,200,100,100,100,90];
[T,Av] = ode45(@DifEq, t, x0);
function dA = DifEq(t, x)
N = 139000000;
pi = 1500;
zeta = 0.1;
eta = 0.2;
theta = 0.3;
iota = 0.3;
delta = 0.1;
rho = 0.5;
mu = 0.0000425;
beta = B(1);
alpha =B(2);
gamma = B(3);
upsilon =B(4);
epsilon = B(5);
lamda = B(6);
sigma = B(7);
kappa = B(8);
nu = B(9);
xi = B(10);
xdot = zeros(8,1);
xdot(1) = pi -beta*(zeta*x(3)+eta*x(4)+theta*x(5)+iota*x(6))*(x(1)/N) -mu*x(1);
xdot(2) = beta*(zeta*x(3)+eta*x(4)+theta*x(5)+iota*x(6))*(x(1)/N) -(delta+mu)*x(2);
xdot(3) = rho*delta*x(2)-(lamda+gamma+nu+mu)*x(3);
xdot(4) = (1-rho)*delta*x(2)-(sigma+kappa+mu)*x(4);
xdot(5) = lamda*x(3) + sigma*x(4)-(alpha+upsilon+mu)*x(5);
xdot(6) = alpha*x(6) + kappa*x(4)- (epsilon+xi+mu)*x(6);
xdot(7) = gamma*x(3) + upsilon*x(5) + epsilon*x(6);
xdot(8) = nu*x(3) + xi*x(6);
dA = xdot;
end
A = Av(:,1); % Return Only One Column To Fit A Column Vector
end
.
mallela ankamma rao
le 5 Avr 2022
mallela ankamma rao
le 5 Avr 2022
Star Strider
le 5 Avr 2022
That is likely caused by the fact that the differential equation integrators return column vectors (or column-oriented matrices).
Force ‘x’ and ‘t’ to be column vectors.
x = [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346];
t = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
x = x(:);
t = t(:);
That will then work.
Also, Torsten believes that:
A = Av(:,2);
is correct. Change the column reference to whatever works with your code to regress against the correct column.
.
Torsten
le 5 Avr 2022
Testing your code shows that changing
x = [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346];
t = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
to
x = [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346].';
t = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19].';
removes the problem.
mallela ankamma rao
le 6 Avr 2022
mallela ankamma rao
le 6 Avr 2022
Star Strider
le 6 Avr 2022
A related example —
t=[0.1
0.2
0.4
0.6
0.8
1
1.5
2
3
4
5
6];
c=[0.902 0.06997 0.02463 0.00218
0.8072 0.1353 0.0482 0.008192
0.6757 0.2123 0.0864 0.0289
0.5569 0.2789 0.1063 0.06233
0.4297 0.3292 0.1476 0.09756
0.3774 0.3457 0.1485 0.1255
0.2149 0.3486 0.1821 0.2526
0.141 0.3254 0.194 0.3401
0.04921 0.2445 0.1742 0.5277
0.0178 0.1728 0.1732 0.6323
0.006431 0.1091 0.1137 0.7702
0.002595 0.08301 0.08224 0.835];
ftns = @(theta) norm(c-kinetics(theta,t));
PopSz = 500;
Parms = 10;
opts = optimoptions('ga', 'PopulationSize',PopSz, 'InitialPopulationMatrix',randi(1E+4,PopSz,Parms)*1E-3, 'MaxGenerations',5E3, 'FunctionTolerance',1E-8, 'PlotFcn',@gaplotbestf, 'PlotInterval',1);
t0 = clock;
fprintf('\nStart Time: %4d-%02d-%02d %02d:%02d:%07.4f\n', t0)
[theta,fval,exitflag,output,population,scores] = ga(ftns, Parms, [],[],[],[],zeros(Parms,1),Inf(Parms,1),[],[],opts);
t1 = clock;
fprintf('\nStop Time: %4d-%02d-%02d %02d:%02d:%07.4f\n', t1)
GA_Time = etime(t1,t0)
DT_GA_Time = datetime([0 0 0 0 0 GA_Time], 'Format','HH:mm:ss.SSS');
fprintf('\nElapsed Time: %23.15E\t\t%s\n\n', GA_Time, DT_GA_Time)
fprintf('Fitness value at convergence = %.4f\nGenerations \t\t\t\t = %d\n\n',fval,output.generations)
fprintf(1,'\tRate Constants:\n')
for k1 = 1:length(theta)
fprintf(1, '\t\tTheta(%2d) = %8.5f\n', k1, theta(k1))
end
tv = linspace(min(t), max(t));
Cfit = kinetics(theta, tv);
figure
hd = plot(t, c, 'p');
for k1 = 1:size(c,2)
CV(k1,:) = hd(k1).Color;
hd(k1).MarkerFaceColor = CV(k1,:);
end
hold on
hlp = plot(tv, Cfit);
for k1 = 1:size(c,2)
hlp(k1).Color = CV(k1,:);
end
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend(hlp, compose('C_%d',1:size(c,2)), 'Location','N')
function C=kinetics(theta,t)
c0 = theta(7:10);
% c0=[1;0;0;0];
[T,Cv]=ode45(@DifEq,t,c0);
%
function dC=DifEq(t,c)
dcdt=zeros(4,1);
dcdt(1)=-theta(1).*c(1)-theta(2).*c(1);
dcdt(2)= theta(1).*c(1)+theta(4).*c(3)-theta(3).*c(2)-theta(5).*c(2);
dcdt(3)= theta(2).*c(1)+theta(3).*c(2)-theta(4).*c(3)+theta(6).*c(4);
dcdt(4)= theta(5).*c(2)-theta(6).*c(4);
dC=dcdt;
end
C=Cv;
end
Its running time exceeds the 55 seconds that the online Run feature enforces, so copy it as is, save it to a new .m file on your MATLAB search path, and run it to see how it works. When I ran it a few minutes ago, it required about 11 minutes to converge (AMD Ryzen 9 3900 processor).
.
mallela ankamma rao
le 6 Avr 2022
Star Strider
le 6 Avr 2022
My pleasure!
mallela ankamma rao
le 6 Avr 2022
This seems to run without error —
t = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
c = [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346];
t = t(:);
c = c(:);
% theta = [0.5,0.004,0.1,0.13,0.07,0.1,0.07,0.03,0.0001,0.0002 ];
ftns = @(theta) norm(c-kinetics(theta,t));
PopSz = 500;
Parameter = 18;
opts = optimoptions('ga','PopulationSize',PopSz,'InitialPopulationMatrix',randi(1E+4,PopSz,Parameter).*[ones(1,10)*1E-3 ones(1,8)*10],'MaxGenerations',1E4, 'FunctionTolerance',1E-10);%, 'PlotFcn','gaplotbestf'); %how can I interpret the InitialPopulationMatrix?
t0 = clock;
fprintf('\nStart Time: %4d-%02d-%02d %02d:%02d:%07.4f\n',t0)
[p,fval,exitflag,output] = ga(ftns,Parameter,[],[],[],[],zeros(Parameter,1),[ones(10,1); Inf(8,1)],[],[],opts);
disp(p)
t1 = clock;
fprintf('\nStop Time: %4d-%02d-%02d %02d:%02d:%07.4f\n', t1)
GA_Time = etime(t1,t0);
DT_GA_Time = datetime([0 0 0 0 0 GA_Time], 'Format','HH:mm:ss.SSS');
fprintf('\nElapsed Time: %23.15E\t\t%s\n\n', GA_Time, DT_GA_Time)
fprintf('Fitness value at convergence = %.4f\nGenerations \t\t\t = %d\n\n',fval,output.generations)
fprintf(1,'\tRate Constants:\n')
for k1 = 1:length(p)
fprintf(1, '\t\tTheta(%2d) = %8.5f\n', k1, p(k1))
end
tv = linspace(min(t), max(t));
Cfit = kinetics(p, tv);
figure
hd = plot(t, c, 'p');
for k1 = 1:size(c,2)
CV(k1,:) = hd(k1).Color;
hd(k1).MarkerFaceColor = CV(k1,:);
end
hold on
hlp = plot(tv, Cfit);
for k1 = 1:size(c,2)
hlp(k1).Color = CV(k1,:);
end
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend(hlp, compose('C_%d',1:size(c,2)), 'Location','N')
function C=kinetics(theta,t)
% c0 = [1217,100,3,2,1,1,1,1];
c0 = theta(11:18);
[T,CV]=ode45(@DifEq,t,c0);
%
function dC=DifEq(t,c)
N = 13900;
pi = 700;
zeta = 0.1;
eta = 0.2;
rita = 0.3;
iota = 0.3;
delta = 0.1;
rho = 0.5;
mu = 0.0000425;
beta = theta(1);
alpha =theta(2);
gamma = theta(3);
upsilon =theta(4);
epsilon = theta(5);
lamda = theta(6);
sigma = theta(7);
kappa = theta(8);
nu = theta(9);
xi = theta(10);
dcdt = zeros(8,1);
dcdt(1) = pi -beta*(zeta*c(3)+eta*c(4)+rita*c(5)+iota*c(6))*(c(1)/N) -mu*c(1);
dcdt(2) = beta*(zeta*c(3)+eta*c(4)+rita*c(5)+iota*c(6))*(c(1)/N) -(delta+mu)*c(2);
dcdt(3) = rho*delta*c(2)-(lamda+gamma+nu+mu)*c(3);
dcdt(4) = (1-rho)*delta*c(2)-(sigma+kappa+mu)*c(4);
dcdt(5) = lamda*c(3) + sigma*c(4)-(alpha+upsilon+mu)*c(5);
dcdt(6) = alpha*c(6) + kappa*c(4)- (epsilon+xi+mu)*c(6);
dcdt(7) = gamma*c(3) + upsilon*c(5) + epsilon*c(6);
dcdt(8) = nu*c(3) + xi*c(6);
dC=dcdt;
end
C=CV(:,2);
end
Giving it more iterations and a larger 'InitialPopulationMatrix' that I did here (I originally limited it to 50 rows in order to work with the onlilne Run feature) will llikely provide a better fit to the data.
The first 10 values of ‘theta’ are the parameters, and the last 8 are the initial conditions for the differential equations.
.
mallela ankamma rao
le 7 Avr 2022
Star Strider
le 7 Avr 2022
My code considers the initial conditions, as well as the kinetic constants, as parameters to be estimated. I would use the parameters and initial conditions my code estimates.
It may be necessary to run the genetic algorithm several times (probably at least 10) in order to get the best parameter estimates. Choose the set with the lowest fitness value at convergence.
If they are different from the publised data, they may be correct and the published data may not be. It would be necessary to know how the authors estimated their parameters in order to be certain the published parameters are correct. You can always run the published parameters and initial conditions with your integrated differential equations to see how well they fit the data. I encourage you to do that.
mallela ankamma rao
le 7 Avr 2022
Star Strider
le 7 Avr 2022
The ga function can take a while to converge. It will be necessary to be certain that you are returning the correct column of ‘Cv’ as ‘C’. It converged relatively rapidly when I ran it.
Use this options structure:
opts = optimoptions('ga','PopulationSize',PopSz,'InitialPopulationMatrix',randi(1E+4,PopSz,Parameter).*[ones(1,10)*1E-3 ones(1,8)*10],'MaxGenerations',1E4, 'FunctionTolerance',1E-10, 'PlotFcn','gaplotbestf');
That will plot the progress of the optimisation so you can see how it is working.
Also, defining:
PopSz = 250;
will speed up its convergence without sacrificing accuracy.
.
mallela ankamma rao
le 7 Avr 2022
Star Strider
le 7 Avr 2022
mallela ankamma rao
le 7 Avr 2022
Star Strider
le 7 Avr 2022
I did not run it again, however it appears to be correct.
The plot titles tell what the simulation is doing. More information is always better.
mallela ankamma rao
le 7 Avr 2022
Torsten
le 7 Avr 2022
Why do you plot in "kinetics" and not in your script when lsqnonlin has finished ?
After you got the parameters from lsqnonlin, you can call "kinetics" to get Cv for your plot:
c_data= [503,502,575,513,484,376,405,406,339,490,444,397,341,397,341,356,387,359,346];
time = [1 2 3 4 5 7 9 11 13 15 17 21 25 30 40 50 60];
beta0 = 0.5;
alpha0 = 0.004;
gamma0 = 0.1;
upsilon0 = 0.13;
epsilon0= 0.07;
lamda0= 0.1;
sigma0= 0.07;
kappa0= 0.03;
nu0 = 0.0001;
xi0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
p0 = [beta0; alpha0; gamma0; upsilon0; epsilon0; lamda0; sigma0; kappa0; nu0; xi0 ];
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
[p,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(p) kinetics(p,time,c_data),p0,lb,ub,options );
c_data_minus_Cv=kinetics(p,time,c_data);
Cv = c_data - c_data_minus_Cv;
plot(time,c_data, time,Cv)
mallela ankamma rao
le 8 Avr 2022
mallela ankamma rao
le 13 Avr 2022
0 votes
3 commentaires
Torsten
le 13 Avr 2022
You mustn't plot
plot(time,c_data,time,C)
but
plot(time,c_data,time,Cv(:,2))
and - as I already wrote - you should do it in your calling program:
time = data(:,1);
c_data= data(:,2);
beta0 = 0.5;
alpha0 = 0.004;
gamma0 = 0.1;
upsilon0 = 0.13;
epsilon0= 0.07;
lamda0= 0.1;
sigma0= 0.07;
kappa0= 0.03;
nu0 = 0.0001;
xi0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
p0 = [beta0; alpha0; gamma0; upsilon0; epsilon0; lamda0; sigma0; kappa0; nu0; xi0 ];
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
[p,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(p) immanuel(p,time,c_data),p0,lb,ub,options );
Cdata_minus_Cv =immanuel(p,time,c_data);
Cv = c_data-Cdata_minus_Cv;
plot(time,[c_data,Cv])
mallela ankamma rao
le 13 Avr 2022
mallela ankamma rao
le 13 Avr 2022
Torsten
le 13 Avr 2022
data = [ 1 36456
2 70217
3 108526
4 145164
5 181275
6 213547
7 240654
8 272721
9 299078
10 333744
11 363778
12 394132
13 421468
14 443409
15 469810
16 487974
17 514736
18 541727
19 568561
20 593150
21 612324
22 636210
23 660446
24 684370
25 706720
26 725294
27 745627
28 761699
29 782228
30 804185
31 823231
32 842753
33 862213
34 881151
35 900118
36 918709
37 937090
38 955342
39 973350
40 991455
41 1009475
42 1026953
43 1044144
44 1061441
45 1077789
46 1093666
47 1109004
48 1124038
49 1138716
50 1153092
51 1167220
52 1181179
53 1195019
54 1208837
55 1222551
56 1236139
57 1249576
58 1262481
59 1276016
60 1289370
61 1302464
62 1315314
63 1328090
64 1340619
65 1353343
66 1365137
67 1376739
68 1388198
69 1399694
70 1411209
71 1422686
72 1434108
73 1445094
74 1456141
75 1467207
76 1478261
77 1489368
78 1500598
79 1511874
80 1523705
81 1535790
82 1548121
83 1560820
84 1573720
85 1586918
86 1600698
87 1614958
88 1629596
89 1644646
90 1659887
91 1675382
92 1691064
93 1706817
94 1722602
95 1738639
96 1754950
97 1771695
98 1788880
99 1806476
100 1824847];
time = data(:,1);
c_data= data(:,2);
beta0 = 0.5;
alpha0 = 0.004;
gamma0 = 0.1;
upsilon0 = 0.13;
epsilon0= 0.07;
lamda0= 0.1;
sigma0= 0.07;
kappa0= 0.03;
nu0 = 0.0001;
xi0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
p0 = [beta0; alpha0; gamma0; upsilon0; epsilon0; lamda0; sigma0; kappa0; nu0; xi0 ];
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
[p,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqnonlin(@(p) immanuel(p,time,c_data),p0,lb,ub,options );
disp(p)
Cdata_minus_Cv =immanuel(p,time,c_data);
Cv = c_data-Cdata_minus_Cv;
plot(time,[c_data,Cv])
function C=immanuel(p,time,c_data)
c0 = [1217378052,100,10,5,3,3,1,1];
[T,Cv]=ode45(@DifEq,time,c0);
function dC=DifEq(time,c)
N = 1390000000;
pi = 150;
zeta = 0.1;
eta = 0.2;
theta = 0.3;
iota = 0.3;
delta = 0.1;
rho = 0.5;
mu = 0.0000425;
beta = p(1);
alpha =p(2);
gamma = p(3);
upsilon =p(4);
epsilon = p(5);
lamda = p(6);
sigma = p(7);
kappa = p(8);
nu = p(9);
xi = p(10);
dcdt = zeros(8,1);
dcdt(1) = pi -beta*(zeta*c(3)+eta*c(4)+theta*c(5)+iota*c(6))*(c(1)/N) -mu*c(1);
dcdt(2) = beta*(zeta*c(3)+eta*c(4)+theta*c(5)+iota*c(6))*(c(1)/N) -(delta+mu)*c(2);
dcdt(3) = rho*delta*c(2)-(lamda+gamma+nu+mu)*c(3);
dcdt(4) = (1-rho)*delta*c(2)-(sigma+kappa+mu)*c(4);
dcdt(5) = lamda*c(3) + sigma*c(4)-(alpha+upsilon+mu)*c(5);
dcdt(6) = alpha*c(6) + kappa*c(4)- (epsilon+xi+mu)*c(6);
dcdt(7) = gamma*c(3) + upsilon*c(5) + epsilon*c(6);
dcdt(8) = nu*c(3) + xi*c(6);
dC = dcdt;
end
C=c_data-Cv(:,2);
end
15 commentaires
mallela ankamma rao
le 20 Avr 2022
Torsten
le 20 Avr 2022
How to draw contour plot two different set of values of beta={0.2,0.3} and gamma ={0.1,0.2}.
A contour plot of what ?
mallela ankamma rao
le 20 Avr 2022
mallela ankamma rao
le 21 Avr 2022
mallela ankamma rao
le 22 Avr 2022
Torsten
le 22 Avr 2022
R0 = xm.*0.00230.*(ym+4.7569)./(ym+4.442929)
instead of
R0 = xm.*(0.00230).*((ym+4.7569)/(ym+4.442929))
mallela ankamma rao
le 22 Avr 2022
mallela ankamma rao
le 22 Avr 2022
Torsten
le 22 Avr 2022
You must evaluate your function for Z at every element X(i,j),Y(i,j) such that X,Y and Z finally are of equal size.
mallela ankamma rao
le 23 Avr 2022
mallela ankamma rao
le 25 Avr 2022
mallela ankamma rao
le 29 Avr 2022
mallela ankamma rao
le 29 Avr 2022
Mr. Pavl M.
le 20 Nov 2024
Modifié(e) : Mr. Pavl M.
le 20 Nov 2024
Dear Friend,
How are you?
Are you still on this, what is the approximated volume of research works requests/clients/order?
There are already reliable, very valued original few real world mathematical and physical models and ethical framework lawful business proposal in our disposal. Let's make from it "limonade" furthermore.
Let's make order in it. Hire me continuously, stable 1 here or around for good order in it.
I havn't seen your works from before, so it is new to me and I just do it to correct, amend, order, fix:
Let's understand firstly what it factually is, the underlying mechanics, principles of correct operation and right directed evolution of the system and processes towards product only.
So far which biological or chemical process it is all about?
Where is original
E =;
Ia = ;
Is = ;
Q = ;
?
Who I am? Please get to know better, all datum about my honest work and utilization are provided via http links posted here and there.
We can work hybrid as well, outdoor and indoor (demonstrated already kept connected, kindly don't dissapoint, hire , wait, get).
I need investement to upgrade to enterprise service hardware and also to reward so valuable time, not into software and text complications. Kindly command/order them to invest to me, not others disturbing, wha you, invest you if you will be happy that I will continue to serve your objectives normally well.
Let's get on, Pitch Deck stakeholders, make necessary remittance transactions for good job we really did before and go ahead continue doing this.
clc
clear all
close all
data = [ 1 25
2 75
3 227
4 296
5 258
6 236
7 192
8 126
9 71
10 28
11 11
12 7];
time = data(1:12,1);
infected= data(1:12,2);
beta0 = 1;
lamdaa0= 0.019;
lamdas0= 0.0715;
etas0 = 0.03;
etaq0 = 0.04;
gammaa0 = 0.2;
gammaq0 = 0.13;
gammah0 = 0.07;
mua0 = 0.0001;
muh0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0];
ub = [1,1,1,1,1,1,1,1,1,1];
B0 = [beta0; lamdaa0; lamdas0; etas0; etaq0; gammaa0; gammaq0; gammah0; mua0; muh0 ];
options=optimset('MaxFunEvals', 1100, 'MaxIter', 1100, 'TolFun', 0.00001, 'TolX',0.00001,'Display','on');
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@diff1,B0,time,infected,lb,ub,options);
disp(B)
OUTPUT
C = RESIDUAL
plot(time,infected,time,C)
function C = diff1(B,time)
x0 = [1217378052,120,3,2,1,1,0];
[t,Cv] = ode45(@DifEq, time, x0);
function dC = DifEq(t, x)
N = 1390000000;
pi = 700 ;
zetaa = 0.1;
zetas = 0.2;
zetaq = 0.3;
zetah = 0.3;
omega = 0.2;
theta = 0.5;
mu = 0.0000425;
beta = B(1);
lamdaa= B(2);
lamdas = B(3);
etas = B(4);
etaq = B(5);
gammaa = B(6);
gammaq = B(7);
gammah = B(8);
mua = B(9);
muh = B(10);
%ToDo: update the parameters
E =0.521749;
Ia = 1;
Is = 1;
Q = 1;
xdot = zeros(7,1);
xdot(1) = pi -beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -mu*x(1);
xdot(2) = beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -(omega+mu)*x(2);
xdot(3) = theta*omega*x(2)-(lamdaa+gammaa+mua+mu)*x(3);
xdot(4) = (1-theta)*omega*E-(lamdas+etas+mu)*x(4);
xdot(5) = lamdaa*Ia+lamdas*Is-(etaq+gammaq+mu)*x(5);
xdot(6) = etas*Is+etaq*Q- (gammah+muh+mu)*x(6);
xdot(7) = gammaa*x(4) + gammaq*x(5) + gammah*x(6);
dC = xdot;
end
C = Cv(:,2);
end
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






