Skip to content

prathameshkhade/numerical-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Numerical Integration Calculator

License Version C++

A comprehensive C++ application for numerical integration with multiple methods, detailed step-by-step calculations, and comparison capabilities.

πŸ“ Table of Contents

✨ Features

  • Multiple Integration Methods: Includes Trapezoidal Rule, Simpson's Rules, Boole's Rule, and Romberg Integration
  • Step-by-Step Calculation Display: See how each method works with detailed intermediate steps
  • Method Comparison: Compare the accuracy and results of different integration methods
  • Multiple Functions: Choose from a variety of predefined mathematical functions
  • Result Storage: Save integration results to files and load them later
  • Cross-Platform: Works on Windows, macOS, and Linux
  • User-Friendly Interface: Clear console-based interface with easy navigation

πŸ“Š Supported Integration Methods

  1. Trapezoidal Rule: Uses linear approximation between points

    • Formula: h/2 * [f(a) + f(b) + 2 * sum(f(x_i))]
  2. Simpson's 1/3 Rule: Uses quadratic approximation

    • Formula: h/3 * [f(a) + f(b) + 4 * sum(f(x_odd)) + 2 * sum(f(x_even))]
    • Requires an even number of intervals
  3. Simpson's 3/8 Rule: Uses cubic approximation

    • Formula: 3h/8 * [f(a) + f(b) + 3 * sum(f(not divisible by 3)) + 2 * sum(f(divisible by 3))]
    • Requires a number of intervals divisible by 3
  4. Boole's Rule: Uses fourth-degree polynomial approximation

    • Formula: 4h/90 * [7(f(a) + f(b)) + 32(f(x1) + f(x3) + ...) + 12(f(x2) + f(x6) + ...) + 14(f(x4) + f(x8) + ...)]
    • Requires a number of intervals divisible by 4
  5. Romberg Integration: Uses Richardson extrapolation to improve accuracy

    • Highly accurate for smooth functions
    • Adjustable order for precision control

πŸš€ Installation

Prerequisites

  • C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 19.14+)
  • CMake 3.10 or higher (for building from source)
  • Git (optional, for cloning the repository)

Building from Source

  1. Clone the repository:

    git clone https://github.com/prathameshkhade/Numerical-Integration.git
    cd Numerical-Integration
  2. Create a build directory and navigate to it:

    mkdir build
    cd build
  3. Configure with CMake and build:

    cmake ..
    cmake --build .
  4. Run the executable:

    • Windows: .\Debug\NumericalIntegration.exe or .\Release\NumericalIntegration.exe
    • macOS/Linux: ./NumericalIntegration

Pre-built Binaries

Pre-built binaries for Windows, macOS, and Linux are available in the Releases section.

πŸ“– Usage

Basic Operation

  1. Start the application
  2. Select "Perform Integration" from the main menu
  3. Choose a function to integrate
  4. Enter the lower and upper bounds of integration
  5. Specify the number of intervals
  6. Select an integration method
  7. View the result and step-by-step calculation

Choosing an Integration Method

  • Trapezoidal Rule: Good general-purpose method, works with any number of intervals
  • Simpson's 1/3 Rule: Better accuracy than Trapezoidal for most functions, requires even number of intervals
  • Simpson's 3/8 Rule: Similar accuracy to 1/3 rule, requires intervals divisible by 3
  • Boole's Rule: Higher accuracy for smooth functions, requires intervals divisible by 4
  • Romberg Integration: Highest accuracy, especially for smooth functions

Comparing Methods

  1. Select "Compare All Integration Methods" from the main menu
  2. Enter integration parameters (function, bounds, intervals)
  3. The program will calculate the integral using all available methods
  4. Results are displayed in a comparison table with error estimates

Saving and Loading Results

  • After performing an integration, you can save the result to a file
  • Use "Load Previous Results" to view previously saved results
  • Result files include all parameters and intermediate values

πŸ“ Mathematical Background

