// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; public class Solv { // Newtons formel for iterativ lignings løsning private const double DELTA = 0.0000001; public delegate double FX(double x); public static double FindZero(FX f) { double x, xnext = 0; do { x = xnext; xnext = x - f(x) / ((f(x + DELTA) - f(x)) / DELTA); } while(Math.Abs(xnext - x) > DELTA); return xnext; } // simple trediegrads polynomium y=x^3+x-30 med en enkelt løsning x=3 public static double MyPoly(double x) { return x * x * x + x - 30; } // løs public static void Main(string[] args) { Console.WriteLine(Solv.FindZero(MyPoly)); } }