Skip to content

g30613740/bound_value_problem_2order_DE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numerical Solution of Boundary Value Problems for ODE (requires further development)

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∞.

Requirements

  • C++ compiler with C++17 support (e.g., g++, clang++)
  • GNU Make
  • Python 3 with matplotlib and numpy (for visualisation)

Quick Start


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:

  1. Solve the linear problem using the finite difference method (with tridiagonal solver) and the shooting method.
  2. Solve the nonlinear problem using Newton's method and the secant method.
  3. Print a table of errors (comparing h and h/2) for each method.
  4. Generate parameters.txt with all numerical solutions.
  5. Launch create_plot.py to 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

Example Output

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.)

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.

Comparison for linear problem
Figure 1: Numerical solutions for the linear BVP.

Comparison for nonlinear problem
Figure 2: Numerical solutions for the nonlinear BVP.

(Replace the placeholder images with actual screenshots after running the program.)

Project Structure

.
├── 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)

Author

Name: @g30613740 Philip K.

Year: 2025

License

This project is distributed under the MIT License. See the LICENSE file for details.

About

C++ implementation of finite differenc and shooting methods (with RK4) for linear BVPs, plus Newton's and secant methods for nonlinear BVPs, with L₁, L₂, and L∞ error estimation via grid refinement.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors