public void runsimDrange(Vector v0, double deltafrom, double deltato, int numsteps, string filename) { double[] deltalist = new double[numsteps]; double h = (deltafrom - deltato) / numsteps; PredPrey p = new PredPrey(); //FileStream f = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); //StreamWriter streamWriter = new StreamWriter(filename); Vector v = new Vector(); Vector vloop = new Vector(); v = v0; for (int i = 0; i < numsteps; i++) { deltalist[i] = deltafrom + (i + 1) * h; Vector deltav = new Vector(deltalist); for (int s = 0; s < nreps; s++) { for (int t = 0; t < nsettle; t++) { StreamWriter streamWriter = new StreamWriter(filename); streamWriter.Write(deltalist[i]); streamWriter.Write(" , "); vloop = fv.Evaluate(v); v = v + vloop; streamWriter.Close(); p.run1sim(v, filename); } } } }
static void Main(string[] args) { FunctionVector fv = new FunctionVector(3); fv[0] = x => x[0] + x[1] + x[2]; fv[1] = x => x[0] + x[1] * x[2]; fv[2] = x => x[0] * x[1] + x[2]; Vector tmp = fv.Evaluate(new Vector(new double[] { 1, -1, 3 })); Console.WriteLine("tmp = {0}", tmp); double d = fv[0].Invoke(tmp); Console.WriteLine(d); Console.WriteLine("Start Step 1"); //predator prey simulation //(1) single value PredPrey p = new PredPrey(); p.Nsettle = 1000; Vector v0 = new Vector(new double[] { 0.83, 0.55 }); p.Delta = 1.38; p.run1sim(v0, "C:\\Users\\114113597\\Downloads\\outfile.csv"); Console.ReadKey(); Console.WriteLine("Start Step 2"); //(2) produce bifurcation plot data use default values p.runsimDrange(v0, 1.26, 1.4, 1000, "C:\\Users\\114113597\\Downloads\\outfile1.csv"); Console.ReadKey(); Console.WriteLine("Start Step 3"); //(3) produce second bifurcation plot p.R = 3; p.B = 3.5; p.D = 2; v0 = new Vector(new double[] { 0.57, 0.37 }); p.runsimDrange(v0, 0.5, 0.95, 1000, "C:\\Users\\114113597\\Downloads\\outfile2.csv"); Console.ReadKey(); Console.WriteLine("Finished!!"); }