This program solves a second‑order boundary value problem (BVP) of the form
y'' = f(x, y, y'), x ∈ [a, b], y(a) = q_a, y(b) = q_b,
on the interval [0, 1] with arbitrary boundary conditions q_a, q_b ∈ [-7, 7]. The right‑hand side is chosen as:
- Linear case: f(x, y, y') = y'·cos(x) + y·x³ + tan(x)
- Nonlinear case: f(x, y, y') = (y')²·cos(x) + y²·x³ + tan(x)
Four numerical methods are implemented and compared:
- Linear problem:
- Finite difference method with tridiagonal solver (Thomas algorithm)
- Shooting method (using 4th‑order Runge–Kutta for the auxiliary Cauchy problems)
- Nonlinear problem:
- Newton's method (for solving the nonlinear shooting equation)
- Secant method (for solving the nonlinear shooting equation)
The accuracy is estimated by comparing solutions on two grids (step h and h/2). Absolute and relative errors are computed in three vector norms: L₁, L₂ and L∞.
- C++ compiler with C++17 support (e.g., g++, clang++)
- GNU Make
- Python 3 with
matplotlibandnumpy(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_boundary
The program will:
- Solve the linear problem using the finite difference method (with tridiagonal solver) and the shooting method.
- Solve the nonlinear problem using Newton's method and the secant method.
- Print a table of errors (comparing h and h/2) for each method.
- Generate
parameters.txtwith all numerical solutions. - Launch
create_plot.pyto produce two plots:plot_linear.png– comparison of finite difference and shooting methods for the linear problem.plot_nonlinear.png– comparison of Newton and secant methods for the nonlinear problem.
To clean up build artifacts:
make clean
After running ./cauchy_boundary, the console shows a table similar to the following (values are illustrative):
paragraph 5 - printing errors for y for h / 2 and h –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | | abs 1 | abs 2 | abs inf | rel 1 | rel 2 | rel inf | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | fin diff | 1.234e-05 | 1.567e-05 | 1.890e-05 | 2.345e-05 | 2.678e-05 | 2.901e-05 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | shoot | 3.456e-06 | 4.567e-06 | 5.678e-06 | 6.789e-06 | 7.890e-06 | 8.901e-06 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | newtons | 1.234e-06 | 1.567e-06 | 1.890e-06 | 2.345e-06 | 2.678e-06 | 2.901e-06 | –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– | secants | 1.234e-06 | 1.567e-06 | 1.890e-06 | 2.345e-06 | 2.678e-06 | 2.901e-06 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
(The exact values depend on the chosen boundary conditions and step sizes. The finite difference method typically shows higher error due to its lower order, while shooting and Newton/secant methods provide more accurate results.)
The program automatically generates two plots:
- Linear problem – comparison of finite difference (green) and shooting (purple) methods.
- Nonlinear problem – comparison of Newton (blue) and secant (brown) methods.
Figure 1: Numerical solutions for the linear BVP.
Figure 2: Numerical solutions for the nonlinear BVP.
(Replace the placeholder images with actual screenshots after running the program.)
. ├── Makefile ├── README.md ├── .gitignore ├── LICENSE ├── create_plot.py # Python script for visualisation ├── parameters.txt # generated data (ignored by Git) ├── src/ │ ├── main.cpp │ ├── functions.cpp │ └── functions.h ├── docs/ │ └── Kraevye_zadachi.pdf └── build/ # object files (ignored by Git)
Name: @g30613740 Philip K.
Year: 2025
This project is distributed under the MIT License. See the LICENSE file for details.