Skip to main content

A library for computational mathematics labs

Project description

cmlabs

cmlabs is a computational mathematics library for Python

Installation

pip install cmlabs

Usage

Interpolation

from cmlabs.interpolate import lagrange, newton, CubicSpline

xvals = np.array([0, 2, 3, 5])
yvals = np.array([1, 3, 2, 5])

y = lagrange(xvals, yvals, 1.5)
print(y)
# 3.3375000000000004

y = newton(xvals, yvlas, 1.5)
print(y)
# 3.3375

cs = CubicSpline(x, y, bc_type='not-a-knot')
print(cs.interpolate(0.5))
# 3.3375000000000004

Integration

from cmlabs.integrate import rectangle

xvals = np.array([0, 1, 2, 3])
yvals = np.array([0, 1, 4, 9])

I = rectangle(xvals, yvals, method="left")
print(I)
# 5.0

Differentiation

from cmlabs.differentiate import lagrange_derivative

xvals = np.array([0, 1, 2, 3, 4])
yvals = np.array([0, 1, 4, 9, 16])

L = lagrange_derivative(xvals, yvals, 2.5, 2)
print(L)
# 2.0

Linear Algebra

from cmlabs.linalg import thomas

A = [1, 1]
B = [4, 4, 4]
C = [1, 1]
F = [5, 5, 5]

solution = thomas(A, B, C, F)
print(solution)
# [1.071 0.714 1.071]

Optimization

from cmlabs.optimize import find_root_brackets, bisect

def f(x):
    return x**2 - 4

intervals = find_root_brackets(f, a=0, b=10, bins=10)
print(intervals)
# [(1.1111111111111112, 2.2222222222222223)]

root = bisect(f_test, intervals[0], xtol=1e-5, ytol=1e-5)
print(root)
# 1.9999980926513672

If you find any errors in the formulas or code, please feel free to open a github issue

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

cmlabs-0.2.1.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

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

cmlabs-0.2.1-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

Details for the file cmlabs-0.2.1.tar.gz.

File metadata

  • Download URL: cmlabs-0.2.1.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cmlabs-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ff331999ea211c97ea7fed2d3e49095e38333c879e92fef911835c11acff6247
MD5 a4d40e21ed61ed27a0aa5ededb27d65f
BLAKE2b-256 9a51e0b22fd5cd4481468244c308ddeb5ac0d22c8b9450cfaa3422cff9d7e0e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmlabs-0.2.1.tar.gz:

Publisher: publish.yml on r0manch1k/cmlabs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cmlabs-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: cmlabs-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 46.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cmlabs-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c1b085d7728712e7e99afd01b9c82147276172466e2dbc11413bb788bf84187
MD5 ddc788a39eb031342f0d6e48384d0dd0
BLAKE2b-256 69e2d918e104cc6e88b7e15d4fcaabbcf1fc892b9ec1eb07db779e3aa51c788d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmlabs-0.2.1-py3-none-any.whl:

Publisher: publish.yml on r0manch1k/cmlabs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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