using System;
using System.Collections.Generic;
using System.Text;
namespace ComportMath
{
class Laplace
{
public delegate double FunctionDelegate(double t);
static double[] V;
static double ln2;
const int DefaultStehfestN = 14;
static Laplace()
{
InitStehfest(DefaultStehfestN);
}
public static double Transform(FunctionDelegate F, double s)
{
const int DefaultIntegralN = 5000;
double du = 0.5 / (double)DefaultIntegralN;
double y = - F(0) / 2.0;
double u = 0;
double limit = 1.0 - 1e-10;
while (u < limit)
{
u += du;
y += 2.0 * Math.Pow(u, s - 1) * F(-Math.Log(u));
u += du;
y += Math.Pow(u, s - 1) * F(-Math.Log(u));
}
return 2.0 * y * du / 3.0;
}
public static double InverseTransform(FunctionDelegate f, double t)
{
double ln2t = ln2 / t;
double x = 0;
double y = 0;
for (int i = 0; i < V.Length; i++)
{
x += ln2t;
y += V[i] * f(x);
}
return ln2t * y;
}
public static double Factorial(int N)
{
double x = 1;
if (N > 1)
{
for (int i = 2; i <= N; i++)
x = i * x;
}
return x;
}