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

Uploaded Python 3

File details

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

File metadata

  • Download URL: cmlabs-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a8b611c41de4a9fe976fbedb6a70a5af33e9b2bc2734441177a33670c042c501
MD5 e6c792c0aced943c67bc433672bd1dd9
BLAKE2b-256 98c84080b75e0cd32e921a88827cc9b7190cb58c7cc0906416c9373add86004a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: cmlabs-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68fd9eed576314c95dcec678d185b381a46e9ba3db45901941de8c885d283d90
MD5 eabc7c7ce1aff7134b9d6b8126b05297
BLAKE2b-256 112b9de4edcc2a7d8ad89da8697cf1fa39828db4c235b7666c6fbdcff35027d3

See more details on using hashes here.

Provenance

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