public Differential_Equation() { table1 = new Table(); table2 = new Table(); table3 = new Table(); double h_0 = h * F(x_0, y_0); table1.Add(x_0, y_0, h_0); table2.Add(x_0, y_0, h_0); table3.Add(x_0, y_0, h_0); }
public void Euler(int left, int right, Table table, double factor) { for (int i = left; i < factor * right + 1; i++) euler_iter(i, ref table, factor); }
public void Adams(int left, int right, Table table) { for (int i = left; i < right + 1; i++) adams_iter(i, ref table); }
private void runge_kutti(int i, ref Table table) { double x_prev = table.X(i - 1); double y_prev = table.Y(i - 1); double k1 = h * F(x_prev, y_prev); double k2 = h * F(x_prev + h / 2.0, y_prev + k1 / 2.0); double k3 = h * F(x_prev + h / 2.0, y_prev + k2 / 2.0); double k4 = h * F(x_prev + h, y_prev + k3); double x_next = x_prev + h; double y_next = y_prev + (k1 + 2 * k2 + 2 * k3 + k4) / 6.0; double hi_next = h * F(x_next, y_next); table.Add(x_next, y_next, hi_next); }
private void euler_iter(int i, ref Table table, double factor) { double x_prev, x_next, y_prev, y_next, hi_prev, hi_next; double h = H / factor; x_prev = table.X(i - 1); y_prev = table.Y(i - 1); hi_prev = table.Hi(0, i - 1); x_next = x_prev + h; y_next = y_prev + hi_prev; hi_next = h * F(x_next, y_next); table.Add(x_next, y_next, hi_next); }
private void adams_iter(int i, ref Table table) { double x_prev = table.X(i - 1); double y_prev = table.Y(i - 1); double hi_prev = table.Hi(0, i - 1); double delta_1_hi = table.Hi(1, i - 2); double delta_2_hi = table.Hi(2, i - 3); double delta_3_hi = table.Hi(3, i - 4); double delta_4_hi = table.Hi(4, i - 5); double x_next = x_prev + h; double y_next = y_prev + hi_prev + delta_1_hi / 2.0 + 5.0 * delta_2_hi / 12.0 + 3.0 * delta_3_hi / 8.0 + 251.0 * delta_4_hi / 720.0; double hi_next = h * F(x_next, y_next); table.Add(x_next, y_next, hi_next); }
public void RungeKutti(int left, int right, Table table) { for (int i = left; i < right + 1; i++) runge_kutti(i, ref table); }