I need some free numerical integration code

  • Thread starter Thread starter not_a_commie
  • Start date Start date
N

not_a_commie

Is anyone aware of a free .NET numerical methods library that would
integration? Thanks.
 
Unfortunately the website for NMath says that numeric integration is
not yet available.
 
not_a_commie said:
Is anyone aware of a free .NET numerical methods library that would
integration?

See code below for inspiration.

Arne

==========================================

using System;

namespace E
{
public class NumericalIntegration
{
public delegate double F(double x);
public static double Simpson(F f, double a, double b)
{
int n = 10000;
double h = (b - a) / n;
double sum = 0;
sum += f(a);
for(int i = 1; i <= n/2; i++) sum += 4*f(a + (2*i - 1)*h);
for(int i = 1; i < n/2-1; i++) sum += 2*f(a + 2*i*h);
sum += f(b);
return h/3*sum;
}
}
public class Program
{
public static double Circle(double x)
{
return Math.Sqrt(1 - x * x);
}
public static void Main(string[] args)
{
Console.WriteLine(Math.PI/2);
Console.WriteLine(NumericalIntegration.Simpson(Circle, -1, 1));
Console.ReadLine();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top