c#的php math函数类包含所有的函数吗

Posts - 5,
Articles - 0,
Comments - 0
23:38 by 唐永华, ... 阅读,
对基本类的反射,获取到该类的所有变量定义,函数等信息
private void button1_Click(object sender, EventArgs e)
Type t = typeof(People);
richTextBox1.AppendText("\r"+"----------------Method------------------");
MethodInfo[] methods = t.GetMethods();
foreach (MethodInfo method in methods)
richTextBox1.AppendText('\r' + "Method:" + method);
richTextBox1.AppendText(string.Format('\r' + "method name:{0} returnValue:{1}", method.Name, method.ReturnType));
ParameterInfo[] pi = method.GetParameters();
foreach (ParameterInfo pinfo in pi)
richTextBox1.AppendText(string.Format("\r" + "Parameter name:{0} Type:{1}",pinfo.Name,pinfo.ParameterType));
richTextBox1.AppendText("\n");
richTextBox1.AppendText("\r"+"---------------Field-------------------");
FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (FieldInfo field in fields)
richTextBox1.AppendText("\r"+"Field:" + field);
richTextBox1.AppendText(string.Format("\r" + "Field name:{0}
type:{1}" , field.Name,field.FieldType));
richTextBox1.AppendText("\r"+"--------------Member--------------------");
MemberInfo[] members = t.GetMembers();
foreach (MemberInfo member in members)
richTextBox1.AppendText("\r"+"Member:" + member);
richTextBox1.AppendText("\r"+"--------------Property--------------------");
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo property in properties)
richTextBox1.AppendText("\r"+"Property:" + property);
richTextBox1.AppendText("\r"+"--------------Constructor--------------------");
ConstructorInfo[] constructors = t.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (ConstructorInfo constructor in constructors)
richTextBox1.AppendText("\r"+"Constructor:" + constructor);
基础类定义
public class People //类名
public string Sex
set { sex = }
public static string Name
get { return People. }
set { People.name = }
private People() //构造函数
public static string GetName()
if (string.IsNullOrEmpty(name))
name = "my name";
执行结果如下:
----------------Method------------------Method:System.String get_Sex()method name:get_Sex returnValue:System.String
Method:Void set_Sex(System.String)method name:set_Sex returnValue:System.VoidParameter name:value Type:System.String
Method:System.String get_Name()method name:get_Name returnValue:System.String
Method:Void set_Name(System.String)method name:set_Name returnValue:System.VoidParameter name:value Type:System.String
Method:System.String GetName()method name:GetName returnValue:System.String
Method:System.String ToString()method name:ToString returnValue:System.String
Method:Boolean Equals(System.Object)method name:Equals returnValue:System.BooleanParameter name:obj Type:System.Object
Method:Int32 GetHashCode()method name:GetHashCode returnValue:System.Int32
Method:System.Type GetType()method name:GetType returnValue:System.Type
---------------Field-------------------Field:System.String sexField name:sex
type:System.StringField:System.String nameField name:name
type:System.String--------------Member--------------------Member:System.String get_Sex()Member:Void set_Sex(System.String)Member:System.String get_Name()Member:Void set_Name(System.String)Member:System.String GetName()Member:System.String ToString()Member:Boolean Equals(System.Object)Member:Int32 GetHashCode()Member:System.Type GetType()Member:System.String SexMember:System.String Name--------------Property--------------------Property:System.String SexProperty:System.String Name--------------Constructor--------------------Constructor:Void .ctor()& & & & & & & &本博客所有文章分类的总目录:&
开源Math.NET基础数学类库使用总目录:
  在数值计算的需求中,数值积分也是比较常见的一个。我们也知道像Matlab,Mathematics等软件的积分求解功能非常高大上,不仅能求解定积分,还能求解不定积分,甚至多重积分等等。而Math.NET这个组件没有如此高级的功能,目前也只提供了比较件的闭区间上的定积分求解功能。今天就一起来看看,因为不定积分涉及到符号计算,因此其背后的原理和实现要复杂得多。就连Matlab这种软件暂时也不支持混编编程求解符号计算相关的功能。
  如果本文资源或者显示有问题,请参考&:&
  很多人可能已经淡忘了定积分的概念,当然需要用到的朋友看到这里,也基本不用看本段的内容,比较简单,高等数学已经是10多年前学过的东西了,虽然以前很精通,现在也只能凭印象理解和网络来对这个概念稍微进行整理,可能有些不完整或小错误,还请谅解。
  数学定义:如果函数f(x)在区间[a,b]上连续,用分点xi将区间[a,b]分为n 个小区间,在每个小区间[xi-1,xi]上任取一点ri(i=1,2,3&,n) ,作和式f(r1)+...+f(rn) ,当n趋于无穷大时,上述和式无限趋近于某个常数A,这个常数叫做y=f(x) 在区间上的定积分. 记作/ab f(x) dx 即 /ab f(x) dx =limn&00 [f(r1)+...+f(rn)], 这里,a 与 b叫做积分下限与积分上限,区间[a,b] 叫做积分区间,函数f(x) 叫做被积函数,x 叫做积分变量,f(x)dx 叫做被积式。
  几何定义:可以理解为在 Oxy坐标平面上,由曲线y=f(x)与直线x=a,x=b以及x轴围成的曲边梯形的面积值(一种确定的实数值)。
详细的可以参考以下链接:
& & & & :
2.Math.NET关于定积分的实现
&  Math.NET中对定积分的实现都在MathNet.Numerics.Integration命名空间以及Integrate.cs中,Integrate静态类其实是对Integration命名空间下几个近似积分方法的实现。Math.NET定积分的近似求解主要是用到了&梯形法则&,详细的内容可以参考以下:,其原理非常简单。这里我们只介绍经常用到的Integrate静态类的实现,很简单,其他内部实现过程可以查源码:
2 using MathNet.Numerics.I
4 namespace MathNet.Numerics
/// &summary&
/// 数值积分类
/// &/summary&
public static class Integrate
/// &summary&
/// 近似解析光滑函数在闭区间上的定积分
/// &/summary&
/// &param name="f"&The analytic smooth function to integrate.&/param&
/// &param name="intervalBegin"&Where the interval starts, inclusive and finite.&/param&
/// &param name="intervalEnd"&Where the interval stops, inclusive and finite.&/param&
/// &param name="targetAbsoluteError"&The expected relative accuracy of the approximation.&/param&
/// &returns&Approximation of the finite integral in the given interval.&/returns&
public static double OnClosedInterval(Func&double, double& f, double intervalBegin, double intervalEnd, double targetAbsoluteError)
return DoubleExponentialTransformation.Integrate(f, intervalBegin, intervalEnd, targetAbsoluteError);
/// &summary&
近似解析光滑函数在闭区间上的定积分
/// &/summary&
/// &param name="f"&The analytic smooth function to integrate.&/param&
/// &param name="intervalBegin"&Where the interval starts, inclusive and finite.&/param&
/// &param name="intervalEnd"&Where the interval stops, inclusive and finite.&/param&
/// &returns&Approximation of the finite integral in the given interval.&/returns&
public static double OnClosedInterval(Func&double, double& f, double intervalBegin, double intervalEnd)
return DoubleExponentialTransformation.Integrate(f, intervalBegin, intervalEnd, 1e-8);
  下面的例子就是直接调用该类进行的。  
3.C#使用Math.NET求解定积分的例子
&  使用比较简单,直接看源码:
1 // 1. Integrate x*x on interval [0, 10]
2 Console.WriteLine(@"1.函数 x*x 在闭区间 [0, 10] 上的积分");
3 var result = Integrate.OnClosedInterval(x =& x * x, 0, 10);
4 Console.WriteLine(result);
5 Console.WriteLine();
7 // 2. Integrate 1/(x^3 + 1) on interval [0, 1]
8 Console.WriteLine(@"2.函数 1/(x^3 + 1) 在闭区间 [0, 1] 上的积分");
9 result = Integrate.OnClosedInterval(x =& 1 / (Math.Pow(x, 3) + 1), 0, 1);
10 Console.WriteLine(result);
11 Console.WriteLine();
13 // 3. Integrate f(x) = exp(-x/5) (2 + sin(2 * x)) on [0, 10]
14 Console.WriteLine(@"3.函数 f(x) = exp(-x/5) (2 + sin(2 * x)) 在 [0, 10]上的积分");
15 result = Integrate.OnClosedInterval(x =& Math.Exp(-x / 5) * (2 + Math.Sin(2 * x)), 0, 100);
16 Console.WriteLine(result);
17 Console.WriteLine();
19 // 4. Integrate target function with absolute error = 1E-4
20 Console.WriteLine(@"4. 对目标函数进行积分,绝对误差= 1E-4 ,区间 [0, 10]");
21 Console.WriteLine(@"public static double TargetFunctionA(double x)
23 return Math.Exp(-x / 5) * (2 + Math.Sin(2 * x));
25 result = Integrate.OnClosedInterval(TargetFunctionA, 0, 100, 1e-4);
26 Console.WriteLine(result);
27 Console.WriteLine();
参数主要有3个:函数,积分下限,积分上限,其他的就是附带一个绝对误差了,看看运行结果:
1.函数 x*x 在闭区间 [0, 10] 上的积分
2.函数 1/(x^3 + 1) 在闭区间 [0, 1] 上的积分
3.函数 f(x) = exp(-x/5) (2 + sin(2 * x)) 在 [0, 10]上的积分
4. 对目标函数进行积分,绝对误差= 1E-4 ,区间 [0, 10]
public static double TargetFunctionA(double x)
return Math.Exp(-x / 5) * (2 + Math.Sin(2 * x));
  源码下载:
  如果本文资源或者显示有问题,请参考&:
阅读(...) 评论()C#语言程序必须包含并且只能包含一个的方法(函数)是什么?_百度知道
C#语言程序必须包含并且只能包含一个的方法(函数)是什么?
我有更好的答案
入口函数,也称为:主函数。Main()方法。如:public class Program{
static void Main(){
为您推荐:
其他类似问题
函数的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。10:06 提问
c#的math类包含所有的函数吗?就比如说求开方这个函数
我要用c# 编写一个比较有多功能的计算器但是就是不知道math里面包含这些函数吗?可以直接调用吗?还是要自己动手写?
按赞数排序
不知道你说的所有函数是什么意思,因为函数本身就是有无穷多个的。只能说常见的函数,以及通过它们的组合得到的常用的函数.NET都包括。
Math.Sqrt可以实现。
参考MSDN:
基本的数学计算是有的,如果复杂,你就需要用这些函数组合运算
math类里面包含的有数学运算函数,可以直接调用!
可以上这个百度文库看看
常见的函数都应该包含的
Math.abs() 计算绝对值。
Math.acos() 计算反余弦值。
Math.asin() 计算反正弦值。
Math.atan() 计算反正切值。
Math.atan2() 计算从x 坐标轴到点的角度。
Math.ceil() 将数字向上舍入为最接近的整数。
Math.cos() 计算余弦值。
Math.exp() 计算指数值。
Math.floor() 将数字向下舍入为最接近的整数。
Math.log() 计算自然对数。
Math.max() 返回两个整数中较大的一个。
Math.min() 返回两个整数中较小的一个。
Math.pow() 计算x 的y 次方。
Math.random() 返回一个0.0 与1.0 之间的伪随机数。
Math.round() 四舍五入为最接近的整数。
Math.sin() 计算正弦值。
Math.sqrt() 计算平方根。
Math.tan() 计算正切值。
Math.E 欧拉(Euler) 常数,自然对数的底(大约为2.718)。
Math.LN2 2 的自然对数(大约为0.693)。
Math.LOG2E e 的以2 为底的对数(大约为1.442)。
Math.LN2 10 的自然对数(大约为2.302)。
Math.LOG10E e 的以10 为底的对数(大约为0.434)。
Math.PI 一个圆的周长与其直径的比值(大约为3.14159)。
Math.SQRT1_2 1/2 的平方根的倒数(大约为0.707)。
Math.SQRT2 2 的平方根(大约为1.414)。
基本上常用的都有,Math.sqrt()这就是求平方根的
可以试试用这个开源的包Math.NET:
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐2007年12月 .NET技术大版内专家分月排行榜第一
2007年10月 .NET技术大版内专家分月排行榜第二
匿名用户不能发表回复!|}

我要回帖

更多关于 php math函数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信