This program solves the Cauchy problem for a second‑order ordinary differential equation:
y'' = f(x, y, y') y(a) = q₀, y'(a) = q₁
on the interval [0, 1] with arbitrary initial conditions q₀, q₁ ∈ [-5, 5]. The right‑hand side is chosen as:
f(x, y, y') = y' · cos(x) + y · x³ + tan(x)
Five numerical methods are implemented:
- Euler's method
- Modified Euler method (with recalculation)
- Second‑order Runge–Kutta method
- Fourth‑order Runge–Kutta method
- Third‑order Adams explicit method
The step size for each method is chosen automatically to satisfy a prescribed accuracy. The errors are estimated by comparing solutions on grids with steps h, h/2 and 2h. Both absolute and relative errors are computed in three norms (L₁, L₂, L∞) for the solution y and its derivative y'.
- C++ compiler with C++11 support (e.g., g++, clang++)
- GNU Make
- Python 3 with matplotlib and numpy (for visualisation)
git clone <your-repo-url>
cd <project-folder>
make # compile the program
make run # compile and run
Alternatively, you can run manually:
make
./cauchy
The program will:
- Automatically choose appropriate step sizes for each method.
- Print four tables of errors (for y and y', comparing h with h/2 and with 2h).
- Generate
parameters.txtwith all numerical solutions. - Launch
create_plot.pyto show two plots: one for y(x) and one for y'(x), each containing five curves.
To clean up:
make clean
After running ./cauchy, the console shows tables similar to the following (values are illustrative):
table 1: paragraph 6 - printing errors for y for h / 2 and h –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | | abs 1 | abs 2 | abs inf | rel 1 | rel 2 | rel inf | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | euler | 1.234e-02 | 1.567e-02 | 1.890e-02 | 2.345e-02 | 2.678e-02 | 2.901e-02 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | mod euler | 3.456e-03 | 4.567e-03 | 5.678e-03 | 6.789e-03 | 7.890e-03 | 8.901e-03 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | rk2 | 4.567e-04 | 5.678e-04 | 6.789e-04 | 7.890e-04 | 8.901e-04 | 9.012e-04 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | rk4 | 1.234e-06 | 1.567e-06 | 1.890e-06 | 2.345e-06 | 2.678e-06 | 2.901e-06 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | adams | 1.234e-06 | 1.567e-06 | 1.890e-06 | 2.345e-06 | 2.678e-06 | 2.901e-06 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
(The actual values depend on the chosen initial conditions and the automatic step selection.)
Additionally, two plots are generated: one for the solution y(x) and one for its derivative y'(x), each showing the five numerical methods.
. ├── Makefile ├── README.md ├── .gitignore ├── LICENSE ├── create_plot.py # Python script for visualisation ├── parameters.txt # generated data (ignored) ├── src/ │ ├── main.cpp │ ├── functions.cpp │ └── functions.h ├── docs/ │ └── task.pdf └── build/ # object files (ignored)
Name: @g306137 Philip K.
Year: 2025
This project is distributed under the MIT License.