| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:VB小白求助,哪位大神能帮忙对我的程序进行以下修改,本人万分感谢
取消只看楼主 加入收藏
ciweizyy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
VB小白求助,哪位大神能帮忙对我的程序进行以下修改,本人万分感谢
下面是线性曲线拟合的代码,程序运行显示的是一条直线,但我现在需要一个多项式曲线拟合的程序,也就是说我需要这个程序能显示出曲线,就是做一个二次或二次以上的多项式曲线拟合的程序,只要能在图片框中运行出拟合曲线的结果就行,最好能给我标注一下主要代码的意思,以下的标注不知道对不对,哪位大神能帮帮忙,小白不胜感激!!!

Dim x() As Single, y() As Single, i As Integer, n As Integer, m As Integer’定义为单精度浮点数和整型
Dim sumx As Double, sumy As Double, xaver As Double, yaver As Double
Dim xy As Double, x2 As Double
Dim a As Double, b As Double
Dim xmax As Double, xmin As Double
Dim ymax As Double, ymin As Double’定义为双精度浮点数

Private Sub Command1_Click()
    Randomize’语句初始化随机数生成器
    n = InputBox("请输入坐标点个数:")’数据输入语句
    If n = 0 Then
        MsgBox "请输入坐标点个数"’提示信息
        Command1.Enabled = True
    ElseIf n = 1 Then
        MsgBox "单点无法拟合,请重新输入"
        Exit Sub
        Command1.Enabled = False
        Command2.Enabled = False
        Command3.Enabled = False
        Command4.Enabled = True
         
    Else
        Command1.Enabled = False
        Command2.Enabled = True
        Command4.Enabled = True
    End If
    ReDim x(n)
    ReDim y(n) ’定义数组
    For i = 1 To n
        x(i) = InputBox("请输入第" & i & "个点的横坐标")
        sumx = sumx + x(i)
        Text1 = Text1 & "第" & i & "个点:(" & x(i)
        y(i) = InputBox("请输入第" & i & "个点的纵坐标")
        sumy = sumy + y(i)
        Text1 = Text1 & "," & y(i) & " )" & vbCrLf’输出到text1,vbCrLf回车加换行
    Next i
End Sub

Private Sub Command2_Click()
    Picture1.Cls’清空图像上的内容
    Picture1.DrawWidth = 1’返回或设置图形方法输出的线宽为1
    Command2.Enabled = False
    Command3.Enabled = True
    Command4.Enabled = True
    xmax = x(1): xmin = x(1)
    ymax = y(1): ymin = y(1)
    For i = 2 To n
        If xmax < x(i) Then
            xmax = x(i)
        End If
        If xmin > x(i) Then
            xmin = x(i)
        End If
    Next i
    For i = 2 To n
        If ymax < y(i) Then
           ymax = y(i)
        End If
        If ymin > y(i) Then
            ymin = y(i)
        End If
    Next i
    If xmax = xmin Then
        Picture1.Scale (xmin * 0.5, ymax + 0.2 * (ymax - ymin))-(xmin * 1.5, ymin - 0.2 * (ymax - ymin))
        zbz xmin * 0.5, ymax + 0.2 * (ymax - ymin), xmin * 1.5, ymin - 0.2 * (ymax - ymin)
    ElseIf ymax = ymin Then
        Picture1.Scale (xmin - 0.2 * (xmax - xmin), ymax * 1.5)-(xmax + 0.2 * (xmax - xmin), ymin * 0.5)
        zbz xmin - 0.2 * (xmax - xmin), ymax * 1.5, xmax + 0.2 * (xmax - xmin), ymin * 0.5
    Else
        Picture1.Scale (xmin - 0.2 * (xmax - xmin), ymax + 0.2 * (ymax - ymin))-(xmax + 0.2 * (xmax - xmin), ymin - 0.2 * (ymax - ymin))
        zbz xmin - 0.2 * (xmax - xmin), ymax + 0.2 * (ymax - ymin), xmax + 0.2 * (xmax - xmin), ymin - 0.2 * (ymax - ymin) ’自定义坐标系
    End If
    Picture1.DrawWidth = 5’图片框输出线宽为5
        For i = 1 To n
            Picture1.PSet (x(i), y(i)), vbRed’在图片框上画点
        Next i
End Sub

