| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 693 人关注过本帖
标题:[求助]一个数学公式的编写
只看楼主 加入收藏
dcc3013
Rank: 1
来 自:青海
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-8-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
[求助]一个数学公式的编写

我的公式由于不能在这写出来,我放在附件里了,请大家帮忙解决一下,下面是我原来的代码;我原来的代码中忘了说明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)
搜索更多相关主题的帖子: 公式 
2009-08-12 15:09
xdzhangtao
Rank: 2
等 级:论坛游民
帖 子:6
专家分:34
注 册:2008-7-31
收藏
得分:20 
#include<stdio.h>
#include<conio.h>
#include<math.h>
 
 
double summation(void)
        {
            double x[] = { 1, 2, 3 };
            double w[][3] ={{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+=pow((x[i] - x1), 2);
                }
            }
            return n/x2*wxx/wij;
        }  
int main()
{  
    double a=summation();
    printf("%f",a);
    getch();
    return 0;
}

看看这个,你自创数组啊
2009-08-16 21:08
快速回复:[求助]一个数学公式的编写
数据加载中...
 
   



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

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