https://github.com/pykit3/k3math
k3math is a toy math impl
https://github.com/pykit3/k3math
math python3
Last synced: 4 months ago
JSON representation
k3math is a toy math impl
- Host: GitHub
- URL: https://github.com/pykit3/k3math
- Owner: pykit3
- License: mit
- Created: 2020-11-18T08:58:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-08-28T12:37:23.000Z (9 months ago)
- Last Synced: 2025-08-29T02:28:26.101Z (9 months ago)
- Topics: math, python3
- Language: Python
- Homepage: https://blog.openacid.com
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# k3math
[](https://github.com/pykit3/k3math/actions/workflows/python-package.yml)
[](https://k3math.readthedocs.io/en/stable/?badge=stable)
[](https://pypi.org/project/k3math)
no desc
k3math is a component of [pykit3] project: a python3 toolkit set.
# Install
```
pip install k3math
```
# Synopsis
```python
xs = [1, 2, 3, 4]
ys = [6, 5, 7, 10]
# Fit polynomial curve with 4 points, at degree 0, 1, 2, 3:
for deg in (0, 1, 2, 3):
poly = Polynomial.fit(xs, ys, degree=deg)
print 'y =', poly
# Evaluate y(5) with polynomial
y5 = Polynomial.evaluate(poly, 5)
print 'y(5) =', y5
# Plot the curve and points
lines = Polynomial.plot([(poly, '.')], (-1, 6),
width=30, height=10,
points=zip(xs + [5],
ys + [y5],
['X', 'X', 'X', 'X', '*']))
for l in lines:
print l
# y = 7
# y(5) = 7.0
# X
#
#
#
# ...............X.........*....
# X
# X
# y = 3.5 + 1.4x
# y(5) = 10.5
# .
# *...
# X....
# .....
# .....X
# X....X
# .....
# y = 8.5 - 3.6x + x²
# y(5) = 15.5
# .
# .
# ..
# .*
# ...
# .. ...X
# ...X....X....X.
# y = 12 - 9.166667x + 3.5x² - 0.333333x³
# y(5) = 12.0
#
# . ...*....
# . X.
# . ..
# . ..
# . .X
# X....X...
```
# Author
Zhang Yanpo (张炎泼)
# Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼)
[pykit3]: https://github.com/pykit3