#include <bits/stdc++.h>
using namespace std;
double f(double x, double y) {
return x + y;
}
double rk(double x0, double y0, double h, double x_end) {
double x = x0;
double y = y0;
while (x < x_end) {
double k1 = h * f(x, y);
double k2 = h * f(x + h / 2, y + k1 / 2);
double k3 = h * f(x + h / 2, y + k2 / 2);
double k4 = h * f(x + h, y + k3);
y = y + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4);
x = x + h;
}
return y;
}
int main() {
double x0 = 0.0;
double y0 = 1.0;
double h = 0.1;
double x_end1 = 0.1;
double x_end2 = 0.2;
double result1 = rk(x0, y0, h, x_end1);
double result2 = rk(x0, y0, h, x_end2);
cout << "y(0.1) is: " << result1 << endl;
cout << "y(0.2) is: " << result2 << endl;
return 0;
}
//C213115
//Nazmul Hasan Naeem
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmRvdWJsZSBmKGRvdWJsZSB4LCBkb3VibGUgeSkgewogICAgcmV0dXJuIHggKyB5Owp9CmRvdWJsZSByayhkb3VibGUgeDAsIGRvdWJsZSB5MCwgZG91YmxlIGgsIGRvdWJsZSB4X2VuZCkgewogICAgZG91YmxlIHggPSB4MDsKICAgIGRvdWJsZSB5ID0geTA7CiAgICB3aGlsZSAoeCA8IHhfZW5kKSB7CiAgICAgICAgZG91YmxlIGsxID0gaCAqIGYoeCwgeSk7CiAgICAgICAgZG91YmxlIGsyID0gaCAqIGYoeCArIGggLyAyLCB5ICsgazEgLyAyKTsKICAgICAgICBkb3VibGUgazMgPSBoICogZih4ICsgaCAvIDIsIHkgKyBrMiAvIDIpOwogICAgICAgIGRvdWJsZSBrNCA9IGggKiBmKHggKyBoLCB5ICsgazMpOwoKICAgICAgICB5ID0geSArICgxLjAgLyA2LjApICogKGsxICsgMiAqIGsyICsgMiAqIGszICsgazQpOwogICAgICAgIHggPSB4ICsgaDsKICAgIH0KICAgIHJldHVybiB5Owp9CgppbnQgbWFpbigpIHsKICAgIGRvdWJ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