Private Sub Command3_Click()
    Command3.Enabled = False
    Command4.Enabled = True
    Picture2.Cls
    xaver = sumx / n
    yaver = sumy / n
    For i = 1 To n
        xy = xy + x(i) * y(i)
        x2 = x2 + x(i) * x(i)
    Next i
    b = (xy - n * xaver * yaver) / (x2 - n * xaver * xaver)
    a = yaver - b * xaver
    a = Left(a, 6)
    b = Left(b, 6)
    Picture2.Print "y=" & b & "x+" & a
    If xmax = xmin Then
        Picture1.Scale (xmin * 0.5, ymax + 0.2 * (ymax - ymin))-(xmin * 1.5, ymin - 0.2 * (ymax - ymin))
        zbz xmin * 0.5, ymax + 0.2 * (ymax - ymin), xmin * 1.5, ymin - 0.2 * (ymax - ymin)
        Picture1.Line (xmax, ymax + 0.2 * (ymax - ymin))-(xmax, ymin - 0.2 * (ymax - ymin)), vbBlue’在图片框里画直线
    ElseIf ymax = ymin Then
        Picture1.Scale (xmin - 0.2 * (xmax - xmin), ymax * 1.5)-(xmax + 0.2 * (xmax - xmin), ymin * 0.5)
        zbz xmin - 0.2 * (xmax - xmin), ymax * 1.5, xmax + 0.2 * (xmax - xmin), ymin * 0.5
        Picture1.Line (xmin - 0.2 * (xmax - xmin), ymax)-(xmax + 0.2 * (xmax - xmin), ymin), vbBlue’在图片框里画直线
    Else
        Picture1.Scale (xmin - 0.2 * (xmax - xmin), ymax + 0.2 * (ymax - ymin))-(xmax + 0.2 * (xmax - xmin), ymin - 0.2 * (ymax - ymin))
        zbz xmin - 0.2 * (xmax - xmin), ymax + 0.2 * (ymax - ymin), xmax + 0.2 * (xmax - xmin), ymin - 0.2 * (ymax - ymin)
        Picture1.Line (xmin - 0.2 * (xmax - xmin), b * (xmin - 0.2 * (xmax - xmin)) + a)-(xmax + 0.2 * (xmax - xmin), b * (xmax + 0.2 * (xmax - xmin)) + a), vbBlue’在图片框里画直线
    End If
   
End Sub

Private Sub Command4_Click()
    Text1.Text = ""
    Picture1.Cls
    Picture2.Cls
    Command1.Enabled = True
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
End Sub

Private Sub Command5_Click()
    End
End Sub

Private Sub Form_Activate()’窗体被选为活动窗体时的载入事件
    Dim s As Integer, l As Single’定义为整型,单精度浮点数
    Dim p1 As Single, p2 As Single
    p1 = ScaleWidth: p2 = ScaleHeight’
    l = 255 / p1
    For s = 0 To p1
        Line (s, 0)-(s, p2), RGB(255 - s * l, 255 - s * l, 255 - s * l)
    Next s
End Sub

Private Sub Form_Load()
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
    Picture1.AutoRedraw = True
End Sub

Function zbz(ByVal x1 As Single, y1 As Single, x2 As Single, y2 As Single) ’定义zbz为function过程。Byval 表示参数是按值来传递
For i = x1 + (x2 - x1) / 5 To x2 Step (x2 - x1) / 5
    Picture1.Line (i, y2 + 100 * (y1 - y2) / Picture1.Height)-(i, y2) ’直线的两个端点位置
    Picture1.CurrentX = i - 250 * (x2 - x1) / Picture1.Width’当前打印横坐标的位置
    Picture1.CurrentY = y2 + 350 * (y1 - y2) / Picture1.Height’当前打印纵坐标的位置

    Picture1.Print i
Next
For i = y2 + (y1 - y2) / 5 To y1 Step (y1 - y2) / 5
    Picture1.Line (x1, i)-(x1 + 100 * (x2 - x1) / Picture1.Width, i)
    Picture1.CurrentX = x1 + 150 * (x2 - x1) / Picture1.Width
    Picture1.CurrentY = i + 80 * (y1 - y2) / Picture1.Height
    Picture1.Print i
Next
End Function
搜索更多相关主题的帖子: 不胜感激 多项式 图片 最好 
2015-06-12 16:48
ciweizyy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-6-12
收藏
得分:0 
哪位大神做好了发我邮箱1824090612@   先跪谢了!!!
2015-06-12 16:50
快速回复:VB小白求助,哪位大神能帮忙对我的程序进行以下修改,本人万分感谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026657 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved