ill_polyfit.m Test example for polynomial regression Test example for polynomial regression x x 0.1:0.1:1 Data Data x.^3 - 0.1*x + 1 DataC DataC Data+0.02*randn(1,10) xP xP 0:0.01:1.2 for x n n 1:5 Pn = polyfit(x,DataC,n) devn devn DataC-polyval(Pn,x) Yn Yn polyval(Pn,xP) figure figure ind ind ind+1 hold hold on on end for end for o o 1:5 D = DataC end[th, tll] [th, tll] end arx([D;ones(size(x))]) end end emar emar exp(marll) figure figure Position Position close all close all figure (1) figure 1 subplot (2, 2, 1) subplot 2 2 1 plot (x, DataC,'+') plot x DataC '+' set (gca,'XLim',[0, 1.4]) set gca 'XLim' title ('y=x^3-0.1x+1+0.1 N(0, 1)') title ' y x^3-0.1x+1+0.1 N(0, 1)' set (gcf,'Position',[100 100 350 250]) set gcf 'Position' set (gcf,'PaperPositionMode','auto') set gcf 'PaperPositionMode' 'auto' id id ind () ind subplot (2, 2, ind) subplot 2 2 ind plot (xP, Yn) plot xP Yn title (['Order='num2str(n) ', MSE='num2str(devn *devn'/10)]) title eval (['print-depsc2 f'num2str(n)]) eval close all close all mse (n) mse n marll (o) marll o subplot (1, 2, 1) subplot 1 2 1 bar (emar/sum(emar)) bar emar/ sum emar title ('Probability of the correct order') title 'Probability of the correct order' subplot (1, 2, 2) subplot 1 2 2 plot (-marll/100) plot -marll/ 100 hold on hold on plot (1:5, mse *10,'r') plot 1:5 mse * 10 'r' title ('Bayes factor and MSE') set(gcf title 'Bayes factor and MSE' %Testexampleforpolynomialregression x=0.1:0.1:1; Data=x.^3-0.1*x+1; %DataC=Data+0.02*randn(1,10); xP=0:0.01:1.2; closeall figure(1); %subplot(2,2,1); plot(x,DataC,'+'); set(gca,'XLim',); title('y=x^3-0.1x+1+0.1N(0,1)'); set(gcf,'Position',); set(gcf,'PaperPositionMode','auto'); print-depsc2f0 ind=2; forn=1:5 Pn=polyfit(x,DataC,n); devn=DataC-polyval(Pn,x); Yn=polyval(Pn,xP); %subplot(2,2,ind); figure ind=ind+1; plot(x,DataC,'+'); holdon; plot(xP,Yn); title(['Order='num2str(n)',MSE='num2str(devn*devn'/10)]); set(gcf,'Position',[100100350250]); set(gcf,'PaperPositionMode','auto'); eval(['print-depsc2f'num2str(n)]); closeall mse(n)=devn*devn'/10; end foro=1:5 D=DataC; forn=1:o D=[D;x.^n]; end [th,tll]=arx([D;ones(size(x))]); marll(o)=tll; end emar=exp(marll); figure; subplot(1,2,1); bar(emar/sum(emar)); title('Probabilityofthecorrectorder'); subplot(1,2,2); plot(-marll/100); holdon plot(1:5,mse*10,'r'); title('BayesfactorandMSE') set(gcf,'Position',[100100600250]); set(gcf,'PaperPositionMode','auto'); print-depsc2prob