资源描述:
《VB写的最小二乘法曲线拟合.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、OptionExplicitDimx()AsDouble,y()AsDoubleDimA(20,20)AsDouble,MAsDouble,B()AsDouble'最多取20次的拟合DimNAsDouble,IAsDouble,jAsDoubleDimxiaoA()AsDoubleDimXminAsDouble,XmaxAsDoubleDimYminAsDouble,YmaxAsDoubleDimX0posAsDouble,Y0posAsDoubleDimxmaxposAsDouble,ymaxposAsDoubleDimxstepAsDouble,ystepAsDouble
2、DimxlAsDouble,ylAsDoubleDimxbcAsDouble,ybcAsDoubleDimbcAsDoubleDimXhAsDoublePrivateSubHuaZuoBiao(x()AsDouble,y()AsDouble)ReDimxpos(I)AsDoubleReDimypos(I)AsDoubleReDimx(I),y(I)X0pos=Width*0.25'坐标原点最左点Y0pos=Height*0.75'坐标原点最低点xmaxpos=Width*0.85'坐标最右点ymaxpos=Height*0.15'坐标最高点xstep=(xmaxpos-X0p
3、os)/(Xmax-Xmin)'对应X轴上单位长度代表的屏幕宽度值ystep=(ymaxpos-Y0pos)/(Ymax-Ymin)'对应Y轴上单位长度代表的屏幕高度值'在屏幕上画直角坐标系ForeColor=vbBlueLine(Width*0.1,Y0pos)-(Width*0.9,Y0pos)'画X坐标轴,从左10%,到右的90%处Line(X0pos,Height*0.1)-(X0pos,Height*0.9)'画y坐标轴,从上10%,到下的90%处Font.Size=20'指定X轴,Y轴标志的字体大小CurrentX=Width*0.9CurrentY=Y0pos+
4、100Print"X"'在横线上画X轴标志'在横线上画X轴箭头标志CurrentX=Width*0.9CurrentY=Y0posLine(CurrentX-200,CurrentY-50)-(CurrentX,CurrentY)Line(CurrentX,CurrentY)-(CurrentX-200,CurrentY+50)CurrentX=X0pos-500CurrentY=Height*0.1Print"y"'在纵线上画Y轴标志'在纵线上画Y轴箭头标志CurrentX=X0posCurrentY=Height*0.1Line(CurrentX-50,CurrentY+
5、200)-(CurrentX,CurrentY)Line(CurrentX,CurrentY)-(CurrentX+50,CurrentY+200)CurrentX=X0pos+200'此为Y轴左边500绝对坐标处CurrentY=Y0pos+400'取当前Y轴上的相对坐标值Print"f=f(x)"'在Y轴左边500绝对坐标处对应显示Y轴相对坐标刻度值xl=Xmax-Xminyl=Ymax-YminIfxl<0.01Thenxbc=0.001ElseIfxl<=0.1Thenxbc=0.01ElseIfxl<=2Thenxbc=0.1ElseIfxl<=20Thenxbc=
6、1ElseIfxl<=120Thenxbc=10ElseIfxl<=1000Thenxbc=100ElseIfxl<=10000Thenxbc=1000Elsexbc=10000EndIfIfyl<0.01Thenybc=0.001ElseIfyl<=0.1Thenybc=0.01ElseIfyl<=2Thenybc=0.1ElseIfyl<=20Thenybc=1ElseIfyl<=120Thenybc=10ElseIfyl<=1000Thenybc=100ElseIfyl<=10000Thenybc=1000Elseybc=10000EndIfForbc=XminToXm
7、axStepxbcIfbc<=XmaxThenx(j)=bc'X轴上的相对坐标值xpos(j)=X0pos+(x(j)-Xmin)*xstepLine(xpos(j),Y0pos)-(xpos(j),ymaxpos),vbRed'画垂直于X轴的刻度线,只画了100个绝对尺寸ElseEndIfFont.Size=10'指定X轴,Y轴坐标刻度值的字体大小CurrentX=xpos(j)-200'取当前X轴上的相对坐标值CurrentY=Y0pos+100'此为X轴下方100绝对坐标处Printx(j)'在X