%% Logistic curve data tfit=linspace(-4,4,200); exact=1./(1+exp(-tfit)); plot(tfit,exact,'k','LineWidth',2); grid on; hold on; axis([-4 4 -0.2 1.2]); t=linspace(-4,4,10); y = 1./(1+exp(-t)) + (rand(1,numel(t))-0.5)/6; t=t.';y=y.'; plot(t,y,'o','MarkerSize',8,'MarkerFaceColor','b'); %% Least squares fit [R,c,x,err] = qr_house(vander(t,3),y); plot(tfit,poly(tfit,x),'r','linewidth',2); hold off; %% Error as a function of polynomial order for j = 1:numel(y)-1 plot(t,y,'bo','MarkerFaceColor','b','MarkerSize',8);xlabel('t');ylabel('y'); grid on; hold on; axis([-4 4 -0.2 1.2]); plot(tfit,exact,'k','LineWidth',2); [R,c,x,err] = qr_house(vander(t,j),y); title(['Polynomial order n = ',num2str(j), ' Error = ', num2str(err)]) plot(tfit,poly(tfit,x),'r','linewidth',2); hold off; pause(2) end