how to draw separate graphs

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:

9 个评论

What columns of the 8 created by the differential equations do you want to fit?
Also, this does not make sense:
C=c_data-Cv(:,2);
since ‘C’ should be the 3 columns of the solved differential equations that you want to fit to the data, nothing else, for example:
C = Cv(:,[2 4 8]);
or whatever of them you want to fit.
Thanks for your reply sir.
sir if it is not correct please tell how to correct this. i want only graphing part for fitted values
with this code i estimated the parameter values but how to draw graph for curve fitting
in given data 1st column is days
2nd column is confirmed
3rd column is recovered
4th column is deased
i want curve fit for these columns.i request you please modify my code and give correct code for curve fitting sir.
What do the 2nd, 3rd and 4th column of the matrix "data" represent ?
Should they be fitted against any of the columns of the vector Cv obtained from the ODE integration ?
As is - as Star Strider said - the statement
C=c_data-Cv(:,2);
doesn't make sense since c_data has 4 columns, Cv(:,2) is only one column.
Thanks for your reply sir
i understood your explanation about the graph. i am requesting you how to overcome that please give any suggestions or relating code. can i change with C = c_data - Cv?
i have to write like this for 3rd and 4th columns also. please anyone give some code for curve fitting
I know that English is not your native language, but just try to answer the two questions I asked:
What do the 2nd, 3rd and 4th column of the matrix "data" represent ?
Should they be fitted against any of the columns of the vector Cv obtained from the ODE integration ?
sir this project is mathematical modeling on covid 19.
here 1st column represents days,2nd columns represents confirmed cases,3rd columns represents recovered cases and 4th column represents death cases which are taken from WHO.
In python i knew how to draw how to take curve fitting prediction data against the observed data.
please see code below which belongs to python
fig.add_trace(go.Scatter(x=tspan, y=data[:, 0], mode='markers', name='Observed confirmed', line = dict(dash='dot')))
fig.add_trace(go.Scatter(x=tspan, y=data[:, 1], mode='markers', name='Observed recovered', line = dict(dash='dot')))
fig.add_trace(go.Scatter(x=tspan, y=data[:, 2], mode='markers', name='Observed death', line = dict(dash='dot')))
fig.add_trace(go.Scatter(x=tspan, y=final[:, 0], mode='lines+markers', name='Fitted confirmed'))
fig.add_trace(go.Scatter(x=tspan, y=final[:, 1], mode='lines+markers', name='Fitted recovered'))
fig.add_trace(go.Scatter(x=tspan, y=final[:, 2], mode='lines+markers', name='Fitted death'))
fig.update_layout(title='SEIaIsQHR: Observed vs Fitted',
xaxis_title='Day',
yaxis_title='Counts',
title_x=0.5,
width=1000, height=500)
I need code like this model sir. please help how to draw plot
Torsten
Torsten 2022-6-10
编辑:Torsten 2022-6-10
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 ?
Thanks for your reply sir.
C = [c_data(:,1)-Cv(:,2);c_data(:,2)-Cv(:,2);c_data(:,3)-Cv(:,2)]
i have tried this sir but i did not get answer.
ERROR:
Arrays have incompatible sizes for this operation.
C=c_data-Cv(:,[2,3,4]);
is it correct sir?. I got only curve fitting for 2nd and 3rd column but i did not get curve fit for 4th column.please tell me how to modify this sir.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2022-6-9

0 个投票

Have you looked at nexttile or subplot? These will set up separate axes so that you can draw each curve in its own separate axes.

1 个评论

thanks for your reply sir
i did not see subplot .first i have to fix C = c_data - Cv. but i dont know how to fix sir.

请先登录,再进行评论。

Image Analyst
Image Analyst 2022-6-10

0 个投票

In hindsight, we know that the curves look like a series of Gaussians:
I'm attaching a demo that will fit your data to a specified number of Gaussians.

2 个评论

I'm also attaching a demo that will fit a set of data to a single set of data increasing with exponential growth.
along with a fit I did years ago on COVID when it was just getting started.
Thanks alot for your reply sir.I will try sir

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by