marksfuncs 0.1__tar.gz → 1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {marksfuncs-0.1 → marksfuncs-1.1}/LICENSE.txt +21 -21
- marksfuncs-1.1/PKG-INFO +501 -0
- marksfuncs-1.1/README.md +470 -0
- marksfuncs-1.1/marksfuncs/__init__.py +21 -0
- marksfuncs-1.1/marksfuncs/functions.py +2681 -0
- marksfuncs-1.1/marksfuncs.egg-info/PKG-INFO +501 -0
- {marksfuncs-0.1 → marksfuncs-1.1}/setup.py +3 -3
- marksfuncs-0.1/PKG-INFO +0 -76
- marksfuncs-0.1/README.md +0 -57
- marksfuncs-0.1/marksfuncs/__init__.py +0 -1
- marksfuncs-0.1/marksfuncs/functions.py +0 -1317
- marksfuncs-0.1/marksfuncs.egg-info/PKG-INFO +0 -76
- {marksfuncs-0.1 → marksfuncs-1.1}/marksfuncs.egg-info/SOURCES.txt +0 -0
- {marksfuncs-0.1 → marksfuncs-1.1}/marksfuncs.egg-info/dependency_links.txt +0 -0
- {marksfuncs-0.1 → marksfuncs-1.1}/marksfuncs.egg-info/requires.txt +0 -0
- {marksfuncs-0.1 → marksfuncs-1.1}/marksfuncs.egg-info/top_level.txt +0 -0
- {marksfuncs-0.1 → marksfuncs-1.1}/setup.cfg +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 mark.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 mark.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
marksfuncs-1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: marksfuncs
|
|
3
|
+
Version: 1.1
|
|
4
|
+
Summary: Graph many mathematical functions
|
|
5
|
+
Home-page: https://github.com/marc1fino/marksfuncs
|
|
6
|
+
Author: mark. (Marc Pérez)
|
|
7
|
+
Author-email: <marcperezcarrasco2010@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: python,maths,graphics,functions,xy,mathematical functions
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: Unix
|
|
13
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE.txt
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: matplotlib
|
|
19
|
+
Requires-Dist: scipy
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: keywords
|
|
27
|
+
Dynamic: license
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
# marksfuncs
|
|
33
|
+
|
|
34
|
+
A comprehensive mathematical function plotting library for Python with **50+ built-in function classes**, **free-form expression evaluation**, and **publication-quality graphs**.
|
|
35
|
+
|
|
36
|
+
The project provides ready-to-use classes for elementary functions (linear, quadratic, exponential), transcendental functions (trigonometric, hyperbolic, logarithmic), special functions (Bessel, Gamma, Error, Airy), probability distributions (Gaussian, Weibull, Beta, Gamma, Poisson), and a powerful free-form expression evaluator that works like GeoGebra — all with clean APIs for both interactive plotting and programmatic image generation.
|
|
37
|
+
|
|
38
|
+
**Python** | **Mathematics** | **Data Visualization** | **Scientific Computing**
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+

