Jun 3, 2011 at 8:29 AM
Edited Jun 3, 2011 at 1:39 PM

Hello,
I originally posted that I was having problems getting the Integrate function to compile or run for me. I have since discovered my problem and though I may as well enter my simple example on here.
Would anyone be so kind as to showing me and integration example. Say, perhaps the integral of r squared between 0 and 1?
I've had a go but I can't work out from the tool tip or documentation of what it expects. My useless attempt is pasted below!
double result;
Function<double,double> area = new Function<double,double>(result);
Meta.Numerics.Functions.FunctionMath.Integrate(area, Interval.FromEndpoints(0, 1));
Many thanks and apologies if this has been asked or is available somwehere else. I have had a good look around and couldn't find anything.
The working example:
Interval interval = new Interval();
interval = Meta.Numerics.Interval.FromEndpoints(0.0, 1.0);
// Function A = pi r^2
int n = 2;
Function<double, double> raw = delegate(double x) {
return (Math.Pow(x, n));
};
double result;
result = FunctionMath.Integrate(raw, interval);
If anyone has a neater way of doing this, please feel free to update!


Coordinator
Jun 4, 2011 at 5:29 PM
Edited Jun 4, 2011 at 5:29 PM

Your code works fine, but there is a much more compact way to write it in C#.
double result = FunctionMath.Integrate(x => Math.Pow(x, 2), Interval.FromEndpoints(0.0, 1.0));
We should add this example to our tutorial documentation.

