Skip to main content

A little package for working with equations

Project description

g_equations

g_equations is my Python module for working with equations (some things are powered by NumPy)

Special thanks to Nastya for her helpful support ^^

Using Library

The library is in development so this section is updated together with library itself

Library connection

import g_equations
import g_equations.np_handler

Package Requirements: Some functions from g_equations.np_handler module require NumPy

Linear equation to dictionary

g_equations module has equ_to_dict(equation) function that gets an str object with human-like written liner equation and returnes a dictionary with variablies' coefficients

equ_dict = g_equations.equ_to_dict("x + 72.3y - 3z = 8.0")
print(equ_dict) # {'res': 8.0, 'x': 1.0, 'y': 72.3, 'z': -3.0}
equ_dict = g_equations.equ_to_dict("x + 72.3y - 3z - 6 = 8.0 - x")
print(equ_dict) # {'res': 14.0, 'x': 2.0, 'y': 72.3, 'z': -3.0}

String should have two parts with = between them. All variables are moved to the left side and free terms are moved to the right one
Returned dictionary will have right side value by "res" key and variablies' coefficients by their names

[!WARNING] The function works only with variables whose names consist of a single Latin alphabet character

Linear equation to matrixs

g_equations.np_handler has matrixs_from_dicts(dictionaries) function that gets a list of dictionaties (like in 'the section upper') with variablies' coefficients from a system of equations and returnes list with two entries: matrix of variablies' coefficients and matrix with right side values

[!NOTE] Matrix (not a numpy.matrix) is a list of lists with a rectangular shape
Like this: [ [a11,a12,a13], [a21,a22,a23], [a31,a32,a33] ]

Let's take a look at this system of equations:
$3x - y + 2z = -4;$
$x + 4y - z = 10;$
$2x + 3y + z = 8;$

Matrix can be got via matrixs_from_dicts(dictionaries) like this:

equ1 = {'res': -4.0, 'x': 3.0, 'y': -1.0, 'z': 2.0}
equ2 = {'res': 10.0, 'x': 1.0, 'y':  4.0, 'z': -1.0}
equ3 = {'res':  8.0, 'x': 2.0, 'y':  3.0, 'z': 1.0}
matrix_pair = g_equations.np_handler.matrixs_from_dicts([equ1,equ2,equ3])

There is also matrixs_from_equs(equations) function that gets a list of str objects with 'human-like written liner equations' and do the same things as matrixs_from_dicts(dictionaries)

matrix_pair = g_equations.np_handler.matrixs_from_equs([
    "3x - y + 2z = -4",
    "x + 4y - z = 10",
    "2x + 3y + z = 8"
])

Both matrix_pair look like:

matrix_pair[0]: [ [3.0,-1.0, 2.0],        matrix_pair[1]: [ [-4.0],
                  [1.0, 4.0,-1.0],                          [10.0],
                  [2.0, 3.0, 1.0] ]                         [ 8.0] ]      

Solve system of linear equations

g_equations.np_handler has numpy_from_dicts(dictionaries) function that gets a list of dictionaties (like in 'the section upper') with variablies' coefficients from a system of equations and returnes dictionary with system's roots: roots' coefficients by names of their variables

Let's take a look at this system of equations:
$3x - y + 2z = -4;$
$x + 4y - z = 10;$
$2x + 3y + z = 8;$

Roots can be got via numpy_from_dicts(dictionaries) like this:

equ1 = {'res': -4.0, 'x': 3.0, 'y': -1.0, 'z': 2.0}
equ2 = {'res': 10.0, 'x': 1.0, 'y':  4.0, 'z': -1.0}
equ3 = {'res':  8.0, 'x': 2.0, 'y':  3.0, 'z': 1.0}
system_roots = g_equations.np_handler.numpy_from_dicts([equ1,equ2,equ3])

There is also numpy_from_equs(equations) function that gets a list of str objects with 'human-like written liner equations' and do the same things as numpy_from_dicts(dictionaries)

system_roots = g_equations.np_handler.numpy_from_equs([
    "3x - y + 2z = -4",
    "x + 4y - z = 10",
    "2x + 3y + z = 8"
])

Both system_roots look like:

{'x': 0.16666666666666607, 'y': 2.166666666666668, 'z': -1.166666666666666}

[!NOTE] There are shorter names for these two functions. roots_of_dicts for numpy_from_dicts and solve_equs for numpy_from_equs

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

g_equations-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

g_equations-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file g_equations-1.0.0.tar.gz.

File metadata

  • Download URL: g_equations-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for g_equations-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1e68f179b1ba1140488394184c04862af7f146809a5f3aee96f702a3034e7d9c
MD5 58a9083af1fb829002af4914df728d47
BLAKE2b-256 dfe34ba3d8b4149e3005fbaebf7489ed2399f0995f38b2f89e29bcaeca976f31

See more details on using hashes here.

File details

Details for the file g_equations-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: g_equations-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for g_equations-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8be7c524209b7aacccb2a4871fb7c3c6c668b46adb83bb091c2da244f75f29e2
MD5 1ddf4c209b06a6b71280bee78ed75f00
BLAKE2b-256 675f4e51deff55c447d5deaba7e470e3c2fa5844fc6d64d499b2e9dadc942f97

See more details on using hashes here.

Supported by

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