StapletonMathPackage 1.3.3

dotnet add package StapletonMathPackage --version 1.3.3
                    
NuGet\Install-Package StapletonMathPackage -Version 1.3.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StapletonMathPackage" Version="1.3.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StapletonMathPackage" Version="1.3.3" />
                    
Directory.Packages.props
<PackageReference Include="StapletonMathPackage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StapletonMathPackage --version 1.3.3
                    
#r "nuget: StapletonMathPackage, 1.3.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StapletonMathPackage@1.3.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StapletonMathPackage&version=1.3.3
                    
Install as a Cake Addin
#tool nuget:?package=StapletonMathPackage&version=1.3.3
                    
Install as a Cake Tool

StapletonMathPackage

NuGet

StapletonMathPackage is a C# numerical methods library providing tools for linear algebra, optimization, root-finding, interpolation, and ODE solving. It is pretty old, and I mostly started it as a wrapper around other math packages because I wanted to stick with double arrays in my program rather than specialized matrix classes. This version wraps around Math.Numerics for many of the linear algebra operations.

Licensed under the MIT License.


Features

Linear Algebra

  • Matrix and vector operations (MatrixMath, VectorMath)
  • Determinant, trace, inverse, transpose
  • Eigenvalues & eigenvectors (general & 3×3 symmetric closed form)
  • Gaussian elimination, LU, banded solvers
  • Utilities for stacking, extracting, reshaping, swapping rows/columns

Calculus

  • Numerical integration: trapezoid, Romberg
  • Double integration
  • Vector and matrix-valued integrands

Root Finding

  • Newton-Raphson solvers:
    • With Jacobian supplied
    • With numerical tangent
    • With local secant updates
    • With initial slope
  • Regula Falsi (False Position) method

Interpolation

  • Cubic spline interpolation with derivatives
  • Tridiagonal solver for spline coefficients

Optimization

  • Genetic Algorithm framework:
    • Chromosome representation
    • Mutation & perturbation
    • Tournament-based crossover & population evolution
    • Multicore evaluation via ThreadLocal<Random>

ODE System Solvers

  • Matrix exponential (Taylor, Padé, scaling & squaring)
  • Constant step matrix exponential integration
  • Variable coefficient systems
  • Non-homogeneous systems with forcing functions

Installation

Install via NuGet:

dotnet add package StapletonMathPackage

Or in Visual Studio:

PM> Install-Package StapletonMathPackage

Usage Examples

Matrix Operations

using RandomMath;

double[,] A = { { 1, 2 }, { 3, 4 } };
double[,] B = { { 5, 6 }, { 7, 8 } };

double[,] C = MatrixMath.Multiply(A, B);
double detA = MatrixMath.Determinant(A);

Cubic Spline Interpolation

using RandomMath.CubicSplineFit;

var xs = new double[] { 0, 1, 2, 3 };
var ys = new double[] { 0, 1, 0, 1 };

var spline = new CubicSplineFit(xs, ys);

double dy = 0, d2y = 0;
double yInterp = spline.Interpolate(1.5, ref dy, ref d2y);

Genetic Algorithm

using RandomMath.GeneticAlgorithm;

public class SphereFunction : IOptimize {
    public int nX => 3;
    public double Eval(double[] X) => X.Sum(x => x*x);
    public IOptimize DeepCopy() => new SphereFunction();
}

var ga = new GeneticAlgorithm(new SphereFunction());
ga.Run();
Console.WriteLine($"Best fitness: {ga.Best.Fitness}");

Newton-Raphson (Jacobian supplied)

using RandomMath.NewtonRaphson;

public class SimpleFunc : IMatrixFunctionAndDerivative {
    public double[] Eval(double[] X) => new[] { X[0]*X[0] - 2 };
    public double[,] DEval(double[] X) => new double[,] { { 2*X[0] } };
}

var solver = new NewtonRaphsonJacobian(
    new double[] { 0 },    // target y
    new double[] { 1.0 },  // initial guess
    new SimpleFunc(),
    1e-10, 50
);
solver.Solve();
Console.WriteLine($"Root ≈ {solver.X[0]}");

Matrix Exponential ODE Solve

using RandomMath.ODESystemSolver;

double[,] A = { { 0, 1 }, { -1, 0 } };
var mexp = new MatrixExponential(A, 1.0);
var expAx = mexp.Solve(1.0); // exp(A*1.0)

Documentation

  • All public APIs include XML comments visible in IntelliSense.
  • Example usage included in this README.
  • For advanced methods (ODE solvers, GA tuning), see source files in RandomMath.* namespaces.

Contributing

Contributions are welcome!
Please open an issue or submit a PR with improvements, bug fixes, or new numerical routines.

Guidelines:

  • Follow existing naming conventions.
  • Provide XML documentation for new public APIs.
  • Add unit tests where possible.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.3 17 8/23/2025
1.2.2 135 4/11/2025
1.2.1 176 4/10/2025
1.2.0 185 4/10/2025
1.1.6 138 9/19/2024
1.1.5 152 8/20/2024
1.1.4 141 6/30/2024
1.1.3 133 6/30/2024
1.1.2 121 6/11/2024
1.1.1 132 6/10/2024
1.1.0 133 6/10/2024
1.0.0 159 2/28/2024