#include <iostream>
using namespace std
const int MAXNUM = 3
int main()
{
double x[MAXNUM],y[MAXNUM]
double sumx=0,sumy=0,sumxy=0,sumxx=0
double a,b
int i
cout<<"输入"<<MAXNUM<<腔搜"组样本:"
for (i=0i<MAXNUMi++)
{
cin>>x[i]>>y[i]
sumx += x[i]
sumy += y[i]
sumxy = x[i]*y[i]
sumxx = x[i]*x[i]
}
double averagex,averagey
averagex = sumx/MAXNUM
averagey = sumy/MAXNUM
b = (sumxy - MAXNUM*averagex*averagey)/(sumxx - MAXNUM*averagex*averagex)
a = averagey - b*averagex
cout<<穗圆帆"线性拟合曲线为:y="<猜雹<a<<"+"<<b<<"*y\n"
return 0
}
拟合直线之后宴肆会有一个拟合结果表,在这个表里有直线的方程,斜率值(slop),截距值(intercept),以及这些谨祥橡值的误差(error),和拟合结果的r^2(祥旁越接近于1,表明拟合结果越好)。如果没有看到这个表,那么点击菜单栏上的view
-
results
log,就能看到了。
Dim a() As String, b() As StringPrivate Sub Command1_Click()
Dim temp1 As String
Dim i As Integer, k As Integer
temp1 = Text1.Text
a = Split(temp1, ",")
lenolds = Len("->帆培")
For i = 0 To UBound(a)
s = a(i)
j = InStr(s, "->")
Do While j >0
ReDim Preserve b(i, k)
b(i, k) = Val(Left(s, j + lenolds))
s = Left(s, j - 1) + "->" + Mid(s, j + lenolds + 1)
k = k + 1
j = InStr(s, "型轿桐卜坦->")
Loop
ReDim Preserve b(i, k)
b(i, k) = s
Next i
For i = 0 To UBound(a)
For j = 0 To k
Text2.Text = Text2.Text + b(i, j)
Next j
Next i
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)