// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using MathNet.Numerics.LinearAlgebra; namespace E { public class Program { private static void Solve(double[] f, out double[] b, double[] x, double[] y) { Vector one = Vector.Ones(x.Length); Vector x2 = Vector.Create(x); Vector y2 = Vector.Create(y); Matrix xy3 = Matrix.CreateFromColumns(new List { x2, y2, one }); Vector f2 = Vector.Create(f); Matrix f3 = Matrix.CreateFromColumns(new List { f2 }); Matrix b3 = xy3.Solve(f3); Vector b2 = b3.GetColumnVector(0); b = b2.CopyToArray(); } public static void Main(string[] args) { double[] fx = { 130.816, 196.860, 113.987 }; double[] fy = { 266.000, 256.000, 175.000 }; double[] x = { 173.0, 275.5, 139.5 }; double[] y = { 12.5, 28.5, 153-0 }; double[] b; Solve(fx, out b, x, y); Console.WriteLine("fx = " + b[0] + "*x + " + b[1] + "*y + " + b[2]); Solve(fy, out b, x, y); Console.WriteLine("fy = " + b[0] + "*x + " + b[1] + "*y + " + b[2]); } } }