1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| n=1; p=zeros(1,n+1); b='x^'; p = polyfit(mc.VarName1(1:20000),exp(mc.VarName2(1:20000)),n); t2 = 20.0:0.001:20000; y2 = polyval(p,t2); p = polyfit(mc.VarName1(20001:50000),exp(mc.VarName2(20001:50000)),n); t3 = 20001.0:0.001:50000; y3 = polyval(p,t3); p = polyfit(mc.VarName1(50001:60000),exp(mc.VarName2(50001:60000)),n); t4 = 50001.0:0.001:60000; y4 = polyval(p,t4); p = polyfit(mc.VarName1(60001:70000),exp(mc.VarName2(60001:70000)),n); t5 = 60001.0:0.001:70000; y5 = polyval(p,t5); p = polyfit(mc.VarName1(70001:80000),exp(mc.VarName2(70001:80000)),n); t6 = 70001.0:0.001:80000; y6 = polyval(p,t6); p = polyfit(mc.VarName1(80001:90000),exp(mc.VarName2(80001:90000)),n); t7 = 80001.0:0.001:90000; y7 = polyval(p,t7); p = polyfit(mc.VarName1(90001:99981),exp(mc.VarName2(90001:99981)),n); t8 = 90001.0:0.001:99981; y8 = polyval(p,t8); figure plot(mc.VarName1,exp(mc.VarName2),'.',t2,y2,'y','LineWidth',1) hold on plot(t3,y3,'y','LineWidth',1) hold on plot(t4,y4,'y','LineWidth',1) hold on plot(t5,y5,'y','LineWidth',1) hold on plot(t6,y6,'y','LineWidth',1) hold on plot(t7,y7,'y','LineWidth',1) hold on plot(t8,y8,'y','LineWidth',1) poly2sym(p); fprintf('\nf(x)='); txt=''; for i=1:(n+1) xs=''; if p(i)>0 fprintf('+%g*%s%d',p(i),b,n+1-i); xs=['+',num2str(p(i)),num2str(b),num2str(n+1-i)]; else if p(i)<0 fprintf('%g*%s%d',p(i),b,n+1-i); xs=[num2str(p(i)),num2str(b),num2str(n+1-i)]; else if p(i)==0 fprintf(' '); xs=' '; end end end txt=[txt,xs]; end fprintf('\n'); t=text(50000,0.1,txt);
title('Plot of Data (Points) and Model (Line)')
y3 = polyval(p,mc.VarName1); res = mc.VarName2 - y3;
title('Plot of the Residuals')
|