matlab中的一元回归

学习 时间:2026-04-01 15:12:37 阅读:2717
matlab中的一元回归我在matlab中输入如下程序function[x,y]=DataRegress1xx=[2.38 2.44 2.70 2.98 3.32 3.12 2.14 2.86 3.50 3.20 2.78 2.70 2.36 2.42 2.62 2.80 2.92 3.04 3.26 2.30];yy=[51.11 50.63 51.82 52.97 54.47 53.33 49.90 51.99 55.81 52.93 52.87 52.36 51.38 50.87 51.02 51.29 52.73 52.81 53.59 49.77];[x,index]=sort(xx);y=yy(index);[x,y]=DataRegress1;[c,s]=polyfit(x,y,1);[yhat,w]=polyconf(c,x,s,.05);syy=sum(y.^2)-length(x)*mean(y)^2;sse=syy-c(1)*(sum(x.*y)-length(x)*mean(x)*mean(y));plot(x,yhat,'k-',x,yhat-w,'k--',x,yhat+w,'k- -',x,y,'ks',[x;x],[yhat;y],'k-')legend('Regression line','95% confidence of y',4)axis([2 3.6 57])xlabel('x(input)')ylabel('y(reponse)')titel('simple linear regression')text(2.1,56,['coefficient of determination R^2=' num2str(1-sse/syy,3)])来进行一元回归,可执行的时候弹出如下对话Maximum recursion limit of 500 reached.Use set(0,'RecursionLimit',N)to change the limit.Be aware that exceeding your available stack space cancrash MATLAB and/or your computer.Error in ==> C:\MATLAB6p5p1\progarm\DataRegress1.mOn line 7 ==> [x,y]=DataRegress1;执行不出意料中的图,请问是上面的提示是什么意思,应该如何解决啊,万谢!

最佳回答

闪闪的未来

复杂的睫毛膏

2026-04-01 15:12:37

改了4处,程序通了,见程序批注。function[x,y]=DataRegress1 xx=[2。38 2。44 2。70 2。98 3。32 3。12 2。14 2。86 3。50 3。20 2。78 2。70 2。36 2。42 2。62 2。80 2。92 3。04 3。26 2。30]; yy=[51。11 50。63 51。82 52。97 54。47 53。33 49。90 51。99 55。81 52。93 52。87 52。36 51。38 50。87 51。02 51。29 52。73 52。81 53。59 49。77]; [x,index]=sort(xx) y=yy(index)%[x,y]=DataRegress1; %useless sentance[c,s]=polyfit(x,y,1); [yhat,w]=polyconf(c,x,s,。05); syy=sum(y。^2)-length(x)*mean(y)^2; sse=syy-c(1)*(sum(x。*y)-length(x)*mean(x)*mean(y)); plot(x,yhat,'k-',x,yhat-w,'k--',x,yhat+w,'k--',x,y,'ks',[x;x],[yhat;y],'k-') %yhat+w,'k--' NOT yhat+w,'k- -'legend('Regression line','95% confidence of y',4) axis([2 3。6 48 57]) %Ymin=48 absentxlabel('x(input)') ylabel('y(reponse)') title('simple linear regression') %title NOT titeltext(2。1,56,['coefficient of determination R^2=' num2str(1-sse/syy,3)])

最新回答共有2条回答

  • 踏实的小虾米
    回复
    2026-04-01 15:12:37

    改了4处,程序通了,见程序批注。function[x,y]=DataRegress1 xx=[2。38 2。44 2。70 2。98 3。32 3。12 2。14 2。86 3。50 3。20 2。78 2。70 2。36 2。42 2。62 2。80 2。92 3。04 3。26 2。30]; yy=[51。11 50。63 51。82 52。97 54。47 53。33 49。90 51。99 55。81 52。93 52。87 52。36 51。38 50。87 51。02 51。29 52。73 52。81 53。59 49。77]; [x,index]=sort(xx) y=yy(index)%[x,y]=DataRegress1; %useless sentance[c,s]=polyfit(x,y,1); [yhat,w]=polyconf(c,x,s,。05); syy=sum(y。^2)-length(x)*mean(y)^2; sse=syy-c(1)*(sum(x。*y)-length(x)*mean(x)*mean(y)); plot(x,yhat,'k-',x,yhat-w,'k--',x,yhat+w,'k--',x,y,'ks',[x;x],[yhat;y],'k-') %yhat+w,'k--' NOT yhat+w,'k- -'legend('Regression line','95% confidence of y',4) axis([2 3。6 48 57]) %Ymin=48 absentxlabel('x(input)') ylabel('y(reponse)') title('simple linear regression') %title NOT titeltext(2。1,56,['coefficient of determination R^2=' num2str(1-sse/syy,3)])

上一篇 垛口 长城 中国 城墙 如何排序

下一篇 怎样度过大学时光才算有意义?