how to draw separate graphs
3 views (last 30 days)
Show older comments
Good afternoon sir,
Sir I have taken lsqnonlin method to estimate parameters and draw the graphs for prediction.Here i have to draw graphs for 2,3,4 columns but it shows only one column for predictions.sir i request please tell me how to draw graphs for 3rd and 4th columns and also please tell me how to separate graphs.please give me 3 to 5 lines code if possible.
Thanking you sir
the code and graph are
code:
data = [ 1 1 0 0
2 1 0 0
3 1 0 0
4 2 0 0
5 3 0 0
6 3 0 0
7 3 0 0
8 3 0 0
9 3 0 0
10 3 0 0
11 3 0 0
12 3 0 0
13 3 0 0
14 3 0 0
15 3 1 0
16 3 1 0
17 3 1 0
18 3 2 0
19 3 2 0
20 3 2 0
21 3 2 0
22 3 3 0
23 3 3 0
24 3 3 0
25 3 3 0
26 3 3 0
27 3 3 0
28 3 3 0
29 3 3 0
30 3 3 0
31 3 3 0
32 3 3 0
33 5 3 0
34 6 3 0
35 28 3 0
36 30 3 0
37 31 3 0
38 34 3 0
39 39 3 0
40 48 3 0
41 63 4 0
42 71 4 0
43 81 4 1
44 91 10 1
45 102 10 2
46 112 13 2
47 126 14 2
48 146 15 3
49 171 15 3
50 198 20 4
51 256 23 4
52 334 23 4
53 403 23 7
54 497 25 9
55 571 40 10
56 657 43 11
57 730 50 16
58 883 75 19
59 1019 85 24
60 1139 102 27
61 1326 137 41
62 1635 150 47
63 2059 169 53
64 2545 191 69
65 3105 230 83
66 3684 286 96
67 4293 329 118
68 4777 394 134
69 5350 469 161
70 5915 565 181
71 6728 635 227
72 7599 786 249
73 8453 972 290
74 9211 1086 332
75 10454 1198 359
76 11485 1365 396
77 12371 1509 423
78 13432 1767 449
79 14354 2040 487
80 15725 2466 522
81 17305 2854 560
82 18544 3273 593
83 20081 3976 646
84 21373 4370 682
85 23040 5012 722
86 24448 5496 781
87 26283 5938 825
88 27890 6523 881
89 29458 7103 939
90 31360 7739 1008
91 33065 8429 1079
92 34866 9059 1154
93 37262 10021 1231
94 39826 10852 1323
95 42778 11763 1463
96 46434 12845 1566
97 49405 14140 1694
98 53007 15301 1785
99 56351 16776 1889
100 59690 17887 1986]
time = data(:,1);
c_data = data(:,[2,3,4]);
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
Graph:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1026025/image.jpeg)
9 Comments
Torsten
on 10 Jun 2022
Edited: Torsten
on 10 Jun 2022
Before you plot results, we should first make sure that your code is correct - that's why I insist.
At the moment, you subtract the vector Cv(:,2) from each column of the matrix c_data. Thus, lsqnonlin assumes that columns 2, 3 and 4 of your matrix "data" are repetitions of an experiment and that all three columns should be approximated by Cv(:,2) using one set of parameters. But I think this must be wrong since the values for the three columns differ significantly in size.
So again my question: Is it correct that you want lsqnonlin minimize [c_data(:,1)-Cv(:,2);c_data(:,2)-Cv(:,2);c_data(:,3)-Cv(:,2)] simultaneously ?
Answers (2)
Image Analyst
on 10 Jun 2022
In hindsight, we know that the curves look like a series of Gaussians:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1027730/image.png)
I'm attaching a demo that will fit your data to a specified number of Gaussians.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1027735/image.png)
2 Comments
Image Analyst
on 10 Jun 2022
I'm also attaching a demo that will fit a set of data to a single set of data increasing with exponential growth.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1027830/image.png)
along with a fit I did years ago on COVID when it was just getting started.
See Also
Categories
Find more on Biological and Health Sciences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!