-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal.m
219 lines (206 loc) · 4.98 KB
/
Final.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
clear
close all
load db_data.txt
Re_data = db_data(:,1);
Pr_data = db_data(:,2);
Nu_data = db_data(:,3);
theta_1 = 0.023 ;
theta_2 = 0.8;
theta_3 = 0.4;
p = 3; n = 56;
params = [theta_1 theta_2 theta_3];
Nu_data_vals = Dittus_Boelter([Re_data Pr_data],params);
Res = Nu_data_vals - Nu_data;
sigma2 = (Res'*Res)/(n-p);
sigma_hat = sqrt(sigma2);
figure(14)
hold on
plot(Nu_data_vals, Res, 'kx', 'linewidth',5)
plot(Nu_data_vals, 0*ones(n,1),'-b',Nu_data_vals, 2*sigma_hat*ones(n,1),'-r',Nu_data_vals, -2*sigma_hat*ones(n,1),'-r', 'linewidth',3 )
hold off
set(gca,'Fontsize',20);
xlabel('Nu values')
ylabel('Residuals')
legend('Residue','','2\sigma interval','Location','Northeast')
%%
data.Re_data = Re_data;
data.Pr_data = Pr_data;
data.Nu_data = Nu_data;
options.Algorithm = 'levenberg-marquardt';
q = params;
q=lsqnonlin(@(q) odeparameterestimation(data,q),params,[],[], options);
params=q;
X = [(Re_data.^params(2)).*(Pr_data.^params(3)) params(1)*(Re_data.^params(2)).*(Pr_data.^params(3)).*log(Re_data) params(1).*(Re_data.^params(2)).*(Pr_data.^params(3)).*log(Pr_data)];
Fisher = X'*X;
eta = 1e-8;
[Id, UnId] = PSS_SVD(X,eta);
[Ida, UnIda] = PSS_SVD2update(X,eta);
Nu_data_vals = Dittus_Boelter([Re_data Pr_data],params);
Res = Nu_data_vals - Nu_data;
sigma2 = (Res'*Res)/(n-p);
sigma_hat = sqrt(sigma2);
V = sigma2*eye(p)/(X' * X);
%
figure(13)
hold on
plot(Nu_data_vals, Res, 'kx', 'linewidth',5)
plot(Nu_data_vals, 0*ones(n,1),'-b',Nu_data_vals, 2*sigma_hat*ones(n,1),'-r',Nu_data_vals, -2*sigma_hat*ones(n,1),'-r', 'linewidth',3 )
hold off
set(gca,'Fontsize',20);
xlabel('Nu values')
ylabel('Residuals')
legend('Residue','','2\sigma interval','Location','Northeast')
%
% %%
%
clear data model options
%
data.Re_data = Re_data;
data.Pr_data = Pr_data;
data.Nu_data = Nu_data;
tcov = V;
N = 50000;
theta_init = [0.0043036,0.98191,0.40866 ];
%
params = {
{'theta_1',theta_init(1)}
{'theta_2',theta_init(2)}
{'theta_3',theta_init(3)}};
model.ssfun = @SS_fun;
model.sigma2 = sigma2;
model.N = n;
options.qcov = tcov;
options.nsimu = N;
options.updatesigma = 1;
options.burnin_scale = 10000;
[results,chain,s2chain] = mcmcrun(model,data,params,options);
theta_1_vals = chain(10001:end,1);
theta_2_vals = chain(10001:end,2);
theta_3_vals = chain(10001:end,3);
%
%
[~,density_theta_1,theta_1_mesh,~]=kde(theta_1_vals);
[~,density_theta_2,theta_2_mesh,~]=kde(theta_2_vals);
[~,density_theta_3,theta_3_mesh,~]=kde(theta_3_vals);
%
%
figure(1); clf
mcmcplot(chain,[],results,'chainpanel');
figure(2); clf
mcmcplot(chain,[],results,'pairs');
cov(chain)
chainstats(chain,results)
figure(3); clf
plot(theta_1_vals,'-','linewidth',2)
set(gca,'Fontsize',22);
axis([0 N 0.009 0.011])
box on
xlabel('Chain Iteration')
ylabel('Parameter \theta_1')
%
figure(4); clf
plot(theta_2_vals,'-','linewidth',2)
set(gca,'Fontsize',22);
axis([0 N 0.009 0.011])
box on
xlabel('Chain Iteration')
ylabel('Parameter \theta_2')
%
figure(5); clf
plot(theta_3_vals,'-','linewidth',2)
set(gca,'Fontsize',22);
axis([0 N 0.009 0.011])
box on
xlabel('Chain Iteration')
ylabel('Parameter \theta_3')
%
%
figure(6); clf
hold on
plot(theta_1_mesh,density_theta_1,'k-','linewidth',3)
set(gca,'Fontsize',22);
axis([0.009 0.011 0 3000])
box on
xlabel('Parameter \theta_1')
ylabel("PDF")
hold off
%
figure(7); clf
hold on
plot(theta_2_mesh,density_theta_2,'k-','linewidth',3)
set(gca,'Fontsize',22);
axis([0.009 0.011 0 3000])
box on
xlabel('Parameter \theta_2')
ylabel("PDF")
hold off
%
figure(8); clf
hold on
plot(theta_3_mesh,density_theta_3,'k-','linewidth',3)
set(gca,'Fontsize',22);
axis([0.009 0.011 0 3000])
box on
xlabel('Parameter \theta_3')
ylabel("PDF")
hold off
%
figure(9); clf
scatter(theta_1_vals,theta_2_vals)
box on
set(gca,'Fontsize',23);
xlabel('Parameter \theta_1')
ylabel('Parameter \theta_2')
axis([0.009 0.011 0.16 0.24])
%
%
figure(10); clf
scatter(theta_1_vals,theta_3_vals)
box on
set(gca,'Fontsize',23);
xlabel('Parameter \theta_1')
ylabel('Parameter \theta_3')
axis([0.009 0.011 0.16 0.24])
%
%
figure(11); clf
scatter(theta_2_vals,theta_3_vals)
box on
set(gca,'Fontsize',23);
xlabel('Parameter \theta_2')
ylabel('Parameter \theta_3')
axis([0.009 0.011 0.16 0.24])
%
figure(12)
plot(s2chain(10001:end))
hold on
set(gca,'Fontsize',22);
axis([0 N 200 1000])
xlabel('Chain Iteration')
ylabel(' \sigma^2')
mean(s2chain(10001:end))
function SS= SS_fun(params, data)
theta_1 = params(1); theta_2 = params(2); theta_3 = params(3);
Re_data = data.Re_data;
Pr_data = data.Pr_data;
Nu_data = data.Nu_data;
Nu = theta_1.*(Re_data.^theta_2).*(Pr_data.^theta_3);
Error = Nu_data - Nu;
SS = Error'*Error;
end
function Error = odeparameterestimation(data,params)
theta_1 = params(1); theta_2 = params(2); theta_3 = params(3);
Re_data = data.Re_data;
Pr_data = data.Pr_data;
Nu_data = data.Nu_data;
Nu = theta_1.*(Re_data.^theta_2).*(Pr_data.^theta_3);
Error = Nu - Nu_data;
end
function Nu = Dittus_Boelter(y,params)
theta_1 = params(1);
theta_2 = params(2);
theta_3 = params(3);
Re = y(:,1);
Pr = y(:,2);
Nu = theta_1.*(Re.^theta_2).*(Pr.^theta_3);
end