|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **50+ function classes** — from elementary to special functions and probability distributions
|
|
47
|
+
- **Free-form expressions** — `ExpressionFunction` evaluates any mathematical string (like GeoGebra)
|
|
48
|
+
- **Polynomial by coefficients** — `PolynomialCoefficients` defines polynomials via degree→coefficient mapping
|
|
49
|
+
- **Dual output modes** — `graph()` for interactive display, `image()` for programmatic PNG buffers
|
|
50
|
+
- **Customizable ranges** — configurable x-range (start, end, points) and optional y-axis limits
|
|
51
|
+
- **Rich label support** — automatic formula labels on every plot
|
|
52
|
+
- **Publication ready** — high-quality Matplotlib output with grid, legend, and axis labels
|
|
53
|
+
- **Zero-config** — works out of the box with sensible defaults
|
|
54
|
+
|
|
55
|
+
## Function Categories
|
|
56
|
+
|
|
57
|
+
### Elementary Functions
|
|
58
|
+
|
|
59
|
+
| Class | Formula | Parameters |
|
|
60
|
+
| :--- | :--- | :--- |
|
|
61
|
+
| `Identity` | f(x) = x | `x_values_list` |
|
|
62
|
+
| `Linear` | f(x) = mx + b | `m`, `b`, `x_values_list` |
|
|
63
|
+
| `Quadratic` | f(x) = ax² + bx + c | `a`, `b`, `c`, `x_values_list`, `y_values?` |
|
|
64
|
+
| `Polynomial` | f(x) = Σ aᵢxⁱ (from string) | `polynomial_str`, `x_values_list`, `y_values?` |
|
|
65
|
+
| `PolynomialCoefficients` | f(x) = Σ aᵢxⁱ (from dict/list) | `coefficients`, `x_values_list`, `y_values?` |
|
|
66
|
+
| `Power` | f(x) = axᵇ | `a`, `b`, `x_values_list`, `y_values?` |
|
|
67
|
+
| `Root` / `Radical` | f(x) = a√(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
68
|
+
| `Absolute` | f(x) = a\|bx\| | `a`, `b`, `x_values_list`, `y_values?` |
|
|
69
|
+
|
|
70
|
+
### Exponential & Logarithmic
|
|
71
|
+
|
|
72
|
+
| Class | Formula | Parameters |
|
|
73
|
+
| :--- | :--- | :--- |
|
|
74
|
+
| `Exponential` | f(x) = a·eᵇˣ | `a`, `b`, `x_values_list`, `y_values?` |
|
|
75
|
+
| `Logarithmic` | f(x) = a·log(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
76
|
+
| `GeneralizedExponential` | f(x) = a·e^(-(x-b)²/2c²) | `a`, `b`, `c`, `x_values_list` |
|
|
77
|
+
| `ComplexExponential` | f(x) = a·e^(jbx) | `a`, `b`, `x_values_list` |
|
|
78
|
+
|
|
79
|
+
### Trigonometric & Hyperbolic
|
|
80
|
+
|
|
81
|
+
| Class | Formula | Parameters |
|
|
82
|
+
| :--- | :--- | :--- |
|
|
83
|
+
| `Trigonometric` | f(x) = a·sin(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
84
|
+
| `Hyperbolic` | f(x) = a·sinh(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
85
|
+
| `HyperbolicTangent` | f(x) = a·tanh(x) | `a`, `x_values_list`, `y_values?` |
|
|
86
|
+
| `InverseTrigonometric` | f(x) = a·arcsin(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
87
|
+
| `SincDirichlet` | f(x) = sinc(ax) | `a`, `x_values_list`, `y_values?` |
|
|
88
|
+
| `Dirichlet` | f(x) = sinc(ax - b) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
89
|
+
|
|
90
|
+
### Special Functions
|
|
91
|
+
|
|
92
|
+
| Class | Formula | Parameters |
|
|
93
|
+
| :--- | :--- | :--- |
|
|
94
|
+
| `BesselOrder0` | f(x) = J₀(x) | `x_values_list`, `y_values?` |
|
|
95
|
+
| `BesselOrder1` | f(x) = J₁(x) | `x_values_list`, `y_values?` |
|
|
96
|
+
| `Error` | f(x) = erf(x) | `x_values_list`, `y_values?` |
|
|
97
|
+
| `Airy` | f(x) = Ai(x) | `x_values_list`, `y_values?` |
|
|
98
|
+
| `SineFresnel` | f(x) = S(x) | `x_values_list`, `y_values?` |
|
|
99
|
+
| `CosineFresnel` | f(x) = C(x) | `x_values_list`, `y_values?` |
|
|
100
|
+
| `LogGamma` | f(x) = ln(Γ(x)) | `x_values_list`, `y_values?` |
|
|
101
|
+
| `LogSineProduct` | f(x) = log\|sin(x)\| | `x_values_list` |
|
|
102
|
+
|
|
103
|
+
### Sigmoid & Activation Functions
|
|
104
|
+
|
|
105
|
+
| Class | Formula | Parameters |
|
|
106
|
+
| :--- | :--- | :--- |
|
|
107
|
+
| `Sigmoid` | f(x) = a/(1+e^(-b(x-c))) | `a`, `b`, `c`, `x_values_list`, `y_values?` |
|
|
108
|
+
| `Logistic` | f(x) = c/(1+e^(-b(x-a))) | `a`, `b`, `c`, `x_values_list` |
|
|
109
|
+
| `GeneralizedLogistics` | f(x) = d/(1+e^(-b(x-a)))+c | `a`, `b`, `c`, `d`, `x_values_list` |
|
|
110
|
+
| `Gompertz` | f(x) = a·e^(-b·e^(-cx)) | `a`, `b`, `c`, `x_values_list`, `y_values?` |
|
|
111
|
+
| `Hill` | f(x) = Vₘₐₓ·xⁿ/(Kⁿ+xⁿ) | `vmax`, `k`, `n`, `x_values_list`, `y_values?` |
|
|
112
|
+
|
|
113
|
+
### Probability Distributions
|
|
114
|
+
|
|
115
|
+
| Class | Distribution | Parameters |
|
|
116
|
+
| :--- | :--- | :--- |
|
|
117
|
+
| `Gaussian` / `Gauss` | Normal (μ, σ) | `mu`, `sigma` / `a`, `b`, `c`, `x_values_list`, `y_values?` |
|
|
118
|
+
| `Weibull` | Weibull (k, λ) | `k`, `lambda_param`, `x_values_list`, `y_values?` |
|
|
119
|
+
| `Beta` | Beta (α, β) | `alpha`, `beta`, `x_values_list`, `y_values?` |
|
|
120
|
+
| `Gamma` | Gamma (k, θ) | `k`, `theta`, `x_values_list`, `y_values?` |
|
|
121
|
+
| `Poisson` | Poisson (λ) | `lambda_param`, `x_values_list`, `y_values?` |
|
|
122
|
+
| `ChiSquare` | χ² (df) | `df`, `x_values_list`, `y_values?` |
|
|
123
|
+
|
|
124
|
+
### Waveforms & Periodic Functions
|
|
125
|
+
|
|
126
|
+
| Class | Formula | Parameters |
|
|
127
|
+
| :--- | :--- | :--- |
|
|
128
|
+
| `SawTooth` | f(x) = a(x - 2π⌊x/2π⌋) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
129
|
+
| `SquareWave` | f(x) = a(1-2⌊x/2π⌋%2) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
130
|
+
| `Sign` | f(x) = sign(x) | `x_values_list`, `y_values?` |
|
|
131
|
+
| `Floor` | f(x) = ⌊x⌋ | `x_values_list` |
|
|
132
|
+
| `Ceil` | f(x) = ⌈x⌉ | `x_values_list` |
|
|
133
|
+
| `Triangular` | f(x) = max(0, a - \|x-b\|/c) | `a`, `b`, `c`, `x_values_list`, `y_values?` |
|
|
134
|
+
|
|
135
|
+
### Step & Impulse Functions
|
|
136
|
+
|
|
137
|
+
| Class | Formula | Parameters |
|
|
138
|
+
| :--- | :--- | :--- |
|
|
139
|
+
| `UnitStep` | f(x) = a·u(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
140
|
+
| `Heaviside` | f(x) = u(x) | `x_values_list`, `y_values?` |
|
|
141
|
+
| `DiracDelta` | f(x) = δ(x) | `x_values_list` |
|
|
142
|
+
| `TopHat` | f(x) = 1 for x∈[a,b] | `a`, `b`, `x_values_list` |
|
|
143
|
+
|
|
144
|
+
### Rational & Algebraic
|
|
145
|
+
|
|
146
|
+
| Class | Formula | Parameters |
|
|
147
|
+
| :--- | :--- | :--- |
|
|
148
|
+
| `Rational` | f(x) = a/(bx) | `a`, `b`, `x_values_list`, `y_values?` |
|
|
149
|
+
|
|
150
|
+
### Physics & Engineering
|
|
151
|
+
|
|
152
|
+
| Class | Formula | Parameters |
|
|
153
|
+
| :--- | :--- | :--- |
|
|
154
|
+
| `Planck` | Blackbody radiation | `h`, `k`, `c`, `T`, `x_values_list`, `y_values?` |
|
|
155
|
+
|
|
156
|
+
### Number-Theoretic & Recursive
|
|
157
|
+
|
|
158
|
+
| Class | Description | Parameters |
|
|
159
|
+
| :--- | :--- | :--- |
|
|
160
|
+
| `Ackermann` | Ackermann function (scatter) | `m`, `n`, `x_values_list` |
|
|
161
|
+
| `ModifiedAckermann` | Modified Ackermann (m=0..3) | `m`, `n`, `x_values_list` |
|
|
162
|
+
| `Fibonacci` | Fibonacci sequence (scatter) | `n`, `x_values_list` |
|
|
163
|
+
| `Legendre` | Legendre polynomial Pₙ(x) | `grade`, `x_values_list` |
|
|
164
|
+
|
|
165
|
+
### Free-Form Expression Evaluator
|
|
166
|
+
|
|
167
|
+
| Class | Description | Parameters |
|
|
168
|
+
| :--- | :--- | :--- |
|
|
169
|
+
| `ExpressionFunction` | Evaluate any math expression string | `expression`, `x_values_list`, `y_values?`, `variable='x'` |
|
|
170
|
+
|
|
171
|
+
## Quick Start
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pip install marksfuncs
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from marksfuncs import Exponential, Linear, PolynomialCoefficients, ExpressionFunction
|
|
179
|
+
from PIL import Image
|
|
180
|
+
|
|
181
|
+
# 1. Interactive plotting
|
|
182
|
+
Exponential(a=4, b=2, x_values_list=[-5, 5, 100]).graph()
|
|
183
|
+
|
|
184
|
+
# 2. With custom y-axis limits
|
|
185
|
+
Exponential(a=4, b=2, x_values_list=[-5, 5, 100], y_values=(-10, 10)).graph()
|
|
186
|
+
|
|
187
|
+
# 3. Programmatic image generation (PNG buffer)
|
|
188
|
+
img_buffer = Linear(m=3, b=5, x_values_list=[-5, 5, 100]).image()
|
|
189
|
+
img = Image.open(img_buffer)
|
|
190
|
+
img.save("linear.png")
|
|
191
|
+
|
|
192
|
+
# 4. Polynomial by coefficients (degree → coefficient)
|
|
193
|
+
# f(x) = 3x² + 2x + 1
|
|
194
|
+
poly = PolynomialCoefficients(
|
|
195
|
+
coefficients={0: 1, 1: 2, 2: 3}, # or [1, 2, 3]
|
|
196
|
+
x_values_list=[-5, 5, 100]
|
|
197
|
+
)
|
|
198
|
+
poly.graph()
|
|
199
|
+
|
|
200
|
+
# 5. Free-form expressions like GeoGebra!
|
|
201
|
+
expr = ExpressionFunction(
|
|
202
|
+
expression="sin(x) + x**2",
|
|
203
|
+
x_values_list=[-5, 5, 100]
|
|
204
|
+
)
|
|
205
|
+
expr.graph()
|
|
206
|
+
|
|
207
|
+
# Custom variable name
|
|
208
|
+
expr2 = ExpressionFunction(
|
|
209
|
+
expression="exp(-t)*cos(t)",
|
|
210
|
+
x_values_list=[0, 10, 200],
|
|
211
|
+
variable='t'
|
|
212
|
+
)
|
|
213
|
+
expr2.graph()
|
|
214
|
+
|
|
215
|
+
# Advanced: special functions
|
|
216
|
+
expr3 = ExpressionFunction(
|
|
217
|
+
expression="erf(x) + gamma(x+1)",
|
|
218
|
+
x_values_list=[0.1, 5, 100]
|
|
219
|
+
)
|
|
220
|
+
expr3.graph()
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Installation
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# From PyPI (when published)
|
|
227
|
+
pip install marksfuncs
|
|
228
|
+
|
|
229
|
+
# From source
|
|
230
|
+
git clone https://github.com/marc1fino/marksfuncs.git
|
|
231
|
+
cd marksfuncs
|
|
232
|
+
pip install -e .
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Requires **Python 3.8+**. Dependencies: `numpy`, `scipy`, `matplotlib`, `pillow`.
|
|
236
|
+
|
|
237
|
+
## Core API
|
|
238
|
+
|
|
239
|
+
### Common Parameters
|
|
240
|
+
|
|
241
|
+
All classes share these parameters:
|
|
242
|
+
|
|
243
|
+
| Parameter | Type | Description |
|
|
244
|
+
| :--- | :--- | :--- |
|
|
245
|
+
| `x_values_list` | `[float, float, int]` | **Required.** `[x_min, x_max, num_points]` — defines the x-axis sampling range |
|
|
246
|
+
| `y_values` | `(float, float)` | **Optional.** `(y_min, y_max)` — sets fixed y-axis limits for consistent scaling |
|
|
247
|
+
|
|
248
|
+
### Core Methods
|
|
249
|
+
|
|
250
|
+
Every class provides:
|
|
251
|
+
|
|
252
|
+
| Method | Returns | Description |
|
|
253
|
+
| :--- | :--- | :--- |
|
|
254
|
+
| `graph()` | `None` | Displays interactive Matplotlib window with the plot |
|
|
255
|
+
| `image()` | `io.BytesIO` | Returns PNG image buffer for programmatic use (save, embed, serve) |
|
|
256
|
+
|
|
257
|
+
### ExpressionFunction Namespace
|
|
258
|
+
|
|
259
|
+
`ExpressionFunction` provides a safe evaluation context with:
|
|
260
|
+
|
|
261
|
+
- **Constants**: `pi`, `e`, `inf`, `nan`
|
|
262
|
+
- **NumPy functions**: `sin`, `cos`, `tan`, `arcsin`, `arccos`, `arctan`, `sinh`, `cosh`, `tanh`, `exp`, `log`, `log10`, `log2`, `sqrt`, `cbrt`, `abs`, `floor`, `ceil`, `round`, `sign`, `heaviside`, `maximum`, `minimum`, `clip`, `power`, `mod`, `sinc`, `deg2rad`, `rad2deg`
|
|
263
|
+
- **SciPy special**: `erf`, `erfc`, `gamma`, `gammaln`, `beta`, `betaln`, `j0`, `j1`, `jn`, `yn`, `airy`
|
|
264
|
+
|
|
265
|
+
## Examples
|
|
266
|
+
|
|
267
|
+
### Basic Elementary Functions
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
from marksfuncs import Linear, Quadratic, Power, Absolute
|
|
271
|
+
|
|
272
|
+
# Linear: f(x) = 2x + 3
|
|
273
|
+
Linear(m=2, b=3, x_values_list=[-10, 10, 200]).graph()
|
|
274
|
+
|
|
275
|
+
# Quadratic: f(x) = x² - 4x + 4
|
|
276
|
+
Quadratic(a=1, b=-4, c=4, x_values_list=[-2, 6, 200]).graph()
|
|
277
|
+
|
|
278
|
+
# Power: f(x) = 2x³
|
|
279
|
+
Power(a=2, b=3, x_values_list=[-3, 3, 200]).graph()
|
|
280
|
+
|
|
281
|
+
# Absolute value: f(x) = |x - 2|
|
|
282
|
+
Absolute(a=1, b=1, x_values_list=[-5, 5, 200]).graph()
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Example: Trigonometric & Hyperbolic
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from marksfuncs import Trigonometric, Hyperbolic, HyperbolicTangent
|
|
289
|
+
|
|
290
|
+
# Sine wave: f(x) = 3sin(2x)
|
|
291
|
+
Trigonometric(a=3, b=2, x_values_list=[-2*3.14, 2*3.14, 400]).graph()
|
|
292
|
+
|
|
293
|
+
# Hyperbolic sine: f(x) = 2sinh(x)
|
|
294
|
+
Hyperbolic(a=2, b=1, x_values_list=[-3, 3, 200]).graph()
|
|
295
|
+
|
|
296
|
+
# Tanh activation: f(x) = tanh(x)
|
|
297
|
+
HyperbolicTangent(a=1, x_values_list=[-5, 5, 200]).graph()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Example: Probability Distributions
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from marksfuncs import Gaussian, Weibull, Beta, Gamma, Poisson, ChiSquare
|
|
304
|
+
|
|
305
|
+
# Normal distribution: μ=0, σ=1
|
|
306
|
+
Gaussian(mu=0, sigma=1, x_values_list=[-4, 4, 400]).graph()
|
|
307
|
+
|
|
308
|
+
# Weibull: k=2, λ=1.5
|
|
309
|
+
Weibull(k=2, lambda_param=1.5, x_values_list=[0, 5, 400]).graph()
|
|
310
|
+
|
|
311
|
+
# Beta: α=2, β=5
|
|
312
|
+
Beta(alpha=2, beta=5, x_values_list=[0, 1, 400]).graph()
|
|
313
|
+
|
|
314
|
+
# Chi-square: df=3
|
|
315
|
+
ChiSquare(df=3, x_values_list=[0, 10, 400]).graph()
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Example: Special Functions
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
from marksfuncs import BesselOrder0, BesselOrder1, Error, Airy, LogGamma
|
|
322
|
+
|
|
323
|
+
# Bessel J₀
|
|
324
|
+
BesselOrder0(x_values_list=[0, 20, 400]).graph()
|
|
325
|
+
|
|
326
|
+
# Error function
|
|
327
|
+
Error(x_values_list=[-3, 3, 400]).graph()
|
|
328
|
+
|
|
329
|
+
# Airy Ai(x)
|
|
330
|
+
Airy(x_values_list=[-10, 10, 400]).graph()
|
|
331
|
+
|
|
332
|
+
# Log Gamma
|
|
333
|
+
LogGamma(x_values_list=[0.1, 5, 400]).graph()
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Free-Form Expressions (GeoGebra-like)
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
from marksfuncs import ExpressionFunction
|
|
340
|
+
|
|
341
|
+
# Any valid mathematical expression
|
|
342
|
+
ExpressionFunction(
|
|
343
|
+
expression="sin(x)*exp(-x/5)",
|
|
344
|
+
x_values_list=[0, 20, 400]
|
|
345
|
+
).graph()
|
|
346
|
+
|
|
347
|
+
# Multiple terms
|
|
348
|
+
ExpressionFunction(
|
|
349
|
+
expression="x**3 - 3*x**2 + 2*x - 1",
|
|
350
|
+
x_values_list=[-2, 4, 400]
|
|
351
|
+
).graph()
|
|
352
|
+
|
|
353
|
+
# With special functions
|
|
354
|
+
ExpressionFunction(
|
|
355
|
+
expression="erf(x) + sin(x**2)/2",
|
|
356
|
+
x_values_list=[-3, 3, 400]
|
|
357
|
+
).graph()
|
|
358
|
+
|
|
359
|
+
# Custom variable
|
|
360
|
+
ExpressionFunction(
|
|
361
|
+
expression="cos(omega*t)*exp(-t/tau)",
|
|
362
|
+
x_values_list=[0, 10, 400],
|
|
363
|
+
variable='t'
|
|
364
|
+
).graph()
|
|
365
|
+
|
|
366
|
+
# Polar-like: r = 1 + cos(theta)
|
|
367
|
+
ExpressionFunction(
|
|
368
|
+
expression="1 + cos(x)",
|
|
369
|
+
x_values_list=[0, 2*3.14159, 400]
|
|
370
|
+
).graph()
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Polynomial by Coefficients
|
|
374
|
+
|
|
375
|
+
```python
|
|
376
|
+
from marksfuncs import PolynomialCoefficients
|
|
377
|
+
|
|
378
|
+
# f(x) = 4x⁴ - 3x³ + 2x² - x + 5
|
|
379
|
+
# Using dict (degree → coefficient)
|
|
380
|
+
poly1 = PolynomialCoefficients(
|
|
381
|
+
coefficients={0: 5, 1: -1, 2: 2, 3: -3, 4: 4},
|
|
382
|
+
x_values_list=[-2, 2, 400]
|
|
383
|
+
)
|
|
384
|
+
poly1.graph()
|
|
385
|
+
|
|
386
|
+
# Using list (index = degree)
|
|
387
|
+
poly2 = PolynomialCoefficients(
|
|
388
|
+
coefficients=[5, -1, 2, -3, 4],
|
|
389
|
+
x_values_list=[-2, 2, 400]
|
|
390
|
+
)
|
|
391
|
+
poly2.graph()
|
|
392
|
+
|
|
393
|
+
# Sparse polynomial: f(x) = x¹⁰ - 1
|
|
394
|
+
poly3 = PolynomialCoefficients(
|
|
395
|
+
coefficients={0: -1, 10: 1},
|
|
396
|
+
x_values_list=[-1.5, 1.5, 400]
|
|
397
|
+
)
|
|
398
|
+
poly3.graph()
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Image Generation for Web/Apps
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
from marksfuncs import Sigmoid, ExpressionFunction
|
|
405
|
+
from PIL import Image
|
|
406
|
+
import io
|
|
407
|
+
|
|
408
|
+
# Generate PNG for embedding
|
|
409
|
+
buf = Sigmoid(a=1, b=1, c=0, x_values_list=[-10, 10, 400]).image()
|
|
410
|
+
|
|
411
|
+
# Save to file
|
|
412
|
+
with open("sigmoid.png", "wb") as f:
|
|
413
|
+
f.write(buf.getvalue())
|
|
414
|
+
|
|
415
|
+
# Or open directly
|
|
416
|
+
img = Image.open(buf)
|
|
417
|
+
img.show()
|
|
418
|
+
|
|
419
|
+
# Expression function to image
|
|
420
|
+
buf2 = ExpressionFunction(
|
|
421
|
+
expression="1/(1+exp(-x))",
|
|
422
|
+
x_values_list=[-10, 10, 400]
|
|
423
|
+
).image()
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Project Structure
|
|
427
|
+
|
|
428
|
+
```text
|
|
429
|
+
marksfuncs/
|
|
430
|
+
├── marksfuncs/
|
|
431
|
+
│ ├── __init__.py # Exports all 50+ classes
|
|
432
|
+
│ └── functions.py # All function implementations
|
|
433
|
+
├── setup.py # Packaging configuration
|
|
434
|
+
├── README.md # This file
|
|
435
|
+
└── LICENSE # MIT License
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## Requirements
|
|
439
|
+
|
|
440
|
+
- **Python 3.8+**
|
|
441
|
+
- `numpy` ≥ 1.21
|
|
442
|
+
- `scipy` ≥ 1.7
|
|
443
|
+
- `matplotlib` ≥ 3.5
|
|
444
|
+
- `pillow` ≥ 9.0
|
|
445
|
+
|
|
446
|
+
## Development
|
|
447
|
+
|
|
448
|
+
```bash
|
|
449
|
+
git clone https://github.com/marc1fino/marksfuncs.git
|
|
450
|
+
cd marksfuncs
|
|
451
|
+
python -m venv .venv
|
|
452
|
+
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
|
|
453
|
+
pip install -e .
|
|
454
|
+
|
|
455
|
+
# Quick smoke test
|
|
456
|
+
python -c "
|
|
457
|
+
from marksfuncs import Linear, ExpressionFunction, PolynomialCoefficients
|
|
458
|
+
import numpy as np
|
|
459
|
+
|
|
460
|
+
# Test Linear
|
|
461
|
+
assert Linear(m=2, b=3, x_values_list=[0, 1, 2])._evaluate(5) == 13
|
|
462
|
+
|
|
463
|
+
# Test ExpressionFunction
|
|
464
|
+
expr = ExpressionFunction('x**2 + 1', [0, 1, 2])
|
|
465
|
+
assert abs(expr._evaluate(3) - 10) < 1e-10
|
|
466
|
+
|
|
467
|
+
# Test PolynomialCoefficients
|
|
468
|
+
poly = PolynomialCoefficients([1, 2, 3], [0, 1, 2]) # 3x²+2x+1
|
|
469
|
+
assert poly._evaluate(2) == 17
|
|
470
|
+
|
|
471
|
+
print('All tests passed!')
|
|
472
|
+
"
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## Version History
|
|
476
|
+
|
|
477
|
+
- **1.0.0** — Initial release with 40+ function classes
|
|
478
|
+
- **1.1.0** — Added `PolynomialCoefficients` and `ExpressionFunction` classes; enhanced special functions coverage
|
|
479
|
+
|
|
480
|
+
## Roadmap
|
|
481
|
+
|
|
482
|
+
- Parametric and polar plotting support
|
|
483
|
+
- 3D surface plotting (`plot_surface`)
|
|
484
|
+
- Animation support for time-varying functions
|
|
485
|
+
- LaTeX formula rendering in labels
|
|
486
|
+
- Export to SVG/PDF formats
|
|
487
|
+
- Interactive widgets (ipywidgets integration)
|
|
488
|
+
- Type hints and full mypy compatibility
|
|
489
|
+
- Comprehensive test suite with pytest
|
|
490
|
+
|
|
491
|
+
## License
|
|
492
|
+
|
|
493
|
+
Distributed under the **MIT License**. See [`LICENSE`](LICENSE) for details.
|
|
494
|
+
|
|
495
|
+
## Author
|
|
496
|
+
|
|
497
|
+
**Marc Pérez** — [GitHub](https://github.com/marc1fino)
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
*Mathematical function plotting for education, research, and engineering.*
|