using System; using static System.Math; using static System.Console; static class main{ static double pow(this double x,int n){return Pow(x,n);} static double pow(this double x,double n){return Pow(x,n);} static System.Collections.Generic.List energy,signal,error; static int ncalls=0; static double chi2(vector x){ ncalls++; double m = x[0]; double G = x[1]; double A = x[2]; double sum=0; for(int i=0;i(); signal = new System.Collections.Generic.List(); error = new System.Collections.Generic.List(); System.IO.TextReader stdin = Console.In; char[] separators = new char[] {' '}; do{ string s=stdin.ReadLine(); if(s==null)break; string[] w=s.Split(separators,StringSplitOptions.RemoveEmptyEntries); energy.Add(double.Parse(w[0])); signal.Add(double.Parse(w[1])); error.Add (double.Parse(w[2])); }while(true); vector p,start=new vector("123 3 6"); double m, G, A; int nsteps; p=start.copy(); Error.WriteLine("\n--- qnewton.sr1 ---"); ncalls=0; nsteps=qnewton.min(chi2,ref p,acc:1e-3,method:"sr1"); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls} nsteps={nsteps}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); p=start.copy(); Error.WriteLine("\n--- qnewton.broyden ---"); ncalls=0; nsteps=qnewton.min(chi2,ref p,acc:1e-3,method:"broyden"); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls} nsteps={nsteps}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); p=start.copy(); Error.WriteLine("\n--- simplex ---"); ncalls=0; nsteps=simplex.downhill(chi2,ref p,step:0.5,sizegoal:1e-3); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls} nsteps={nsteps}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); Error.WriteLine("\n--- prernd ---"); vector a=new vector(110,1,1); vector b=new vector(130,5,9); ncalls=0; p=prernd.run(chi2,a,b,seconds:1); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); Error.WriteLine("\n--- rndstart ---"); ncalls=0; p=rndstart.run(chi2,a,b,seconds:1); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); Error.WriteLine("\n--- swarm ---"); ncalls=0; p=swarm.run(chi2,a,b,seconds:1); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); Error.WriteLine("\n--- bbpso ---"); ncalls=0; p=bbpso.run(chi2,a,b,seconds:1); m=p[0]; G=p[1]; A=p[2]; Error.Write($"ncalls ={ncalls}\n"); Error.Write($"mass ={m}\n"); Error.Write($"Gamma ={G}\n"); Error.Write($"Sqrt(chi^2/n)={Sqrt(chi2(p)/energy.Count)}\n"); for(double e=energy[0];e<=energy[energy.Count-1];e+=1.0/16) WriteLine($"{e} {A*breitwigner(e,m,G)}"); }//Main }//main