public static List <Heun> heun2(string expresion, string solucionAnalitica, double a, double b, double h, double x0, double y0) { List <Heun> listaPuntoMedio = new List <Heun>(); Heun heun = null; int iteracion = 0; double xi = x0; double k1 = 0; double y0i = 0; double k2 = 0; double yHeun = y0; double yt = 0; double errorGlobal = 0; while (xi < b) { if (iteracion == 0) { xi = x0; yHeun = y0; heun = new Heun(iteracion, xi, k1, y0i, k2, yHeun, yt, errorGlobal); listaPuntoMedio.Add(heun); } else { k1 = calcularK(expresion, xi, yHeun);// revisar calcular despues y0i = yHeun + k1 * h; xi += h; k2 = calcularK(expresion, xi, y0i); yHeun = yHeun + (k1 + k2) / 2 * h; yt = evaluarFuncion(solucionAnalitica, xi); errorGlobal = yt - yHeun; heun = new Heun(iteracion, xi, k1, y0i, k2, yHeun, yt, errorGlobal); listaPuntoMedio.Add(heun); } iteracion += 1; } return(listaPuntoMedio); }
private FdmBase GetFdm(ISde sde) { Console.WriteLine("Create FDM"); Console.WriteLine("1. Euler, 2. Extrapolated Euler, 3. Milstein, 4. Predictor-Corrector (PC),"); Console.WriteLine("5. PC adjusted, 6. PC midpoint, 7. Exact, 8. Discrete Milstein,"); Console.WriteLine("9. Karhunen Loeve, 10. Platen 1.0 strong scheme, 11. Heun"); Console.WriteLine("12. Derivative Free, 13. FRKI (Runge Kutta), 14. Heun2: "); int c = Convert.ToInt32(Console.ReadLine()); FdmBase fdm; int NT = 500; Console.Write("How many NT? "); NT = Convert.ToInt32(Console.ReadLine()); double a, b; switch (c) { case 1: fdm = new EulerFdm(sde, NT); break; case 2: fdm = new ExtrapolatedEulerFdm(sde, NT); break; case 3: fdm = new MilsteinFdm(sde, NT); break; case 4: a = 0.5; b = 0.5; fdm = new PredictorCorrectorFdm(sde, NT, a, b); break; case 5: a = 0.5; b = 0.5; fdm = new ModifiedPredictorCorrectorFdm(sde, NT, a, b); break; case 6: a = 0.5; b = 0.5; fdm = new MidpointPredictorCorrectorFdm(sde, NT, a, b); break; case 7: fdm = new ExactFdm(sde, NT); break; case 8: fdm = new DiscreteMilsteinFdm(sde, NT); break; case 9: int N = 100; // Series truncation value // IRng rng = new PolarMarsagliaSitmo(); // fdm = new KarhunenLoeve(sde, NT, N, rng); fdm = new Platen_01_Explicit(sde, NT); break; case 10: fdm = new Platen_01_Explicit(sde, NT); break; case 11: fdm = new Heun(sde, NT); break; case 12: fdm = new DerivativeFree(sde, NT); break; case 13: fdm = new FRKI(sde, NT); break; case 14: fdm = new Heun2(sde, NT); break; default: fdm = new ExtrapolatedEulerFdm(sde, NT); break; } return(fdm); }
private FdmBase GetFdm(ISde sde) { Console.WriteLine("Create FDM"); Console.WriteLine("1. Euler, 2. Extrapolated Euler, 3. Milstein, 4. Predictor-Corrector (PC),"); Console.WriteLine("5. PC adjusted, 6. PC midpoint, 7. Exact, 8. Discrete Milstein,"); Console.WriteLine("9. Platen 1.0 strong scheme, 10. Platen 1.0 strong scheme, 11. Heun"); Console.WriteLine("12. Derivative Free, 13. FRKI (Runge Kutta), 14. Heun2, 15. Fitted PC: "); int c = Convert.ToInt32(Console.ReadLine()); FdmBase fdm; int NT; Console.Write("How many NT? "); NT = Convert.ToInt32(Console.ReadLine()); double a, b; switch (c) { case 1: fdm = new EulerFdm(sde, NT); break; case 2: fdm = null; // new ExtrapolatedEulerFdm(sde, NT); break; case 3: fdm = new MilsteinFdm(sde, NT); break; case 4: a = 0.5; b = 0.5; fdm = new PredictorCorrectorFdm(sde, NT, a, b); break; case 5: a = 0.5; b = 0.5; fdm = new ModifiedPredictorCorrectorFdm(sde, NT, a, b); break; case 6: a = 0.5; b = 0.5; fdm = new MidpointPredictorCorrectorFdm(sde, NT, a, b); break; case 7: fdm = new ExactFdm(sde, NT, IC, v, r); break; case 8: fdm = new DiscreteMilsteinFdm(sde, NT); break; case 9: fdm = new Platen_01_Explicit(sde, NT); break; case 10: fdm = new Platen_01_Explicit(sde, NT); break; case 11: fdm = new Heun(sde, NT); break; case 12: fdm = new DerivativeFree(sde, NT); break; case 13: fdm = new FRKI(sde, NT); break; case 14: fdm = new Heun2(sde, NT); break; case 15: a = 0.5; b = 0.5; fdm = new FittedMidpointPredictorCorrectorFdm(sde, NT, a, b); break; default: fdm = null; // new ExtrapolatedEulerFdm(sde, NT); break; } return(fdm); }