format compact more off tMeasured=[0 0.5 1 1.5 2] tMeasured = 0 0.5000 1.0000 1.5000 2.0000 tMeasured=[0 0.5 1 1.5 2]'; TExactFun=@(t)14.6*exp(-1.1*t); tPlot=linspace(0,2,100)'; TExactPlot=TExactFun(tPlot); TMeasured=TExactFun(tMeasured); TMeasured TMeasured = 14.6000 8.4235 4.8599 2.8039 1.6177 round(TMeasured) ans = 15 8 5 3 2 TMeasured=round(TMeasured); t=0.7; TLinear=interp1(TMeasured,TMeasured,t) TLinear = NaN TLinear=interp1(tMeasured,TMeasured,t) TLinear = 6.8000 TSpline=spline(tMeasured,TMeasured,t) TSpline = 6.5300 tMeasured=[0 0.5 1 1.5 2]'; TExactFun=@(t)14.6*exp(-1.1*t); TMeasured=TExactFun(tMeasured); tPlot=linspace(0,2,100)'; TExactPlot=TExactFun(tPlot); TMeasured=round(TMeasured); t=0.7; TLinear=interp1(tMeasured,TMeasured,t); TSpline=spline(tMeasured,TMeasured,t); TLinear TLinear = 6.8000 TSpline TSpline = 6.5300 TExactFun(t) ans = 6.7600 TLinearPlot=interp1(tMeasured,TMeasured,tPlot); TSplinePlot=spline(tMeasured,TMeasured,tPlot); plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... tPlot,TLinearPlot,'r',tPlot,TSplinePlot,'b') errLinear=max(abs(TLinearplot-TExactPlot)); {Undefined function or variable 'TLinearplot'.} errLinear=max(abs(TLinearPlot-TExactPlot)); errLinear=max(abs(TLinearPlot-TExactPlot)) errLinear = 0.5255 errSpline=max(abs(TSplinePlot-TExactPlot)) errSpline = 0.4445 CoefLin=polyfit(tMeasured,TMeasured,1) CoefLin = -6.2000 12.8000 t=0.7 t = 0.7000 polyval(CoefLin,t) ans = 8.4600 TLinFitPlot=polyval(CoefLin,tPlot); plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... tPlot,TLinFitPlot,'r') CoefPar=polyfit(tMeasured,TMeasured,2) CoefPar = 3.7143 -13.6286 14.6571 plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... TParFitPlot=polyval(CoefPar,tPlot); polyval(CoefPar,t) ans = 6.9371 plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... tPlot,TParFitPlot,'r') errPar=max(abs(TParFitPlot-TExactPlot)) errPar = 0.6394 CoefCube=polyfit(tMeasured,TMeasured,3) CoefCube = -2.0000 9.7143 -17.9286 14.9571 polyval(CoefCube,t) ans = 6.4811 TCubeFitPlot=polyval(CoefCube,tPlot); plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... tPlot,TCubeFitPlot,'r') errCube=max(abs(TCubeFitPlot-TExactPlot)) errCube = 0.4838 CoefQuart=polyfit(tMeasured,TMeasured,4) CoefQuart = 2.0000 -10.0000 19.5000 -21.5000 15.0000 polyval(CoefQuart,t) ans = 6.5552 TQuartFitPlot=polyval(CoefQuart,tPlot); plot(tPlot,TExactPlot,'k:',tMeasured,TMeasured,'mo',... tPlot,TQuartFitPlot,'r') errQuart=max(abs(TQuartFitPlot-TExactPlot)) errQuart = 0.4732 derTExactPlot=-1.1*TExactPlot derTExactPlot = -16.0600 -15.7070 -15.3619 -15.0242 -14.6941 -14.3711 -14.0553 -13.7464 -13.4443 -13.1488 -12.8598 -12.5772 -12.3008 -12.0305 -11.7661 -11.5075 -11.2546 -11.0072 -10.7653 -10.5287 -10.2974 -10.0711 -9.8497 -9.6332 -9.4215 -9.2145 -9.0120 -8.8139 -8.6202 -8.4308 -8.2455 -8.0643 -7.8870 -7.7137 -7.5442 -7.3784 -7.2162 -7.0576 -6.9025 -6.7508 -6.6025 -6.4574 -6.3154 -6.1767 -6.0409 -5.9081 -5.7783 -5.6513 -5.5271 -5.4056 -5.2868 -5.1706 -5.0570 -4.9459 -4.8372 -4.7309 -4.6269 -4.5252 -4.4258 -4.3285 -4.2334 -4.1403 -4.0493 -3.9603 -3.8733 -3.7882 -3.7049 -3.6235 -3.5439 -3.4660 -3.3898 -3.3153 -3.2425 -3.1712 -3.1015 -3.0333 -2.9667 -2.9015 -2.8377 -2.7753 -2.7144 -2.6547 -2.5964 -2.5393 -2.4835 -2.4289 -2.3755 -2.3233 -2.2723 -2.2223 -2.1735 -2.1257 -2.0790 -2.0333 -1.9886 -1.9449 -1.9022 -1.8604 -1.8195 -1.7795 derTExactPlot=-1.1*TExactPlot; derTExactPlot=-1.1*TExactPlot; derCoefLin=polyder(CoefLin); derCoefPar=polyder(CoefPar); derCoefCube=polyder(CoefCube); derTLinFitPlot=polyval(derCoefLin,tPlot); derTParFitPlot=polyval(derCoefPar,tPlot); derTCubeFitPlot=polyval(derCoefCube,tPlot); derTQuartFitPlot=polyval(derCoefQuart,tPlot); {Undefined function or variable 'derCoefQuart'.} derTQuartFitPlot=polyval(derCoefQuart,tPlot); {Undefined function or variable 'derCoefQuart'.} derCoefQuart=polyder(CoefQuart); derTQuartFitPlot=polyval(derCoefQuart,tPlot); plot(tPlot,derTExactPlot,'k',... tPlot,derTLinFitPlot,'r',... tPlot,derTParFitPlot,'g',... tPlot,derTCubeFitPlot,'b',... tPlot,derTQuartFitPlot,'y') exit