Skip to main content

Project on solving the Calculus of variations problems using symbolic mathematics

Project description

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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calculus-of-variations-0.3.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

calculus_of_variations-0.3.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file calculus-of-variations-0.3.0.tar.gz.

File metadata

  • Download URL: calculus-of-variations-0.3.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for calculus-of-variations-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8f6cf21b62b5e01f9198587be9fedbb009fdd8502af3e98c247cb4e9ed84a326
MD5 c59b66b7db8eda9f744896314885f662
BLAKE2b-256 d43ac90883e796cd5476b7d90c600b68af0351a789f87ee44533fcda019a3b16

See more details on using hashes here.

File details

Details for the file calculus_of_variations-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: calculus_of_variations-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for calculus_of_variations-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6d76217c9eb74d8a363d820499b5f65d8a3e6240089de69e1833bb9a154de82
MD5 a7c5aeb6bbe3ddefb657a4d210d1d854
BLAKE2b-256 0f3dcd0f43ec35ad3b5fbdb610d8a74c8c0802bffd6d012256f3883e7ea941a5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page