double[] funcVals = new double[1000]; double[] yVals = new double[1000]; double[] derVals = new double[1000]; double[] kouellAnswers = new double[1000]; double getNextByRunge(double x, double y, fnc funcForRunge, double h, int ind = 0) { double ni1 = funcForRunge(x, y, ind); double ni2 = funcForRunge(x + h / 2.0, y + h / 2.0 * ni1, ind); double ni3 = funcForRunge(x + h / 2.0, y + h / 2.0 * ni2, ind); double ni4 = funcForRunge(x + h, y + h * ni3, ind); double delta = h / 6.0 * (ni1 + 2 * ni2 + 2 * ni3 + ni4); y = y + delta; return y; } double funForFireMethod(double x, double y, int ind) { return Math.Sin(3 * x) + 2 * y + 3 * yVals[ind]; } double secFunFir(double x, double y, int ind) { return derVals[ind]; } void kouell(double a, double b, double y0, double y0d) { int ind = 0; double x = a; derVals[ind] = y0d; yVals[ind] = y0; funcVals[ind] = funForFireMethod(x, derVals[ind], ind); for (int i = 0; i < 2; ++i) { yVals[ind + 1] = getNextByRunge(x, yVals[ind], secFunFir, h, ind); derVals[ind + 1] = getNextByRunge(x, derVals[ind], funForFireMethod, h, ind); ind++; x += h; } while (x < b) { yVals[ind + 1] = getNextByRunge(x, yVals[ind], secFunFir, h, ind); derVals[ind + 1] = getNextByRunge(x, derVals[ind], funForFireMethod, h, ind); ind++; x += h; } } void fireMethod() { double ya = - 1000; double yb = 1000; double a = 1.2; double b = 1.9; int steps = (int)((b - a) / h + 0.5); double A = 5.1; double B = 1.4; double al1 = 2; double al2 = -1.7; double bet1 = -4; double bet2 = 5; while (yb - ya > 1e-8) { double cy = (ya + yb) / 2.0; double cyd = (5.1 - 2 * cy) / -1.7; kouell(a, b, cy, cyd); double yAtB = yVals[steps]; double derAtB = derVals[steps]; double diffAtB = -4 * yAtB + 5 * derAtB - 1.4; if (diffAtB > 0) yb = cy; else ya = cy; } }