主题:[原创]为什么会这样?
Dim X() As Double, Y() As Double '定义
Dim m As Double, a As Double, b As Double
Dim a1 As Double, b1 As Double, c1 As Double, d1 As Double
Dim xmax As Double, ymax As Double, max As Double
Dim j As Integer
ReDim X(i + 4) As Double
ReDim Y(i + 4) As Double
For k = 0 To i + 4
X(k) = Val(Text1(k).Text) '获取form2的数据,并建组
Y(k) = Val(Text1(k + 10).Text)
If xmax < X(k) Then xmax = X(k)
If ymax < Y(k) Then ymax = Y(k)
If xmax < ymax Then
max = ymax '获得最大数据
Else
max = xmax
End If
j = Len(CStr(max)) '最大值的字符串长度
If max Mod 10 = 0 Then
j = j - 1
End If
Next
For k = 0 To i + 4
a1 = X(k) * X(k) + a1 'x()的平方和
b1 = X(k) + b1 'x()的和
c1 = X(k) * Y(k) + c1 'x()*Y()的和
d1 = Y(k) + d1 'y()的和
Next
m = b1 ^ 2 - (i + 5) * a1 'M的值
a = (c1 * b1 - d1 * a1) / m '截距
b = (b1 * d1 - (i + 5) * c1) / m '斜率
[color=FF00FF]我把X(),Y()改成single型,结果a,b的值与标准相差10^-8数量级,但text里输入的值都是100以内,只有一位小数.....照例说没超过single的数量范围,为什么非得改成double型的????????[/color]
Dim m As Double, a As Double, b As Double
Dim a1 As Double, b1 As Double, c1 As Double, d1 As Double
Dim xmax As Double, ymax As Double, max As Double
Dim j As Integer
ReDim X(i + 4) As Double
ReDim Y(i + 4) As Double
For k = 0 To i + 4
X(k) = Val(Text1(k).Text) '获取form2的数据,并建组
Y(k) = Val(Text1(k + 10).Text)
If xmax < X(k) Then xmax = X(k)
If ymax < Y(k) Then ymax = Y(k)
If xmax < ymax Then
max = ymax '获得最大数据
Else
max = xmax
End If
j = Len(CStr(max)) '最大值的字符串长度
If max Mod 10 = 0 Then
j = j - 1
End If
Next
For k = 0 To i + 4
a1 = X(k) * X(k) + a1 'x()的平方和
b1 = X(k) + b1 'x()的和
c1 = X(k) * Y(k) + c1 'x()*Y()的和
d1 = Y(k) + d1 'y()的和
Next
m = b1 ^ 2 - (i + 5) * a1 'M的值
a = (c1 * b1 - d1 * a1) / m '截距
b = (b1 * d1 - (i + 5) * c1) / m '斜率
[color=FF00FF]我把X(),Y()改成single型,结果a,b的值与标准相差10^-8数量级,但text里输入的值都是100以内,只有一位小数.....照例说没超过single的数量范围,为什么非得改成double型的????????[/color]