VB写的最小二乘法曲线拟合.doc
《VB写的最小二乘法曲线拟合.doc》由会员分享,可在线阅读,更多相关《VB写的最小二乘法曲线拟合.doc(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateVB写的最小二乘法曲线拟合Option ExplicitOption ExplicitDim x() As Double, y() As DoubleDim A(20, 20) As Double, M As Double, B() As Double 最多取20次的拟合Dim N As Double, I As Double, j As DoubleDim xiao
2、A() As DoubleDim Xmin As Double, Xmax As DoubleDim Ymin As Double, Ymax As DoubleDim X0pos As Double, Y0pos As DoubleDim xmaxpos As Double, ymaxpos As DoubleDim xstep As Double, ystep As DoubleDim xl As Double, yl As DoubleDim xbc As Double, ybc As DoubleDim bc As DoubleDim Xh As DoublePrivate Sub H
3、uaZuoBiao(x() As Double, y() As Double)ReDim xpos(I) As DoubleReDim ypos(I) As DoubleReDim x(I), y(I)X0pos = Width * 0.25 坐标原点最左点Y0pos = Height * 0.75 坐标原点最低点xmaxpos = Width * 0.85 坐标最右点ymaxpos = Height * 0.15 坐标最高点xstep = (xmaxpos - X0pos) / (Xmax - Xmin) 对应X轴上单位长度代表的屏幕宽度值ystep = (ymaxpos - Y0pos)
4、/ (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 + 100Print X 在横线上画X轴标志 在横线上画X轴箭头标志Cur
5、rentX = 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 + 200)-(
6、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 - YminIf xl 0.01 Then xbc = 0.001ElseIf xl = 0.1 Then xbc = 0.01ElseIf xl = 2 Then xbc
7、= 0.1ElseIf xl = 20 Then xbc = 1ElseIf xl = 120 Then xbc = 10ElseIf xl = 1000 Then xbc = 100ElseIf xl = 10000 Then xbc = 1000Else xbc = 10000End IfIf yl 0.01 Then ybc = 0.001ElseIf yl = 0.1 Then ybc = 0.01ElseIf yl = 2 Then ybc = 0.1ElseIf yl = 20 Then ybc = 1ElseIf yl = 120 Then ybc = 10ElseIf yl =
8、 1000 Then ybc = 100ElseIf yl = 10000 Then ybc = 1000Else ybc = 10000End If For bc = Xmin To Xmax Step xbcIf bc = Xmax Thenx(j) = bc X轴上的相对坐标值xpos(j) = X0pos + (x(j) - Xmin) * xstepLine (xpos(j), Y0pos)-(xpos(j), ymaxpos), vbRed 画垂直于X轴的刻度线,只画了100个绝对尺寸ElseEnd IfFont.Size = 10 指定X轴,Y轴坐标刻度值的字体大小Current
9、X = xpos(j) - 200 取当前X轴上的相对坐标值CurrentY = Y0pos + 100 此为X轴下方100绝对坐标处Print x(j) 在X轴下方100绝对坐标处对应显示X轴相对坐标刻度值Next bcFor bc = Ymin To Ymax Step ybcIf bc = Ymax Theny(j) = bc X轴上的相对坐标值ypos(j) = Y0pos + (y(j) - Ymin) * ystepLine (X0pos, ypos(j)-(xmaxpos, ypos(j), vbRed 画垂直于X轴的刻度线,只画了100个绝对尺寸ElseEnd IfFont.S
10、ize = 10 指定X轴,Y轴坐标刻度值的字体大小CurrentX = X0pos - 500 取当前X轴上的相对坐标值CurrentY = ypos(j) - 100 此为X轴下方100绝对坐标处Print y(j) 在X轴下方100绝对坐标处对应显示X轴相对坐标刻度值Next bcEnd SubPrivate Sub ZuoDian(x() As Double, y() As Double)ReDim xpos(I) As DoubleReDim ypos(I) As DoubleFor I = 0 To Nxpos(I) = X0pos + (x(I) - Xmin) * xstepy
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 最小二乘法 曲线拟合
限制150内