using System; using static System.Math; using static System.Console; class main{ static void Main(){ vector c = new vector("1 1"); matrix A = new matrix("1 0;0 1"); int ncalls=0; Func f = (z)=>{ncalls++;return (A*(z-c)).map(t=>t*t);}; /* Func f = delegate(vector z){ ncalls++; vector r=new vector(2); double x=z[0],y=z[1],b=10; r[0]=2*(1-x)*(-1)+b*2*(y-x*x)*(-1)*2*x; r[1]=b*2*(y-x*x); return r; }; */ vector p = new vector("2 2"); p.print("broyden: p="); vector root = roots.broyden(f,p,eps:1e-4); root.print("root="); f(root).print("f(root)="); WriteLine($"ncalls={ncalls}"); p.print("newton: p="); root = roots.newton(f,p,eps:1e-4); root.print("root="); f(root).print("f(root)="); WriteLine($"ncalls={ncalls}"); } }