Matematisk Model for Mavesækkens Tømning - Danmarks Tekniske ...

Matematisk Model for Mavesækkens Tømning - Danmarks Tekniske ... Matematisk Model for Mavesækkens Tømning - Danmarks Tekniske ...

26.07.2013 Views

96 MATLAB kode til behandling af forsøgsdata 134 plot(Time,Cdata,'.b','MarkerSize',15) 135 hold on 136 plot(Time,predCC,'r','linewidth',2) 137 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14); 138 legend('Data','dQ/dt = aQˆ2 + c') 139 axis([0 Time(end) 0 1]) 140 set(get(h,'CurrentAxes'),'fontsize',14) 141 print('−depsc', '−tiff', ['modelC']) 142 print('−dpng', '−loose', ['modelC']) 143 144 % Calculating Sum of Square Errors and AIC 145 diffC = Cdata − predCC'; 146 SSEC = diffC'*diffC; 147 KC = length(DC); 148 AICC = n*log(SSEC/n)+2*KC; 149 150 % Model D 151 % Defining matrix X and finding parameters. 152 XD = [Cdata(1:end−1) ones(16,1)]; 153 DD = pinv(XD)*Y; 154 155 % Calculating the model of Y. 156 predYD = XD*DD; 157 % Plot of the model of Y with datapoints. 158 h = figure; 159 subplot(1,2,1) 160 plot(Time(2:end),Y,'b','linewidth',2) 161 hold on 162 plot(Time(2:end),predYD,'r','linewidth',2) 163 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 164 axis tight 165 166 % Calculating the model of data. 167 predCD(1) = 1; 168 for k = 2:17 169 predCD(k) = predYD(k−1)*15+predCD(k−1); 170 end 171 % Plot the model of data with datapoints. 172 subplot(1,2,2) 173 plot(Time,Cdata,'.b','MarkerSize',15) 174 hold on 175 plot(Time,predCD,'r','linewidth',2) 176 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14); 177 legend('Data','dQ/dt = bQ + c') 178 axis([0 Time(end) 0 1]) 179 set(get(h,'CurrentAxes'),'fontsize',14) 180 print('−depsc', '−tiff', ['modelD']) 181 print('−dpng', '−loose', ['modelD']) 182 183 % Calculating Sum of Square Errors and AIC 184 diffD = Cdata − predCD'; 185 SSED = diffD'*diffD; 186 KD = length(DD); 187 AICD = n*log(SSED/n)+2*KD; 188

189 %%%%%%%%%%%%%%%%%%%%%%%%% 1 parameter %%%%%%%%%%%%%%%%%%%%%%%%% 190 % Model E 191 % Defining matrix X and finding parameters. 192 XE = [Cdata(1:end−1).*Cdata(1:end−1)]; 193 DE = pinv(XE)*Y; 194 195 % Calculating the model of Y. 196 predYE = XE*DE; 197 % Plot of the model of Y with datapoints. 198 h = figure; 199 subplot(1,2,1) 200 plot(Time(2:end),Y,'b','linewidth',2) 201 hold on 202 plot(Time(2:end),predYE,'r','linewidth',2) 203 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 204 axis tight 205 206 % Calculating the model of data. 207 predCE(1) = 1; 208 for k = 2:17 209 predCE(k) = predYE(k−1)*15+predCE(k−1); 210 end 211 % Plot the model of data with datapoints. 212 subplot(1,2,2) 213 plot(Time,Cdata,'.b','MarkerSize',15) 214 hold on 215 plot(Time,predCE,'r','linewidth',2) 216 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14); 217 legend('Data','dQ/dt = aQˆ2') 218 axis([0 Time(end) 0 1]) 219 set(get(h,'CurrentAxes'),'fontsize',14) 220 print('−depsc', '−tiff', ['modelE']) 221 print('−dpng', '−loose', ['modelE']) 222 223 % Calculating Sum of Square Errors and AIC 224 diffE = Cdata − predCE'; 225 SSEE = diffE'*diffE; 226 KE = length(DE); 227 AICE = n*log(SSEE/n)+2*KE; 228 229 % Model F 230 % Defining matrix X and finding parameters. 231 XF = [Cdata(1:end−1)]; 232 DF = pinv(XF)*Y; 233 234 % Calculating the model of Y. 235 predYF = XF*DF; 236 % Plot of the model of Y with datapoints. 237 h = figure; 238 subplot(1,2,1) 239 plot(Time(2:end),Y,'b','linewidth',2) 240 hold on 241 plot(Time(2:end),predYF,'r','linewidth',2) 242 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 243 axis tight 97

189 %%%%%%%%%%%%%%%%%%%%%%%%% 1 parameter %%%%%%%%%%%%%%%%%%%%%%%%%<br />

190 % <strong>Model</strong> E<br />

191 % Defining matrix X and finding parameters.<br />

192 XE = [Cdata(1:end−1).*Cdata(1:end−1)];<br />

193 DE = pinv(XE)*Y;<br />

194<br />

195 % Calculating the model of Y.<br />

196 predYE = XE*DE;<br />

197 % Plot of the model of Y with datapoints.<br />

198 h = figure;<br />

199 subplot(1,2,1)<br />

200 plot(Time(2:end),Y,'b','linewidth',2)<br />

201 hold on<br />

202 plot(Time(2:end),predYE,'r','linewidth',2)<br />

203 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14);<br />

204 axis tight<br />

205<br />

206 % Calculating the model of data.<br />

207 predCE(1) = 1;<br />

208 <strong>for</strong> k = 2:17<br />

209 predCE(k) = predYE(k−1)*15+predCE(k−1);<br />

210 end<br />

211 % Plot the model of data with datapoints.<br />

212 subplot(1,2,2)<br />

213 plot(Time,Cdata,'.b','MarkerSize',15)<br />

214 hold on<br />

215 plot(Time,predCE,'r','linewidth',2)<br />

216 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14);<br />

217 legend('Data','dQ/dt = aQˆ2')<br />

218 axis([0 Time(end) 0 1])<br />

219 set(get(h,'CurrentAxes'),'fontsize',14)<br />

220 print('−depsc', '−tiff', ['modelE'])<br />

221 print('−dpng', '−loose', ['modelE'])<br />

222<br />

223 % Calculating Sum of Square Errors and AIC<br />

224 diffE = Cdata − predCE';<br />

225 SSEE = diffE'*diffE;<br />

226 KE = length(DE);<br />

227 AICE = n*log(SSEE/n)+2*KE;<br />

228<br />

229 % <strong>Model</strong> F<br />

230 % Defining matrix X and finding parameters.<br />

231 XF = [Cdata(1:end−1)];<br />

232 DF = pinv(XF)*Y;<br />

233<br />

234 % Calculating the model of Y.<br />

235 predYF = XF*DF;<br />

236 % Plot of the model of Y with datapoints.<br />

237 h = figure;<br />

238 subplot(1,2,1)<br />

239 plot(Time(2:end),Y,'b','linewidth',2)<br />

240 hold on<br />

241 plot(Time(2:end),predYF,'r','linewidth',2)<br />

242 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14);<br />

243 axis tight<br />

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!