[求助]一个数学公式的编写
[Discuz!]&Menu=yes" target="_blank">" border="0">我的公式由于不能在这写出来,我放在附件里了,请大家帮忙解决一下,下面是我原来的代码;我原来的代码中忘了说明Wij是矩阵,所以出了点错,Xi、Xj分别是已知的值,X上面一缸的是X的平均数,n是个数,请大家帮帮,谢谢了
private double summation()
{
double[] x = { 1, 2, 3 };
double [,] w ={{1,2,3},{4,5,6},{7,8,9}};
double wxx = 0, wij = 0, x1 = 0, x2 = 0;
int n = 3, i, j;
for (i=0; i<n; i++)
{
x1 += x[i];
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
wxx += w[i, j] * (x[i] - x1) * (x[j] - x1);
wij += w[i, j];
x2 += Math.Pow((x[i] - x1), 2);
}
}
return n/x2*wxx/wij;
}
或者带参数:
private double summation(double[]x,double[,]w,int n)
{
double wxx = 0, wij = 0, x1 = 0, x2 = 0;
int i, j;
for (i = 0; i < n; i++)
{
x1 += x[i];
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
wxx += w[i, j] * (x[i] - x1) * (x[j] - x1);
wij += w[i, j];
x2 += Math.Pow((x[i] - x1), 2);
}
}
return n / x2 * wxx / wij;
}
QQ.rar
(15.96 KB)