Open source math.net basic Math class library using C # for numerical integration

Source: Internet
Author: User
Tags sin

Original: "Original" open source math.net basic Math Library using C # for numerical integration

Total contents of this blog article category: http://www.cnblogs.com/asxinyu/p/4288836.html

Open Source math.net basic Math Class library use total directory: http://www.cnblogs.com/asxinyu/p/4329737.html

Objective

In the demand of numerical calculation, the numerical integral is also a more common one. We also know that the integral solution function of software such as Matlab,mathematics is very tall, not only can solve definite integral, but also can solve indefinite integral, even multiple integrals and so on. The Math.net component does not have such a high level of functionality, and currently only provides a definite integral solution on the closed interval of the comparator. Take a look today, because indefinite integrals involve symbolic computations, so the rationale behind them is much more complex. Even the MATLAB software temporarily does not support mixed programming to solve symbolic computation-related functions.

If there is a problem with the resource or display in this article, please refer to the original address: http://www.cnblogs.com/asxinyu/p/4301017.html

1. Definite integral

Many people may have forgotten the concept of definite integral, of course, need to use friends to see here, but also basically do not see this paragraph of the content, relatively simple, advanced mathematics has been more than 10 years ago learned things, although very proficient, now can only be based on the impression of understanding and network to the concept of a slightly organized, There may be some incomplete or minor errors, please understand.

Mathematical definition: If the function f (x) is continuous on the interval [a, b], the interval [a, b] is divided into n small intervals by the Point XI, in each small interval [xi-1,xi] takes a little Ri (i=1,2,3 ", N), and the type F (R1) +...+f (RN), when n tends to infinity, The above and the infinite approach to a constant A, this constant is called y=f (x) in the interval of the definite integral. Recorded as/ab f (x) dx is/ab f (x) dx =limn>00 [F (R1) +...+f (RN)], here, A and B are called the integral lower bound and integral upper bound, the interval [a] is called the integral interval, the function f (x) is called the integrand, X is called the integral variable, f (x) d X is called an integrand.

Geometric definition: It can be understood as the area value (a definite real value) of the curved edge trapezoid formed by the curve y=f (x) and the line x=a,x=b and the x-axis on the oxy coordinate plane.

For details, refer to the following links:

Calculation formula and properties of definite integral: http://www.shuxuecheng.com/gaosuzk/content/lljx/wzja/5/5-2.htm

2.math.net on the realization of definite integral

The realization of definite integral in math.net is in MathNet.Numerics.Integration namespace and Integrate.cs, integrate static class is actually the realization of several approximate integral methods under integration namespace. The approximate solution of math.net definite integral is to use the "trapezoid law", the detailed content can refer to the following: link, its principle is very simple. Here we only introduce commonly used integrate static class implementation, very simple, other internal implementation process can check the source code:

1 usingSystem;2 usingMathNet.Numerics.Integration;3 4 namespaceMathnet.numerics5 {6     /// <summary>7     ///Numerical Integration class8     /// </summary>9      Public Static classIntegrateTen     { One         /// <summary>       A         ///definite integral of approximate analytic smooth function on closed interval -         /// </summary> -         /// <param name= "F" >The analytic smooth function to integrate.</param> the         /// <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 DoubleOnclosedinterval (func<Double,Double> F,DoubleIntervalbegin,DoubleIntervalend,Doubletargetabsoluteerror) -         { +             returndoubleexponentialtransformation.integrate (F, Intervalbegin, Intervalend, targetabsoluteerror); A         } at  -         /// <summary>    -         ///definite integral of approximate analytic smooth function on closed interval -         /// </summary> -         /// <param name= "F" >The analytic smooth function to integrate.</param> -         /// <param name= "Intervalbegin" >Where The interval starts, inclusive and finite.</param> in         /// <param name= "Intervalend" >Where The interval stops, inclusive and finite.</param> -         /// <returns>approximation of the finite integral in the given interval.</returns> to          Public Static DoubleOnclosedinterval (func<Double,Double> F,DoubleIntervalbegin,Doubleintervalend) +         { -             returnDoubleexponentialtransformation.integrate (f, Intervalbegin, Intervalend, 1e-8); the         } *     } $}

The following example is a direct call to this class.

3.c# example of using math.net to solve definite integrals

Easy to use, directly see the source code:

1 //1. Integrate x*x on interval [0, ten]2Console.WriteLine (@"1. Function x*x integral on closed interval [0, 10]");3 varresult = Integrate.onclosedinterval (x = = x * x,0,Ten);4 Console.WriteLine (result);5 Console.WriteLine ();6 7 //2. Integrate 1/(X^3 + 1) on interval [0, 1]8Console.WriteLine (@"2. Function 1/(x^3 + 1) integral on closed interval [0, 1]");9result = Integrate.onclosedinterval (x = =1/(Math.pow (x,3) +1),0,1);Ten Console.WriteLine (result); One Console.WriteLine (); A  - //3. Integrate f (x) = exp (-X/5) (2 + sin (2 * x)) on [0] -Console.WriteLine (@"3. function f (x) = exp (-X/5) (2 + sin (2 * x)) on [0, 10] integral"); theresult = Integrate.onclosedinterval (x = Math.exp (-×/5) * (2+ Math.sin (2* x)),0, -); - Console.WriteLine (result); - Console.WriteLine (); -  + //4. Integrate target function with absolute error = 1E-4 -Console.WriteLine (@"4. Integral to the objective function, absolute error = 1E-4, interval [0, ten]"); +Console.WriteLine (@"Public static Double Targetfunctiona (double x) A { at return Math.exp (-X/5) * (2 + math.sin (2 * x)); - }"); -result = Integrate.onclosedinterval (Targetfunctiona,0, -, 1e-4); - Console.WriteLine (result); -Console.WriteLine ();

There are 3 main parameters: function, lower limit of integral, integral upper limit, the other is to attach an absolute error, to see the results of the operation:

1. function x*x in closed interval [0,Ten] on the points333.3333333333322. function1/(x^3+1) in the closed interval [0,1] on the points0.8356488482647023. function f (x) = exp (-x/5) (2+ Sin (2* x)) in the [0,Ten] on the points10.49504948392724. Integral to the objective function, absolute error = 1e-4Interval0,Ten] Public Static DoubleTargetfunctiona (Doublex) {    returnMath.exp (-X/5) * (2+ Math.sin (2*x));}10.4950494839276
4. Resources

SOURCE Download: http://www.cnblogs.com/asxinyu/p/4264638.html

If there is a problem with the resource or display in this article, please refer to the original address: http://www.cnblogs.com/asxinyu/p/4301017.html

Open source math.net basic Math class library using C # for numerical integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.