online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** This program first defines the function f(x, y), which is the differential equation that we want to solve. Then, it defines the function milne_predictor_corrector(), which implements the Milne predictor corrector method. This function takes in the initial value of x, y, the step size, and the number of steps, and returns the solution to the differential equation. *******************************************************************************/ #include <iostream> #include <math.h> using namespace std; double f(double x, double y) { return x * y; } double milne_predictor_corrector(double x0, double y0, double h, int n) { double y[n + 1]; y[0] = y0; for (int i = 1; i <= n; i++) { double y_pred = y[i - 1] + h * f(x0 + (i - 1) * h, y[i - 1]); double y_corr = y[i - 1] + h * (2 * f(x0 + (i - 1) * h, y[i - 1]) + f(x0 + i * h, y_pred)); y[i] = y_corr / 3; } return y[n]; } int main() { double x0 = 0; double y0 = 1; double h = 0.1; int n = 10; double y = milne_predictor_corrector(x0, y0, h, n); cout << "The solution is y = " << y << endl; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue