Skip to content

Drain-Man/NumInt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NumInt

Release Python License

NumInt is a Python tool to approximate definite integrals using standard numerical methods: Left-hand, Right-hand, Midpoint, Trapezoid, and Simpson. It supports both interactive input and CLI commands.


Features

  • Approximate definite integrals with 5 standard numerical methods.
  • Compute absolute error compared to the exact integral (when possible).
  • Supports constants like pi and e.
  • Interactive prompts or CLI arguments.

Installation

Clone the repository:

git clone https://github.com/Drain-Man/NumInt.git
cd NumInt

Install dependencies:

pip install -r requirements.txt

Usage

Interactive Mode: Run the program and follow the prompts:

python main.py

You will be asked for:

  • Function f(x) (e.g., sin(x)+x^2)
  • Lower and upper bounds
  • Number of subintervals
  • Approximation method

CLI Mode:

python main.py --function "sin(x)" --lower 0 --upper pi --n 100 --method simpson

Parameters:

  • --function: Function to integrate (supports ^ for exponentiation)
  • --lower: Lower bound of interval
  • --upper: Upper bound of interval
  • --n: number of subintervals
  • --method: Approximation method (left, right, center, trapezoid, simpson)
  • --version: Show program version and exit

Supported Mathematical Functions

NumInt parses functions using SymPy, allowing many standard mathematical expressions.

Examples:

sin(x)
cos(x)
x^2 + 3*x
exp(x)
sqrt(x)

Logarithms

Logarithms follow SymPy syntax:

log(x)      # natural logarithm (ln)
log(x, 10)  # base-10 logarithm

NumInt also supports:

ln(x)

which is treated as an alias for log(x).

Constants supported:

pi
e

Pre-built Windows Executable: Windows users can run NumInt without installing Python

  1. Download the Windows executable from the Releases section: https://github.com/Drain-Man/NumInt/releases

  2. Run from the command line with CLI arguments:

...\NumInt.exe --function "x^2" --lower 0 --upper 1 --n 10 --method trapezoid
  1. Run the .exe without CLI Arguments to use in interactive mode. Note: This Version is v1.0. Future releases may include updated binaries.

Building the Windows Executable Yourself: If you prefer to build the .exe locally (e.g. for a newer version):

# Install PyInstaller if not installed
pip install pyinstaller

# From the project root
pyinstaller --onefile --name NumInt --icon Resources\NumInt.ico main.py

The .exe will appear in the dist/ folder.


Examples

Interactive Example:

Enter a function f(x): sin(x)
Enter the lower boundary of the interval: 0
Enter the upper boundary of the interval: pi
Enter the number of subintervals: 8
Enter the type of approximation
1: Left
2: Right
3: Center
4: Trapezoid
5: Simpson
(Enter number or name): simpson

Simpson approximation: 2.00026917
Exact value:           2
Absolute error:        2.692e-04

Optional: Add NumInt to PATH (Windows)

If you want to run NumInt.exe from any folder without typing the full path:

  1. Move NumInt.exe to a permanent location (e.g. C:\Program Files\NumInt\)
  2. Open Environment Variables with sysdm.cpl -> Advanced -> Environment Variables.
  3. Under "User variables" or "System variables", edit the Path variable and add the folder containing NumInt.exe.
  4. Ok -> Ok -> Ok
  5. Open a new Command Prompt and test:
NumInt.exe --version

Changelog

All notable changes to this project are documented in CHANGELOG.md.


Credits / Dependencies

About

CLI tool for approximating definite integrals using numerical methods (Riemann sums, trapezoid, Simpson).

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages