| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 333 人关注过本帖
标题:怎么把这C#改成C语言?(这道题关乎我的工作,请各位高手出手相助,万分感激 ...
只看楼主 加入收藏
yuandingfa
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-11-1
收藏
 问题点数:0 回复次数:0 
怎么把这C#改成C语言?(这道题关乎我的工作,请各位高手出手相助,万分感激)
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static double ApplyFuzzyOperation(double a,double b)
{
return Math.Min(a, b);
}

static void Main(string[] args)
{

while (true)
{
//模糊规则
//if e is E_NB and ec is EC_NB, then u is U_NB
//if e is E_PB and ec is EC_PB, then u is U_PB

//定义模糊集合
FuzzySet_Guass U_NB = new FuzzySet_Guass(3, -10, -10, 10, 1001, "U_NB");
FuzzySet_Guass U_PB = new FuzzySet_Guass(3, 10, -10, 10, 1001, "U_PB");

FuzzySet_Guass E_NB = new FuzzySet_Guass(3, -10, -10, 10, 1001, "E_NB");
FuzzySet_Guass E_PB = new FuzzySet_Guass(3, 10, -10, 10, 1001, "E_PB");

FuzzySet_Guass EC_NB = new FuzzySet_Guass(3, -10, -10, 10, 1001, "EC_NB");
FuzzySet_Guass EC_PB = new FuzzySet_Guass(3, 10, -10, 10, 1001, "EC_PB");


//输入误差e和误差变化率ec
Console.Write("e=");
double input1 = Convert.ToDouble(Console.ReadLine());
Console.Write("ec=");
double input2 = Convert.ToDouble(Console.ReadLine());

//step1
double e1 = E_NB.FuzzifyInput(input1);
double ec1 = EC_NB.FuzzifyInput(input2);
Console.WriteLine("e1={0},ec1={1}",e1,ec1);

//step2
double a1=ApplyFuzzyOperation(e1, ec1);
Console.WriteLine("a1={0}", a1);

//step3
U_NB.ApplyImplicationMethod(a1);//被改变的U_NB


//step1
double e2 = E_PB.FuzzifyInput(input1);
double ec2 = EC_PB.FuzzifyInput(input2);


//step2
double a2 = ApplyFuzzyOperation(e2, ec2);


//step3
U_PB.ApplyImplicationMethod(a2);//被改变的U_PB


//step4
U_PB.ApplyAggregationMethod(U_NB);//被改变的U_PB


//step5
double u = U_PB.Defuzzify();
Console.WriteLine("u={0}\n",u);
}

}
}



public class FuzzySet_Guass
{
double m_sigma;
double m_aver;

double m_border_left;
double m_border_right;

double m_points;

string m_name;

double[] m_data;

public void ApplyAggregationMethod(FuzzySet_Guass set1)
{
for (int i = 0; i < set1.m_data.Length;i++ )
{
this.m_data[i] = Math.Max(this.m_data[i], set1.m_data[i]);
}
}

public FuzzySet_Guass(double sigma, double aver, double border_left, double border_right, int points,string name)
{
m_sigma = sigma;
m_aver = aver;
m_border_left = border_left;
m_border_right = border_right;
m_points = points;
m_name = name;

m_data=new double[points];


double x = m_border_left;
for(int i=0;i <this.m_data.Length;i++)
{
x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
m_data[i]=Gauss(x, m_sigma, m_aver);
}
}

public double FuzzifyInput(double accurate_input)
{
return Gauss(accurate_input, m_sigma, m_aver);
}

public void ApplyImplicationMethod(double a)
{
for(int i=0;i <this.m_data.Length;i++)
{
this.m_data[i] = Math.Min(a,this.m_data[i]);
}
}

public double Defuzzify()
{
double numerator=0;

double denominator = 0;
double x=0;

for (int i = 0; i < this.m_data.Length;i++ )
{
x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
numerator += x * this.m_data[i];

denominator += this.m_data[i];
}

return numerator / denominator;
}

public void PrintFuzzySetElements()
{
Console.WriteLine("Fuzzy Set -- "+this.m_name);
foreach (double v in m_data)
{
Console.WriteLine(v);
}
Console.WriteLine();

for (int i = 0; i < this.m_data.Length; i++)
{
double x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
Console.WriteLine("i={0},data={1},x={2}",i,this.m_data[i],x);
}
Console.WriteLine();
}

double Gauss(double x, double sigma, double aver)
{
return Math.Pow(Math.E, -Math.Pow((x - aver) / sigma, 2)/2);
}
}
}
搜索更多相关主题的帖子: 感激 C语言 
2009-11-01 15:59
快速回复:怎么把这C#改成C语言?(这道题关乎我的工作,请各位高手出手相助,万 ...
数据加载中...
 
   



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

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