您的位置:首页 > 编程语言 > C#

开源Math.NET基础数学类库使用(08)C#进行数值积分

2015-03-05 21:43 931 查看
前言

  在数值计算的需求中,数值积分也是比较常见的一个。我们也知道像Matlab,Mathematics等软件的积分求解功能非常高大上,不仅能求解定积分,还能求解不定积分,甚至多重积分等等。而Math.NET这个组件没有如此高级的功能,目前也只提供了比较件的闭区间上的定积分求解功能。今天就一起来看看,因为不定积分涉及到符号计算,因此其背后的原理和实现要复杂得多。就连Matlab这种软件暂时也不支持混编编程求解符号计算相关的功能。

1.定积分

  很多人可能已经淡忘了定积分的概念,当然需要用到的朋友看到这里,也基本不用看本段的内容,比较简单,高等数学已经是10多年前学过的东西了,虽然以前很精通,现在也只能凭印象理解和网络来对
91aa
这个概念稍微进行整理,可能有些不完整或小错误,还请谅解。

  数学定义:如果函数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轴围成的曲边梯形的面积值(一种确定的实数值)。

using System;
2 using MathNet.Numerics.Integration;
3
4 namespace MathNet.Numerics
5 {
6 /// <summary>
7 /// 数值积分类
8 /// </summary>
9 public static class Integrate
10 {
11 /// <summary>
12 /// 近似解析光滑函数在闭区间上的定积分
13 /// </summary>
14 /// <param name="f">The analytic smooth function to integrate.</param>
15 /// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param>
16 /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
17 /// <param name="targetAbsoluteError">The expected relative accuracy of the approximation.</param>
18 /// <returns>Approximation of the finite integral in the given interval.</returns>
19 public static double OnClosedInterval(Func<double, double> f, double intervalBegin, double intervalEnd, double targetAbsoluteError)
20 {
21 return DoubleExponentialTransformation.Integrate(f, intervalBegin, intervalEnd, targetAbsoluteError);
22 }
23
24 /// <summary>
25 /// 近似解析光滑函数在闭区间上的定积分
26 /// </summary>
27 /// <param name="f">The analytic smooth function to integrate.</param>
28 /// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param>
29 /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
30 /// <returns>Approximation of the finite integral in the given interval.</returns>
31 public static double OnClosedInterval(Func<double, double> f, double intervalBegin, double intervalEnd)
32 {
33 return DoubleExponentialTransformation.Integrate(f, intervalBegin, intervalEnd, 1e-8);
34 }
35 }
36 }
复制代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