https://github.com/lopither/advanced-ode-solver-derivative-calculator
ODE solver in scipy with plotting feature
https://github.com/lopither/advanced-ode-solver-derivative-calculator
calculator calculus math ode ode-solver python scipy sympy
Last synced: 4 months ago
JSON representation
ODE solver in scipy with plotting feature
- Host: GitHub
- URL: https://github.com/lopither/advanced-ode-solver-derivative-calculator
- Owner: lopither
- Created: 2025-09-23T20:18:46.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-09-23T20:22:47.000Z (5 months ago)
- Last Synced: 2025-09-23T22:16:31.462Z (5 months ago)
- Topics: calculator, calculus, math, ode, ode-solver, python, scipy, sympy
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Advanced ODE Solver & Derivative Calculator
This repository contains a cross‑platform Python application for solving ordinary differential equations (ODEs) of arbitrary order and for computing derivatives symbolically. It provides a simple yet powerful graphical user interface (GUI) built with `tkinter` and relies on scientific libraries such as **SciPy**, **SymPy** and **Matplotlib**. The project is designed to make it easy for users—whether they are students, researchers or engineers—to experiment with differential equations, inspect solutions numerically and symbolically, and visualise results without writing any code themselves.
## Features
### ▸ Supports ODEs of any order
Unlike many simple solvers that handle only first‑order equations, this application can solve ODEs of order *n*:
- Enter the order of the equation in the **Order n** field. The GUI will automatically generate initial‑condition fields for all derivatives up to order *n − 1* (i.e. `y(x₀)`, `y′(x₀)`, `y″(x₀)`, …).
- Specify the right‑hand side of your equation in terms of `x`, `y` (for the function), `y1`, `y2`, … up to `y(n-1)`. For example, the second‑order equation
\(y'' = -2y' - 3y + \sin(x)\)
can be entered as `-2*y1 - 3*y + sin(x)`.
- Prime notation is also supported; you may write `y'`, `y''`, `y'''`, etc., and they will be automatically converted into `y1`, `y2`, `y3`, etc.
- Exponentiation using the caret (`^`) is normalised to Python’s `**` operator. Writing `x^2` or `y^(-1)` is acceptable.
- Initial values for each derivative can be specified; these are required by the underlying numerical solver.
### ▸ Dynamic singularity handling
Many differential equations are undefined at certain points (e.g. `1/x` at `x=0` or `x^(-1)` at `x=0`). When the chosen initial point lies on such a singularity, attempting to evaluate the equation would cause a division‑by‑zero or other undefined operation. To avoid abrupt errors:
1. The solver tests the right‑hand side at the initial point `x₀` and the provided initial conditions.
2. If evaluation raises an exception or produces `NaN`/`Inf`, the solver nudges the starting point by a tiny amount (up to `1×10⁻⁶ × 10⁵`) in the direction of integration.
3. If a safe starting point is found, it proceeds with integration and notifies you of the shift; otherwise it prompts you to choose a different `x₀`.
This makes it much easier to work with functions like `sin(x)/x` or `x^(-1)` without manually adjusting the domain.
### ▸ Multiple integration algorithms
The underlying numerical integrator uses **SciPy’s** `solve_ivp`, which implements a variety of adaptive algorithms. The application tries these methods in sequence until it finds one that successfully integrates your equation:
1. **RK45** – A Runge–Kutta solver of order 5(4).
2. **RK23** – A lower‑order solver useful for less smooth problems.
3. **DOP853** – A high‑order explicit solver for smooth, non‑stiff problems.
4. **BDF** – An implicit multistep solver for stiff problems.
5. **LSODA** – An automatic method that switches between stiff and non‑stiff algorithms.
If all methods fail, an informative error is displayed. You can also tune the integration by changing the number of evaluation points.
### ▸ Derivative calculator with LaTeX output
Apart from solving differential equations, the GUI provides a symbolic derivative calculator:
- Enter any single‑variable function `g(x)` in conventional mathematical notation (e.g. `sin(x)**2`, `exp(x)`, `log(x)`).
- Choose the order `n` of the derivative (0 returns the original function).
- Press **Compute derivative**. The application uses **SymPy** to compute `dⁿg/dxⁿ`, simplifies the result, and displays it:
- **Graphically** – A pop‑up window with the derivative rendered using Matplotlib’s mathtext engine.
- **As LaTeX** – A plain text LaTeX string for copying into your documents.
This dual display allows you to both see the expression rendered and use it in typeset form elsewhere.
### ▸ Modern, user‑friendly interface
- Organised into labelled sections (**ODE Solver** and **Derivative Calculator**) for clarity.
- Dynamic creation of input fields based on the order you specify.
- Consistent spacing and padding for a neat appearance across platforms.
- Uses only standard Python libraries (`tkinter`) and well‑established scientific packages, so no external GUI frameworks are required.
## Installation
1. Clone or download this repository.
2. Ensure you have Python 3.7 or later installed.
3. Install dependencies using `pip`:
```bash
pip install scipy sympy matplotlib