Skip to main content

tests linter codecov

python 3.6 release (latest by date) license

pre-commit code style: black

pypi version pypi downloads

About

My bachelor project on solving the Calculus of variations problems using symbolic mathematics (2018).

I participated with this project at the IX International Scientific and Practical Conference named after A.I. Kitov "Information Technologies and Mathematical Methods in Economics and Management" (link).

My presentation about this project.

What is Calculus of variations

According to Wikipedia:
The calculus of variations is a field of mathematical analysis that uses variations, which are small changes in functions and functionals, to find maxima and minima of functionals: mappings from a set of functions to the real numbers. Functionals are often expressed as definite integrals involving functions and their derivatives. Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations.

Simplest problem

The definition above might seem quite difficult to understand, so let's consider the simplest problem:




This is the task of finding an extrema in continuously differentiable functions space , where:

- functional to maximize/minimize,
- fixed closed line segment,
- continuously differentiable function,
- function derivative,
- boundary conditions.

Example




Euler–Lagrange equation

Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations:

, where

- partial derivative of w.r.t. ,
- partial derivative of w.r.t. .

Arbitrary constants arising when solving this differential equation, find them from the given boundary conditions.

List of supported problems

More about each task in project wiki.

Usage

First, install the package:

pip install calculus-of-variations

Usage for example above:

import calculus_of_variations

solver = calculus_of_variations.SimplestSolver(
    L="x_diff ** 2 + t * x",
    t0="0", t1="1",
    x0="0", x1="0",
)

solver.solve()

# integral from 0 to 1 of (x_diff ** 2 + t * x)dt -> extr
# x(0) = 0
# x(1) = 0

# general_solution: C1 + C2*t + t**3/12
# coefficients: {C1: 0, C2: -1/12}
# particular_solution: t**3/12 - t/12
# extrema_value: -1/180

Other cases:

# Simplest problem
solver = calculus_of_variations.SimplestSolver(
    L="x_diff ** 2",
    t0="0", t1="1",
    x0="0", x1="1",
)
solver.solve()

# Boltz problem
solver = calculus_of_variations.BoltzSolver(
    L="x_diff ** 2 + 2 * x",
    l="x_t0 ** 2",
    t0="0", t1="1",
)
solver.solve()

# Isoperimetric problem
solver = calculus_of_variations.IsoperimetricSolver(
    f0="x_diff ** 2",
    t0="0", t1="1",
    x0="0", x1="1",
    f_list="x",
    alpha_list="0",
)
solver.solve()

# Higher derivatives problem
solver = calculus_of_variations.HigherDerivativesSolver(
    n="2",
    L="x_diff_2 ** 2",
    t0="0", t1="1",
    x0="0", x1="0",
    x0_array="0",
    x1_array="1",
)
solver.solve()

# Multidimensional problem
solver = calculus_of_variations.MultidimensionalSolver(
    L="x1_diff**2 + x2_diff**2",
    t0="0", t1="1",
    x1_0="0", x1_1="1",
    x2_0="0", x2_1="1",
)
solver.solve()

For specific examples see examples.sh.
List of allowed functions that you can use as parameters: link.

Web-interface

The project supports simple web-interface for solving problems. You can specify host (--host) and port (--port) (default values: host: 127.0.0.1 and port: 8050):

# Simplest problem
python -m web_interface.simplest_problem_dash --host "127.0.0.1" --port 8050

# Boltz problem
python -m web_interface.boltz_problem_dash --host "127.0.0.1" --port 8050

# Isoperimetric problem
python -m web_interface.isoperimetric_problem_dash --host "127.0.0.1" --port 8050

# Higher derivatives problem
python -m web_interface.higher_derivatives_problem_dash --host "127.0.0.1" --port 8050

# Multidimensional problem
python -m web_interface.multidimensional_problem_dash --host "127.0.0.1" --port 8050

You can also launch web-interface using docker.
To build docker image run:

docker image build -t calculus_of_variations .

You can also pull image from Docker Hub:

docker pull dayyass/calculus_of_variations

To start docker container run (example for simplest_problem_dash):

docker container run -d -p 8050:8050 --name calculus_of_variations calculus_of_variations python -m web_interface.simplest_problem_dash --host 0.0.0.0 --port 8050

To access web-interface go to http://localhost:8050

Tests

To launch tests run the following commands:
python -m unittest discover

To use pre-commit hooks run:
pre-commit install

To measure code coverage run the following commands:
coverage run -m unittest discover && coverage report -m

Requirements

Python >= 3.6

Citation

If you use calculus-of-variations in a scientific publication, we would appreciate references to the following BibTex entry:

@misc{dayyass2018variations,
    author       = {El-Ayyass, Dani},
    title        = {Calculus of Variations problems solving using symbolic mathematics},
    howpublished = {\url{https://github.com/dayyass/calculus-of-variations}},
    year         = {2018}
}

Metadata

Release files for calculus-of-variations 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calculus-of-variations 0.3.0
File Size Uploaded
calculus-of-variations-0.3.0.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for calculus-of-variations 0.3.0
File Interpreter ABI Platform
calculus_of_variations-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / calculus-of-variations-0.3.0.tar.gz

Download URL calculus-of-variations-0.3.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8f6cf21b62b5e01f9198587be9fedbb009fdd8502af3e98c247cb4e9ed84a326
BLAKE2b-256 checksum
How to use checksums
d43ac90883e796cd5476b7d90c600b68af0351a789f87ee44533fcda019a3b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.5

Release files / calculus_of_variations-0.3.0-py3-none-any.whl

Download URL calculus_of_variations-0.3.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6d76217c9eb74d8a363d820499b5f65d8a3e6240089de69e1833bb9a154de82
BLAKE2b-256 checksum
How to use checksums
0f3dcd0f43ec35ad3b5fbdb610d8a74c8c0802bffd6d012256f3883e7ea941a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page