load lecture4.mat plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempLinearNPlot,'b',timePlot,TempSplineNPlot,'r') polyfit(timeMeasuredN,TempMeasuredN,1) ans = -6.3385 12.4480 coefLinFit=polyfit(timeMeasuredN,TempMeasuredN,1) coefLinFit = -6.3385 12.4480 TempLinFitPlot=polyval(coefLinFit,timePlot) TempLinFitPlot = Columns 1 through 5 12.4480 12.4057 12.3635 12.3212 12.2790 Columns 6 through 10 12.2367 12.1945 12.1522 12.1100 12.0677 Columns 11 through 15 12.0254 11.9832 11.9409 11.8987 11.8564 Columns 16 through 20 11.8142 11.7719 11.7296 11.6874 11.6451 Columns 21 through 25 11.6029 11.5606 11.5184 11.4761 11.4338 Columns 26 through 30 11.3916 11.3493 11.3071 11.2648 11.2226 Columns 31 through 35 11.1803 11.1381 11.0958 11.0535 11.0113 Columns 36 through 40 10.9690 10.9268 10.8845 10.8423 10.8000 Columns 41 through 45 10.7577 10.7155 10.6732 10.6310 10.5887 Columns 46 through 50 10.5465 10.5042 10.4620 10.4197 10.3774 Columns 51 through 55 10.3352 10.2929 10.2507 10.2084 10.1662 Columns 56 through 60 10.1239 10.0816 10.0394 9.9971 9.9549 Columns 61 through 65 9.9126 9.8704 9.8281 9.7858 9.7436 Columns 66 through 70 9.7013 9.6591 9.6168 9.5746 9.5323 Columns 71 through 75 9.4901 9.4478 9.4055 9.3633 9.3210 Columns 76 through 80 9.2788 9.2365 9.1943 9.1520 9.1097 Columns 81 through 85 9.0675 9.0252 8.9830 8.9407 8.8985 Columns 86 through 90 8.8562 8.8140 8.7717 8.7294 8.6872 Columns 91 through 95 8.6449 8.6027 8.5604 8.5182 8.4759 Columns 96 through 100 8.4336 8.3914 8.3491 8.3069 8.2646 Columns 101 through 105 8.2224 8.1801 8.1378 8.0956 8.0533 Columns 106 through 110 8.0111 7.9688 7.9266 7.8843 7.8421 Columns 111 through 115 7.7998 7.7575 7.7153 7.6730 7.6308 Columns 116 through 120 7.5885 7.5463 7.5040 7.4617 7.4195 Columns 121 through 125 7.3772 7.3350 7.2927 7.2505 7.2082 Columns 126 through 130 7.1660 7.1237 7.0814 7.0392 6.9969 Columns 131 through 135 6.9547 6.9124 6.8702 6.8279 6.7856 Columns 136 through 140 6.7434 6.7011 6.6589 6.6166 6.5744 Columns 141 through 145 6.5321 6.4898 6.4476 6.4053 6.3631 Columns 146 through 150 6.3208 6.2786 6.2363 6.1941 6.1518 Columns 151 through 155 6.1095 6.0673 6.0250 5.9828 5.9405 Columns 156 through 160 5.8983 5.8560 5.8137 5.7715 5.7292 Columns 161 through 165 5.6870 5.6447 5.6025 5.5602 5.5180 Columns 166 through 170 5.4757 5.4334 5.3912 5.3489 5.3067 Columns 171 through 175 5.2644 5.2222 5.1799 5.1376 5.0954 Columns 176 through 180 5.0531 5.0109 4.9686 4.9264 4.8841 Columns 181 through 185 4.8418 4.7996 4.7573 4.7151 4.6728 Columns 186 through 190 4.6306 4.5883 4.5461 4.5038 4.4615 Columns 191 through 195 4.4193 4.3770 4.3348 4.2925 4.2503 Columns 196 through 200 4.2080 4.1657 4.1235 4.0812 4.0390 Columns 201 through 205 3.9967 3.9545 3.9122 3.8700 3.8277 Columns 206 through 210 3.7854 3.7432 3.7009 3.6587 3.6164 Columns 211 through 215 3.5742 3.5319 3.4896 3.4474 3.4051 Columns 216 through 220 3.3629 3.3206 3.2784 3.2361 3.1939 Columns 221 through 225 3.1516 3.1093 3.0671 3.0248 2.9826 Columns 226 through 230 2.9403 2.8981 2.8558 2.8135 2.7713 Columns 231 through 235 2.7290 2.6868 2.6445 2.6023 2.5600 Columns 236 through 240 2.5177 2.4755 2.4332 2.3910 2.3487 Columns 241 through 245 2.3065 2.2642 2.2220 2.1797 2.1374 Columns 246 through 250 2.0952 2.0529 2.0107 1.9684 1.9262 Columns 251 through 255 1.8839 1.8416 1.7994 1.7571 1.7149 Columns 256 through 260 1.6726 1.6304 1.5881 1.5459 1.5036 Columns 261 through 265 1.4613 1.4191 1.3768 1.3346 1.2923 Columns 266 through 270 1.2501 1.2078 1.1655 1.1233 1.0810 Columns 271 through 275 1.0388 0.9965 0.9543 0.9120 0.8697 Columns 276 through 280 0.8275 0.7852 0.7430 0.7007 0.6585 Columns 281 through 285 0.6162 0.5740 0.5317 0.4894 0.4472 Columns 286 through 290 0.4049 0.3627 0.3204 0.2782 0.2359 Columns 291 through 295 0.1936 0.1514 0.1091 0.0669 0.0246 Columns 296 through 300 -0.0176 -0.0599 -0.1021 -0.1444 -0.1867 Column 301 -0.2289 TempLinFitPlot=polyval(coefLinFit,timePlot); plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempLinFitPlot,'y') coefQuadFit=polyfit(timeMeasuredN,TempMeasuredN,2) coefQuadFit = 2.7259 -11.7902 14.2187 TempQuadFitPlot=polyval(coefQuadFit,timePlot); plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempQuadFitPlot,'c') coefQuartFit=polyfit(timeMeasuredN,TempMeasuredN,4) coefQuartFit = 1.1746 -5.3555 10.6889 -15.9337 14.6908 TempQuartFitPlot=polyval(coefQuartFit,timePlot); plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempQuartFitPlot,'c') coefCubeFit=polyfit(timeMeasuredN,TempMeasuredN,3) coefCubeFit = -0.6573 4.6977 -13.3478 14.4617 TempCubeFitPlot=polyval(coefCubeFit,timePlot); plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempCubFitPlot,'m') {Undefined function or variable 'TempCubFitPlot'.} plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempCubeFitPlot,'m') errQuartFitMax=max(abs(TempQuartFitPlot-TempExactFunPlot)) {Undefined function or variable 'TempExactFunPlot'.} errQuartFitMax=max(abs(TempQuartFitPlot-TempExactPlot)) errQuartFitMax = 0.4684 errLinearNMax errLinearNMax = 1.7657 errSplineNMax errSplineNMax = 2.0296 qExact=TempExactFun(2)/(-1.1)-TempExactFun(0)/(-1.1) qExact = 11.8021 integral(TempExactFun,0,2) ans = 11.8021 format long integral(TempExactFun,0,2) ans = 11.802067170827206 qExact qExact = 11.802067170827204 integral(@(t) interp1(timeMeasured,TempMeasured,t),0,2) ans = 12.095000369254418 integral(@(t) spline(timeMeasured,TempMeasured,t),0,2) ans = 11.803333333333333 integral(@(t) polyval(coefLinFit,t),0,2) ans = 12.219084009333578 integral(@(t) polyval(coefQuadFit,t),0,2) ans = 12.125891672886226 integral(@(t) polyval(coefQuartFit,t),0,2) ans = 12.113011014231544 integral(@(t) spline(timeMeasuredN,TempMeasuredN,t),0,2) ans = 12.171005745875888 plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempLinearNPlot,'b',timePlot,TempSplineNPlot,'r') plot(timeMeasuredN,TempMeasuredN,'ok',timePlot,TempExactPlot,'--k',timePlot,TempLinearPlot,'b',timePlot,TempSplinePlot,'r') plot(timeMeasured,TempMeasured,'ok',timePlot,TempExactPlot,'--k',timePlot,TempLinearPlot,'b',timePlot,TempSplinePlot,'r') derCoefLinFit=polyder(CoefLinFit) {Undefined function or variable 'CoefLinFit'.} derCoefLinFit=polyder(coefLinFit) derCoefLinFit = -6.338460399026184 coefLinFit coefLinFit = -6.338460399026184 12.448002403692973 coefQuadFit coefQuadFit = Columns 1 through 2 2.725875841084907 -11.790212081196001 Column 3 14.218656796192571 derCoefQuadFit=polyder(coefQuadFit) derCoefQuadFit = 5.451751682169815 -11.790212081196001 coefQuartFit coefQuartFit = Columns 1 through 2 1.174559586955105 -5.355528078839982 Columns 3 through 4 10.688914570008901 -15.933691226836668 Column 5 14.690776120030867 derCoefQuartFit=polyder(coefQuartFit) derCoefQuartFit = Columns 1 through 2 4.698238347820421 -16.066584236519947 Columns 3 through 4 21.377829140017802 -15.933691226836668 derExactPlot=-1.1*TempExactPlot; derLinFitPlot=polyval(derCoefLinFit,timePlot) derLinFitPlot = Columns 1 through 2 -6.338460399026184 -6.338460399026184 Columns 3 through 4 -6.338460399026184 -6.338460399026184 Columns 5 through 6 -6.338460399026184 -6.338460399026184 Columns 7 through 8 -6.338460399026184 -6.338460399026184 Columns 9 through 10 -6.338460399026184 -6.338460399026184 Columns 11 through 12 -6.338460399026184 -6.338460399026184 Columns 13 through 14 -6.338460399026184 -6.338460399026184 Columns 15 through 16 -6.338460399026184 -6.338460399026184 Columns 17 through 18 -6.338460399026184 -6.338460399026184 Columns 19 through 20 -6.338460399026184 -6.338460399026184 Columns 21 through 22 -6.338460399026184 -6.338460399026184 Columns 23 through 24 -6.338460399026184 -6.338460399026184 Columns 25 through 26 -6.338460399026184 -6.338460399026184 Columns 27 through 28 -6.338460399026184 -6.338460399026184 Columns 29 through 30 -6.338460399026184 -6.338460399026184 Columns 31 through 32 -6.338460399026184 -6.338460399026184 Columns 33 through 34 -6.338460399026184 -6.338460399026184 Columns 35 through 36 -6.338460399026184 -6.338460399026184 Columns 37 through 38 -6.338460399026184 -6.338460399026184 Columns 39 through 40 -6.338460399026184 -6.338460399026184 Columns 41 through 42 -6.338460399026184 -6.338460399026184 Columns 43 through 44 -6.338460399026184 -6.338460399026184 Columns 45 through 46 -6.338460399026184 -6.338460399026184 Columns 47 through 48 -6.338460399026184 -6.338460399026184 Columns 49 through 50 -6.338460399026184 -6.338460399026184 Columns 51 through 52 -6.338460399026184 -6.338460399026184 Columns 53 through 54 -6.338460399026184 -6.338460399026184 Columns 55 through 56 -6.338460399026184 -6.338460399026184 Columns 57 through 58 -6.338460399026184 -6.338460399026184 Columns 59 through 60 -6.338460399026184 -6.338460399026184 Columns 61 through 62 -6.338460399026184 -6.338460399026184 Columns 63 through 64 -6.338460399026184 -6.338460399026184 Columns 65 through 66 -6.338460399026184 -6.338460399026184 Columns 67 through 68 -6.338460399026184 -6.338460399026184 Columns 69 through 70 -6.338460399026184 -6.338460399026184 Columns 71 through 72 -6.338460399026184 -6.338460399026184 Columns 73 through 74 -6.338460399026184 -6.338460399026184 Columns 75 through 76 -6.338460399026184 -6.338460399026184 Columns 77 through 78 -6.338460399026184 -6.338460399026184 Columns 79 through 80 -6.338460399026184 -6.338460399026184 Columns 81 through 82 -6.338460399026184 -6.338460399026184 Columns 83 through 84 -6.338460399026184 -6.338460399026184 Columns 85 through 86 -6.338460399026184 -6.338460399026184 Columns 87 through 88 -6.338460399026184 -6.338460399026184 Columns 89 through 90 -6.338460399026184 -6.338460399026184 Columns 91 through 92 -6.338460399026184 -6.338460399026184 Columns 93 through 94 -6.338460399026184 -6.338460399026184 Columns 95 through 96 -6.338460399026184 -6.338460399026184 Columns 97 through 98 -6.338460399026184 -6.338460399026184 Columns 99 through 100 -6.338460399026184 -6.338460399026184 Columns 101 through 102 -6.338460399026184 -6.338460399026184 Columns 103 through 104 -6.338460399026184 -6.338460399026184 Columns 105 through 106 -6.338460399026184 -6.338460399026184 Columns 107 through 108 -6.338460399026184 -6.338460399026184 Columns 109 through 110 -6.338460399026184 -6.338460399026184 Columns 111 through 112 -6.338460399026184 -6.338460399026184 Columns 113 through 114 -6.338460399026184 -6.338460399026184 Columns 115 through 116 -6.338460399026184 -6.338460399026184 Columns 117 through 118 -6.338460399026184 -6.338460399026184 Columns 119 through 120 -6.338460399026184 -6.338460399026184 Columns 121 through 122 -6.338460399026184 -6.338460399026184 Columns 123 through 124 -6.338460399026184 -6.338460399026184 Columns 125 through 126 -6.338460399026184 -6.338460399026184 Columns 127 through 128 -6.338460399026184 -6.338460399026184 Columns 129 through 130 -6.338460399026184 -6.338460399026184 Columns 131 through 132 -6.338460399026184 -6.338460399026184 Columns 133 through 134 -6.338460399026184 -6.338460399026184 Columns 135 through 136 -6.338460399026184 -6.338460399026184 Columns 137 through 138 -6.338460399026184 -6.338460399026184 Columns 139 through 140 -6.338460399026184 -6.338460399026184 Columns 141 through 142 -6.338460399026184 -6.338460399026184 Columns 143 through 144 -6.338460399026184 -6.338460399026184 Columns 145 through 146 -6.338460399026184 -6.338460399026184 Columns 147 through 148 -6.338460399026184 -6.338460399026184 Columns 149 through 150 -6.338460399026184 -6.338460399026184 Columns 151 through 152 -6.338460399026184 -6.338460399026184 Columns 153 through 154 -6.338460399026184 -6.338460399026184 Columns 155 through 156 -6.338460399026184 -6.338460399026184 Columns 157 through 158 -6.338460399026184 -6.338460399026184 Columns 159 through 160 -6.338460399026184 -6.338460399026184 Columns 161 through 162 -6.338460399026184 -6.338460399026184 Columns 163 through 164 -6.338460399026184 -6.338460399026184 Columns 165 through 166 -6.338460399026184 -6.338460399026184 Columns 167 through 168 -6.338460399026184 -6.338460399026184 Columns 169 through 170 -6.338460399026184 -6.338460399026184 Columns 171 through 172 -6.338460399026184 -6.338460399026184 Columns 173 through 174 -6.338460399026184 -6.338460399026184 Columns 175 through 176 -6.338460399026184 -6.338460399026184 Columns 177 through 178 -6.338460399026184 -6.338460399026184 Columns 179 through 180 -6.338460399026184 -6.338460399026184 Columns 181 through 182 -6.338460399026184 -6.338460399026184 Columns 183 through 184 -6.338460399026184 -6.338460399026184 Columns 185 through 186 -6.338460399026184 -6.338460399026184 Columns 187 through 188 -6.338460399026184 -6.338460399026184 Columns 189 through 190 -6.338460399026184 -6.338460399026184 Columns 191 through 192 -6.338460399026184 -6.338460399026184 Columns 193 through 194 -6.338460399026184 -6.338460399026184 Columns 195 through 196 -6.338460399026184 -6.338460399026184 Columns 197 through 198 -6.338460399026184 -6.338460399026184 Columns 199 through 200 -6.338460399026184 -6.338460399026184 Columns 201 through 202 -6.338460399026184 -6.338460399026184 Columns 203 through 204 -6.338460399026184 -6.338460399026184 Columns 205 through 206 -6.338460399026184 -6.338460399026184 Columns 207 through 208 -6.338460399026184 -6.338460399026184 Columns 209 through 210 -6.338460399026184 -6.338460399026184 Columns 211 through 212 -6.338460399026184 -6.338460399026184 Columns 213 through 214 -6.338460399026184 -6.338460399026184 Columns 215 through 216 -6.338460399026184 -6.338460399026184 Columns 217 through 218 -6.338460399026184 -6.338460399026184 Columns 219 through 220 -6.338460399026184 -6.338460399026184 Columns 221 through 222 -6.338460399026184 -6.338460399026184 Columns 223 through 224 -6.338460399026184 -6.338460399026184 Columns 225 through 226 -6.338460399026184 -6.338460399026184 Columns 227 through 228 -6.338460399026184 -6.338460399026184 Columns 229 through 230 -6.338460399026184 -6.338460399026184 Columns 231 through 232 -6.338460399026184 -6.338460399026184 Columns 233 through 234 -6.338460399026184 -6.338460399026184 Columns 235 through 236 -6.338460399026184 -6.338460399026184 Columns 237 through 238 -6.338460399026184 -6.338460399026184 Columns 239 through 240 -6.338460399026184 -6.338460399026184 Columns 241 through 242 -6.338460399026184 -6.338460399026184 Columns 243 through 244 -6.338460399026184 -6.338460399026184 Columns 245 through 246 -6.338460399026184 -6.338460399026184 Columns 247 through 248 -6.338460399026184 -6.338460399026184 Columns 249 through 250 -6.338460399026184 -6.338460399026184 Columns 251 through 252 -6.338460399026184 -6.338460399026184 Columns 253 through 254 -6.338460399026184 -6.338460399026184 Columns 255 through 256 -6.338460399026184 -6.338460399026184 Columns 257 through 258 -6.338460399026184 -6.338460399026184 Columns 259 through 260 -6.338460399026184 -6.338460399026184 Columns 261 through 262 -6.338460399026184 -6.338460399026184 Columns 263 through 264 -6.338460399026184 -6.338460399026184 Columns 265 through 266 -6.338460399026184 -6.338460399026184 Columns 267 through 268 -6.338460399026184 -6.338460399026184 Columns 269 through 270 -6.338460399026184 -6.338460399026184 Columns 271 through 272 -6.338460399026184 -6.338460399026184 Columns 273 through 274 -6.338460399026184 -6.338460399026184 Columns 275 through 276 -6.338460399026184 -6.338460399026184 Columns 277 through 278 -6.338460399026184 -6.338460399026184 Columns 279 through 280 -6.338460399026184 -6.338460399026184 Columns 281 through 282 -6.338460399026184 -6.338460399026184 Columns 283 through 284 -6.338460399026184 -6.338460399026184 Columns 285 through 286 -6.338460399026184 -6.338460399026184 Columns 287 through 288 -6.338460399026184 -6.338460399026184 Columns 289 through 290 -6.338460399026184 -6.338460399026184 Columns 291 through 292 -6.338460399026184 -6.338460399026184 Columns 293 through 294 -6.338460399026184 -6.338460399026184 Columns 295 through 296 -6.338460399026184 -6.338460399026184 Columns 297 through 298 -6.338460399026184 -6.338460399026184 Columns 299 through 300 -6.338460399026184 -6.338460399026184 Column 301 -6.338460399026184 derLinFitPlot=polyval(derCoefLinFit,timePlot); derQuadFitPlot=polyval(derCoefQuadFit,timePlot); derQuartFitPlot=polyval(derCoefQuartFit,timePlot); plot(timePlot,derTempExact,'--k',timePlot,derLinFitPlot,'y',timeplot,derQuadFitPlot,'c',timeplot,derQuartFitPlot,'m') {Undefined function or variable 'derTempExact'.} plot(timePlot,derExactPlot,'--k',timePlot,derLinFitPlot,'y',timeplot,derQuadFitPlot,'c',timeplot,derQuartFitPlot,'m') {Undefined function or variable 'timeplot'.} plot(timePlot,derExactPlot,'--k',timePlot,derLinFitPlot,'y',timeplot,derQuadFitPlot,'c',timePlot,derQuartFitPlot,'m') {Undefined function or variable 'timeplot'.} plot(timePlot,derExactPlot,'--k',timePlot,derLinFitPlot,'y',timePlot,derQuadFitPlot,'c',timePlot,derQuartFitPlot,'m') timeDesired=3 timeDesired = 3 TempLinear=interp1(timeMeasured,TempMeasured,timeDesired,'linear','extrap') TempLinear = -0.739999999999999 TempExact TempExact = 0.538494244058104 TempSpline=spline(timeMeasuredN,TempMeasuredN,timeDesired) TempSpline = -8.348353902013725e+03 TempSpline=spline(timeMeasured,TempMeasured,timeDesired) TempSpline = -0.080000000000008 TempSplineN=spline(timeMeasuredN,TempMeasuredN,timeDesired) TempSplineN = -8.348353902013725e+03 TempLinearN=interp1(timeMeasuredN,TempMeasuredN,timeDesired,'linear','extrap') TempLinearN = -31.116374883265770 polyval(coefLinFit,3) ans = -6.567378793385581 polyval(coefQuadFit,3) ans = 3.380903122368734 polyval(coefQuartFit,3) ans = 13.630001984284986 save lecture5 help polyval polyval Evaluate polynomial. Y = polyval(P,X) returns the value of a polynomial P evaluated at X. P is a vector of length N+1 whose elements are the coefficients of the polynomial in descending powers. Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1) If X is a matrix or vector, the polynomial is evaluated at all points in X. See POLYVALM for evaluation in a matrix sense. [Y,DELTA] = polyval(P,X,S) uses the optional output structure S created by POLYFIT to generate prediction error estimates DELTA. DELTA is an estimate of the standard deviation of the error in predicting a future observation at X by P(X). If the coefficients in P are least squares estimates computed by POLYFIT, and the errors in the data input to POLYFIT are independent, normal, with constant variance, then Y +/- DELTA will contain at least 50% of future observations at X. Y = polyval(P,X,[],MU) or [Y,DELTA] = polyval(P,X,S,MU) uses XHAT = (X-MU(1))/MU(2) in place of X. The centering and scaling parameters MU are optional output computed by POLYFIT. Example: Evaluate the polynomial p(x) = 3x^2+2x+1 at x = 5,7, and 9: p = [3 2 1]; polyval(p,[5 7 9])% Class support for inputs P,X,S,MU: float: double, single See also polyfit, polyvalm. Reference page for polyval Other functions named polyval