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("120 3 6"); start.print("start: m,G,A =",file:Error); p=start.copy(); Error.WriteLine("\n--- qnewton.sr1 ---"); ncalls=0; p=qnewton.sr1(chi2,p,acc:1e-3); double m=p[0]; double G=p[1]; double 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)}"); p=start.copy(); Error.WriteLine("\n--- simplex ---"); ncalls=0; p=simplex.downhill(chi2,p,step:0.5,delta:1e-3); 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"); p=start.copy(); Error.WriteLine("\n--- swarm ---"); ncalls=0; p=swarm.run(chi2,start:p,step:0.5,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"); }//Main }//main