Numerical integration methods approximate definite integrals using various techniques:

  • Trapezoidal Rule: Approximates the area under the curve using trapezoids
  • Simpson's Rules: Use quadratic (1/3) or cubic (3/8) polynomials to approximate the function
  • Boole's Rule: Uses fourth-degree polynomials for higher accuracy
  • Romberg Integration: Applies Richardson extrapolation to the trapezoidal rule

For a function f(x) and an interval [a, b], the definite integral is approximated by dividing the interval into n subintervals and applying the specific formula for each method.

πŸ“‚ Project Structure

numerical-integration/
β”œβ”€β”€ include/                # Header files
β”‚   β”œβ”€β”€ function.h          # Mathematical function definitions
β”‚   β”œβ”€β”€ input.h             # Input handling class
β”‚   β”œβ”€β”€ integrator.h        # Base integrator class
β”‚   β”œβ”€β”€ methods/            # Integration methods
β”‚   β”‚   β”œβ”€β”€ trapezoidal.h
β”‚   β”‚   β”œβ”€β”€ simpson13.h
β”‚   β”‚   β”œβ”€β”€ simpson38.h
β”‚   β”‚   β”œβ”€β”€ boole.h
β”‚   β”‚   └── romberg.h
β”‚   └── utils.h             # Utility functions
β”œβ”€β”€ src/                    # Implementation files
β”‚   β”œβ”€β”€ function.cpp
β”‚   β”œβ”€β”€ input.cpp
β”‚   β”œβ”€β”€ integrator.cpp
β”‚   β”œβ”€β”€ methods/
β”‚   β”‚   β”œβ”€β”€ trapezoidal.cpp
β”‚   β”‚   β”œβ”€β”€ simpson13.cpp
β”‚   β”‚   β”œβ”€β”€ simpson38.cpp
β”‚   β”‚   β”œβ”€β”€ boole.cpp
β”‚   β”‚   └── romberg.cpp
β”‚   β”œβ”€β”€ utils.cpp
β”‚   └── main.cpp            # Program entry point
β”œβ”€β”€ CMakeLists.txt          # CMake build configuration
β”œβ”€β”€ LICENSE                 # License file
└── README.md               # This file

πŸ› οΈ Build Instructions

Windows

Using Visual Studio

  1. Open Visual Studio
  2. Select "Open a local folder" and navigate to the repository
  3. Visual Studio should detect the CMakeLists.txt and configure the project
  4. Build using Build > Build All
  5. Run the executable from the output directory

Using Command Line

  1. Open Command Prompt or PowerShell
  2. Navigate to the project directory
  3. Create and navigate to a build directory:
    mkdir build
    cd build
  4. Configure and build with CMake:
    cmake ..
    cmake --build . --config Release
  5. Run the executable:
    .\Release\NumericalIntegration.exe

macOS

  1. Open Terminal
  2. Navigate to the project directory
  3. Create and navigate to a build directory:
    mkdir build
    cd build
  4. Configure and build with CMake:
    cmake ..
    make
  5. Run the executable:
    ./NumericalIntegration

Linux

  1. Open a terminal
  2. Navigate to the project directory
  3. Create and navigate to a build directory:
    mkdir build
    cd build
  4. Configure and build with CMake:
    cmake ..
    make
  5. Run the executable:
    ./NumericalIntegration

πŸ’‘ Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Please ensure your code follows the project's coding style and includes appropriate tests.

πŸ“œ Changelog

v2.0.0 (2025-06-07)

  • Complete rewrite with modular C++ design
  • Added new integration methods (Boole's Rule, Romberg Integration)
  • Improved error handling and robustness
  • Added method comparison functionality
  • Added support for saving/loading results
  • Cross-platform compatibility improvements
  • Comprehensive documentation

v1.0.0 (Initial Release)

  • Basic implementation with Trapezoidal, Simpson's 1/3, and Simpson's 3/8 rules
  • Console-based interface
  • Step-by-step calculation display

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author


If you find this project useful, please consider giving it a star on GitHub!

About

This program will help you to find out the answers of the Numerical Integration step by step.

Resources

Stars

Watchers

Forks

Packages

No packages published