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

94 MATLAB kode til behandling af forsøgsdata 24 set(get(h,'CurrentAxes'),'fontsize',14) 25 axis([0 Time(end) 0 1]) 26 print('−depsc', '−tiff', ['data emil']) 27 print('−dpng', '−loose', ['data emil']) 28 29 n = 17; % Number of datapoints. 30 31 %%%%%%%%%%%%%%%%%%%%%%%%% 3 parameters %%%%%%%%%%%%%%%%%%%%%%%%% 32 % Model A 33 % Defining matrix X and finding parameters. 34 XA = [Cdata(1:end−1).*Cdata(1:end−1) Cdata(1:end−1) ones(16,1)]; 35 DA = pinv(XA)*Y; 36 37 % Calculating the model of Y. 38 predYA = XA*DA; 39 % Plot of the model of Y with datapoints. 40 h = figure; 41 subplot(1,2,1) 42 plot(Time(2:end),Y,'b','linewidth',2) 43 hold on 44 plot(Time(2:end),predYA,'r','linewidth',2) 45 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 46 axis tight 47 48 % Calculating the model of data. 49 predCA(1) = 1; 50 for k = 2:17 51 predCA(k) = predYA(k−1)*15+predCA(k−1); 52 end 53 % Plot the model of data with datapoints. 54 subplot(1,2,2) 55 plot(Time,Cdata,'.b','MarkerSize',15) 56 hold on 57 plot(Time,predCA,'r','linewidth',2) 58 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14); 59 legend('Data','dQ/dt = aQˆ2 + bQ + c') 60 axis([0 Time(end) 0 1]) 61 set(get(h,'CurrentAxes'),'fontsize',14) 62 print('−depsc', '−tiff', ['modelA']) 63 print('−dpng', '−loose', ['modelA']) 64 65 % Calculating Sum of Square Errors and AIC 66 diffA = Cdata − predCA'; 67 SSEA = diffA'*diffA; 68 KA = length(DA); 69 AICA = n*log(SSEA/n)+2*KA; 70 71 %%%%%%%%%%%%%%%%%%%%%%%%% 2 parameters %%%%%%%%%%%%%%%%%%%%%%%%% 72 % Model B 73 % Defining matrix X and finding parameters. 74 XB = [Cdata(1:end−1).*Cdata(1:end−1) Cdata(1:end−1)]; 75 DB = pinv(XB)*Y; 76 77 % Calculating the model of Y. 78 predYB = XB*DB;

79 % Plot of the model of Y with datapoints. 80 h = figure; 81 subplot(1,2,1) 82 plot(Time(2:end),Y,'b','linewidth',2) 83 hold on 84 plot(Time(2:end),predYB,'r','linewidth',2) 85 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 86 axis tight 87 88 % Calculating the model of data. 89 predCB(1) = 1; 90 for k = 2:17 91 predCB(k) = predYB(k−1)*15+predCB(k−1); 92 end 93 % Plot the model of data with datapoints. 94 subplot(1,2,2) 95 plot(Time,Cdata,'.b','MarkerSize',15) 96 hold on 97 plot(Time,predCB,'r','linewidth',2) 98 xlabel('Time [min]','fontsize',14); ylabel('Q','fontsize',14); 99 legend('Data','dQ/dt = aQˆ2 + bQ') 100 axis([0 Time(end) 0 1]) 101 set(get(h,'CurrentAxes'),'fontsize',14) 102 print('−depsc', '−tiff', ['modelB']) 103 print('−dpng', '−loose', ['modelB']) 104 105 % Calculating Sum of Square Errors and AIC 106 diffB = Cdata − predCB'; 107 SSEB = diffB'*diffB; 108 KB = length(DB); 109 AICB = n*log(SSEB/n)+2*KB; 110 111 % Model C 112 % Defining matrix X and finding parameters. 113 XC = [Cdata(1:end−1).*Cdata(1:end−1) ones(16,1)]; 114 DC = pinv(XC)*Y; 115 116 % Calculating the model of Y. 117 predYC = XC*DC; 118 % Plot of the model of Y with datapoints. 119 h = figure; 120 subplot(1,2,1) 121 plot(Time(2:end),Y,'b','linewidth',2) 122 hold on 123 plot(Time(2:end),predYC,'r','linewidth',2) 124 xlabel('Time [min]','fontsize',14); ylabel('dQ/dt','fontsize',14); 125 axis tight 126 127 % Calculating the model of data. 128 predCC(1) = 1; 129 for k = 2:17 130 predCC(k) = predYC(k−1)*15+predCC(k−1); 131 end 132 % Plot the model of data with datapoints. 133 subplot(1,2,2) 95

94 MATLAB kode til behandling af <strong>for</strong>søgsdata<br />

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

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

26 print('−depsc', '−tiff', ['data emil'])<br />

27 print('−dpng', '−loose', ['data emil'])<br />

28<br />

29 n = 17; % Number of datapoints.<br />

30<br />

31 %%%%%%%%%%%%%%%%%%%%%%%%% 3 parameters %%%%%%%%%%%%%%%%%%%%%%%%%<br />

32 % <strong>Model</strong> A<br />

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

34 XA = [Cdata(1:end−1).*Cdata(1:end−1) Cdata(1:end−1) ones(16,1)];<br />

35 DA = pinv(XA)*Y;<br />

36<br />

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

38 predYA = XA*DA;<br />

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

40 h = figure;<br />

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

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

43 hold on<br />

44 plot(Time(2:end),predYA,'r','linewidth',2)<br />

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

46 axis tight<br />

47<br />

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

49 predCA(1) = 1;<br />

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

51 predCA(k) = predYA(k−1)*15+predCA(k−1);<br />

52 end<br />

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

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

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

56 hold on<br />

57 plot(Time,predCA,'r','linewidth',2)<br />

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

59 legend('Data','dQ/dt = aQˆ2 + bQ + c')<br />

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

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

62 print('−depsc', '−tiff', ['modelA'])<br />

63 print('−dpng', '−loose', ['modelA'])<br />

64<br />

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

66 diffA = Cdata − predCA';<br />

67 SSEA = diffA'*diffA;<br />

68 KA = length(DA);<br />

69 AICA = n*log(SSEA/n)+2*KA;<br />

70<br />

71 %%%%%%%%%%%%%%%%%%%%%%%%% 2 parameters %%%%%%%%%%%%%%%%%%%%%%%%%<br />

72 % <strong>Model</strong> B<br />

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

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

75 DB = pinv(XB)*Y;<br />

76<br />

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

78 predYB = XB*DB;

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

Saved successfully!

Ooh no, something went wrong!