PyPoSolver
PyPoSolver is a Python library for performing mathematical and physics calculations, including numerical integration, root-finding, linear algebra operations, and basic mechanics.
Installation
pip install pyposolver
Usage
Mathematics
Integration
Use the trapezoidal_rule
function to perform numerical integration:
from pyposolver.maths.integration import trapezoidal_rule
def f(x):
return x**2
result = trapezoidal_rule(f, 0, 1, 100)
print(result)
Root-Finding
Use bisection_method
to find the root of a function within a specified interval:
from pyposolver.maths.root_finding import bisection_method
def f(x):
return x**2 - 4
root = bisection_method(f, 0, 3)
print(root)
Use newton_raphson_method
for root-finding with an initial guess and the function's derivative:
from pyposolver.maths.root_finding import newton_raphson_method
def f(x):
return x**3 - 2*x - 5
def df(x):
return 3*x**2 - 2
root = newton_raphson_method(f, df, 2)
print(root)
Linear Algebra
Calculate the dot product of two vectors:
from pyposolver.maths.linear_algebra import dot_product
vector1 = [1, 2, 3]
vector2 = [4, 5, 6]
result = dot_product(vector1, vector2)
print(result)
Compute the cross product of two 3D vectors:
from pyposolver.maths.linear_algebra import cross_product
vector1 = [1, 2, 3]
vector2 = [4, 5, 6]
result = cross_product(vector1, vector2)
print(result)
Multiply two matrices:
from pyposolver.maths.linear_algebra import matrix_multiply
matrix1 = [[1, 2], [3, 4]]
matrix2 = [[5, 6], [7, 8]]
result = matrix_multiply(matrix1, matrix2)
print(result)
Physics
Calculate velocity given initial velocity, acceleration, and time:
from pyposolver.physics.mechanics import velocity
initial_velocity = 5
acceleration = 2
time = 3
result = velocity(initial_velocity, acceleration, time)
print(result)
Calculate force using mass and acceleration:
from pyposolver.physics.mechanics import force
mass = 10
acceleration = 5
result = force(mass, acceleration)
print(result)