XLPack API: C# example programs

How to call XLPack from C#

To call XLPack from C#, it is necessary to use DLL directly.
DLL interface program xlpack.cs is included in SDK, so that the calling program can easily call XLPack like built-in functions without considering the detail DLL interface by declaring “using static XLPack;”.
Two dimensional array is used for the coefficient matrix a. One dimensional array is used for the right hand matrix b.

C# example program (Example (1))

using System;
using System.IO;
using static XLPack;

public class Test
{

static void Test_dgesv()
{
    const int n = 3;
    double[,] a =
        {{ 0.2, -0.32, -0.8 },
         { -0.11, 0.81, -0.92 },
         { -0.93, 0.37, -0.29 }};
    double[] b = { -0.3727, 0.4319, -1.4247 };
    int[] ipiv = new int[n];
    int info;

    dgesv(n, a, ipiv, b, out info);
    Console.Write("x = {0}  {1}  {2}\n", b[0], b[1], b[2]);
    Console.Write("info = {0}\n", info);
}

public static int Main(string[] args)
{
    Test_dgesv();
    return 0;
}

}

Result

x = 0.86  0.64  0.51
info = 0

C# example program (Example (2))

In Example (2), the integral of f(x) is computed using qk15. qk15 requires the external function defining f(x). It can be coded in C# and qk15 will call it when necessary.

using System;
using System.IO;
using static XLPack;

public class Test
{

static double f_qk15(double x)
{
	return 1/(1 + x*x);
}

static void Test_qk15()
{
	double a, b, result, abserr;

	a = 0; b = 4;
	qk15(f_qk15, a, b, out result, out abserr);
	Console.Write("result = {0}, abserr = {1}\n", result, abserr);
}

public static int Main(string[] args)
{
    Test_qk15();
    return 0;
}

}

Result

result = 1.32581766136379, abserr = 0.00148272394121622