Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numerical Solution of Nonlinear Systems

Graphs of the functions and the level lines of the residual sum of squares, with the roots marked

This program solves a system of two nonlinear algebraic equations:

x - y³ = 0
ln(x+2) - y = 0

using four iterative methods:

  • Simple iteration (fixed-point iteration)
  • Newton's method (with analytical Jacobian)
  • Modified Newton's method (constant Jacobian matrix)
  • Discrete Newton's method (finite-difference approximation of derivatives)

The program finds the two roots:

  • Root 1: (-1.696595, -1.192686)
  • Root 2: (97.07366, 4.59586)

Convergence is compared in terms of number of iterations. A Python script visualises the functions and the level lines of the residual sum of squares.

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:


make
./nonlinear_system

To clean up:


make clean

Example Output

After running ./nonlinear_system, the console shows a table comparing the four methods:

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|                      |     x      |     y      | iter_num |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|   simple iteration   | 9.707e+01  | 4.596e+00  |    50    |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|        newton        | 9.707e+01  | 4.596e+00  |     6    |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|      mod newton      | 9.707e+01  | 4.596e+00  |     8    |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|     discr newton     | 9.707e+01  | 4.596e+00  |     6    |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

(The exact values depend on the initial approximation and tolerance.)

Additionally, a Python script create_plot.py will be launched to display the graphs of the functions and the level lines of the residual sum of squares, with the roots marked.

Project Structure

.
├── Makefile
├── README.md
├── .gitignore
├── LICENSE
├── create_plot.py          # Python script for visualisation
├── src/
│   ├── main.cpp
│   ├── functions.cpp
│   └── functions.h
├── docs/
│   └── task.pdf
└── build/                  # object files (ignored)

Author

Name: @g30613740 Philip K.

Year: 2025

License

This project is distributed under the MIT License.

About

C++ implementation of simple iteration, Newton's method, modified Newton's method, and discrete Newton's method for solving a system of two nonlinear algebraic equations, with Python visualization.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages