A library to simplify mathematical computations.
Project description
stdmathlib
A Python library to simplify mathematical computations.
Installation
pip install stdmathlib
Functions
integrate_expression
Integrates a mathematical expression with respect to a variable.
Parameters:
expression_str(str): The mathematical expression as a string.var(str): The variable to integrate with respect to (default is'x').lower_limit(float, optional): The lower limit of integration.upper_limit(float, optional): The upper limit of integration.
Returns:
integral_expr: The symbolic integral expression (indefinite integral).integral_value(optional): The numerical value of the definite integral.
Example Usage:
from stdmathlib import integrate_expression
# Indefinite integral
integral_expr = integrate_expression('x**2')
print(f"Indefinite integral: {integral_expr} + C") # Output: x**3/3 + C
# Definite integral from x=0 to x=2
integral_expr, integral_value = integrate_expression('x**2', lower_limit=0, upper_limit=2)
print(f"Indefinite integral: {integral_expr} + C") # Output: x**3/3 + C
print(f"Definite integral from 0 to 2: {integral_value}") # Output: 2.66666666666667
derivative
Differentiates a mathematical expression with respect to a variable.
Parameters:
expression_str(str): The mathematical expression as a string.var(str): The variable to differentiate with respect to (default is'x').eval_point(float, optional): The point at which to evaluate the derivative.
Returns:
derivative_expr: The symbolic derivative expression.derivative_value(optional): The numerical value of the derivative ateval_point.
Example Usage:
from stdmathlib import derivative
# Differentiate symbolically
derivative = derivative('x**2 + 3*x + 2')
print(derivative) # Output: 2*x + 3
# Differentiate and evaluate at x = 2
derivative_expr, derivative_value = derivative('x**2 + 3*x + 2', eval_point=2)
print(derivative_expr) # Output: 2*x + 3
print(derivative_value) # Output: 7
partial_derivative_expression
Computes the partial derivative of a multivariable function with respect to specified variables.
Parameters:
expression_str(str): The multivariable function as a string.variables(list of str): List of variable names in the function.differentiation_vars(list of str): List of variables to differentiate with respect to.eval_points(dict, optional): Dictionary of variable values for evaluation.
Returns:
derivative_expr: The symbolic partial derivative expression.derivative_value(optional): The numerical value of the derivative ateval_points.
Example Usage:
from stdmathlib import partial_derivative_expression
# Compute ?f/?x
expression = 'x**2 * y + y**3'
variables = ['x', 'y']
differentiation_vars = ['x']
partial_derivative = partial_derivative_expression(expression, variables, differentiation_vars)
print(partial_derivative) # Output: 2*x*y
plot
Plots a mathematical expression using matplotlib.
Parameters:
expression_str(str): The mathematical expression as a string, e.g.,'sin(x)'.var(str): The variable in the expression (default is'x').range_start(float): The start of the range for the variable (default is-10).range_end(float): The end of the range for the variable (default is10).num_points(int): The number of points to compute for plotting (default is1000).title(str): The title of the plot.xlabel(str): The label for the x-axis.ylabel(str): The label for the y-axis.line_style(str): The line style for the plot (e.g.,'-','--','-.',':').color(str): The color of the plot line (e.g.,'blue','red','#FF5733').
Returns:
None: Displays the plot.
Example Usage:
from stdmathlib import plot
import numpy as np
# Plot y = sin(x) from -2? to 2? with customizations
plot(
expression_str='sin(x)',
range_start=-2 * np.pi,
range_end=2 * np.pi,
title='Sine Function',
xlabel='Angle (radians)',
ylabel='Amplitude',
line_style='--',
color='red'
)
integrate_multivariable_expression
Computes the multivariable integral of an expression with respect to specified variables.
Parameters:
expression_str(str): The mathematical expression as a string.variables(list of str): List of variable names to integrate with respect to.limits(list of tuples, optional): List of tuples specifying the limits for each variable. Each tuple should be(variable_name, lower_limit, upper_limit).
Returns:
- For indefinite integrals: The symbolic integral expression.
- For definite integrals: The numerical value of the integral.
Example Usage:
from stdmathlib import integrate_multivariable_expression
# Indefinite integral
integral_expr = integrate_multivariable_expression('x * y', ['x', 'y'])
print(f"Indefinite integral: {integral_expr} + C")
# Definite integral
limits = [('x', 0, 1), ('y', 0, 2)]
integral_value = integrate_multivariable_expression('x * y', ['x', 'y'], limits=limits)
print(f"Definite integral value: {integral_value}")
factorial
Computes the factorial of a non-negative integer.
Parameters:
n(int): The number to compute the factorial of (n ? 0).
Returns:
int: The factorial ofn.
Example Usage:
from stdmathlib import factorial
result = factorial(5)
print(f"5! = {result}") # Output: 5! = 120
combinations
Computes the number combinations of two non-negative integers.
Parameters:
n(int): The number of items in the set (n ? 0).r(int): The number of spots that can be chosen from (n ? r ? 0).
Returns:
int: The number of combinations possible givennandr.
Example Usage:
from stdmathlib import combinations
result = combinations(5, 3)
print(f"5C3 = {result}") # Output: 5C3 = 10
permutations
Computes the number of arrangements that n can make with the length of r, where order is important.
Parameters:
n(int): The number of items in the set (n ? 0).r(int): the number of selected objects arranged in a certain order (n ? r ? 0).
Returns:
int: The number of permutations possible givennandr.
Example Usage:
from stdmathlib import permutations
result = permutations(5, 3)
print(f"5P3 = {result}") # Output: 5P3 = 60
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stdmathlib-0.1.10.tar.gz.
File metadata
- Download URL: stdmathlib-0.1.10.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
580034d2a2951fd117b154a331e8a24758a65f73b871ac7f16be2c3ba5452519
|
|
| MD5 |
dc1f1ee8e365a007755ecd75dad8a3ab
|
|
| BLAKE2b-256 |
bddcfe83d3f58be1c8558184b151d086e7701edb2cb7fde83dc6721669e8907d
|
File details
Details for the file stdmathlib-0.1.10-py3-none-any.whl.
File metadata
- Download URL: stdmathlib-0.1.10-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c59585be68702d7015c5a2f4f18b33f2da292dc0f1d7df8fbd44bd078b09898
|
|
| MD5 |
1561d6f3cc21218548659f221326dd6a
|
|
| BLAKE2b-256 |
e39db78fec94261d13bcfaa4553b9cdd4f861dc4c1515bfe5580f7632c4402f1
|