C# algorithm for Numerical Analysis