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.2.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.2-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cmlabs-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 539eb0177791225e6f816339ea3d9208bdcf3d8fe37e314bd50e02bb9d1fab8d
MD5 8bb8cfaf41cd529554eceace80a8f14c
BLAKE2b-256 95c9f15a38aff7e1060fe77cf90a3d51391bc8efa2a55d3ad085f4054850f192

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmlabs-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: cmlabs-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0107330edf7f475951f8006ff280d2b94e257f97379217975452cc5c623cf811
MD5 1a45693b0c3a19d9cce1270d2689d109
BLAKE2b-256 a6ffc4dbc918fa8a465e7abf4782df2aa4537cf6c462ae864bf84173332cf706

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmlabs-0.2.2-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