estimation of parameters by using lsqnonlin for system of differential equations
15 views (last 30 days)
Show older comments
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
Answers (4)
Torsten
on 2 Apr 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 Comments
Torsten
on 2 Apr 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 );
Star Strider
on 2 Apr 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 Comments
Torsten
on 7 Apr 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)
Torsten
on 13 Apr 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 Comments
Pavl M.
on 20 Nov 2024 at 18:42
Edited: Pavl M.
on 20 Nov 2024 at 19:50
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
See Also
Categories
Find more on Nonlinear ARX Models in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!