Dim a() As String, b() As String
Private 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
#include <math.h>#include <stdio.h>
#include <stdlib.h>
void analysis(double * x, double * y, int n) {
double d1, d2, d3,a,b
double sumx,sumy,sumxx,sumyy,sumxy,mx,my,mxx,myy,mxy
int i
// 变量的初始化
d1 = d2 = d3 =sumx=sumy=sumxx=sumyy=sumxy=0.0
// 计算x、y的平均值
for (i = 0 i < n i++) {
sumx += x[i]
sumy += y[i]
}
mx = sumx / n
my = sumy / n
printf("mx=%f my=%f\n",mx,my)
// 计算x、y平和x*y的平均值
for (i = 0 i < n i++) {
sumxx += x[i]*x[i]
sumyy += y[i]*y[i]
sumxy += x[i]*y[i]
}
mxx = sumxx / n
myy = sumyy / n
mxy = sumxy / n
printf("mxx=%f myy=%f mxy=%f\n",mxx,myy,mxy)
//
a=(n*sumxy-sumx*sumy)/(n*sumxx-sumx*sumx)
b=(sumxx*sumy-sumx*sumxy)/(n*sumxx-sumx*sumx)
printf("a=%f b=%f\n",a,b)
// 计算相关系数的数据组成部分
for (i = 0 i < n i++) {
d1 += (x[i] - mx) * (y[i] - my)
d2 += (x[i] - mx) * (x[i] - mx)
d3 += (y[i] - my) * (y[i] - my)
}
double r = d1 / sqrt(d2 * d3)
//
printf("相关系数r=%f\n",r)
//
double *yy=(double*)malloc(sizeof(double)*n)
double sumerrorsquare=0,error
for(i=0i<ni++) {
yy[i]=a*x[i]+b
sumerrorsquare+=(yy[i]-y[i])*(yy[i]-y[i])
}
error=sqrt(sumerrorsquare/(n-1))
printf("标准偏差s(y)=%f\n",error)
}
int main(){
double x[4]={1.0,3.0,3.0,9.0}
double y[4]={11.0,12.0,13.0,14.0}
analysis(x,y,4)
return 0
}
1、每个funciton开头的程序都要保存成独立的文件,最好在同一个文件夹中;2、运行的时候在Command Window中直接输入yiyuan,然后按提示依次输入,尤其注意x,y的维数要相同。
以上2条做了以后,如果出现错误了,请把你输入的东西和错误提示发上来,我帮你看看。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)