k-math-kit


Namek-math-kit JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryA package with some usual math functions and objects, generally concerning numerical analysis
upload_time2024-07-11 11:52:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License
keywords analysis integration math numerical polynomial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 📐 k_math_kit 📚

Welcome to **k_math_kit**! This toolkit is designed to make advanced mathematical computations and polynomial manipulations easier for you. Whether you are a student, educator, or professional, this library will save you time and effort in performing complex mathematical operations. Created by KpihX.

## Table of Contents

1. [Features](#features)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Examples](#examples)
5. [Contributing](#contributing)
6. [License](#license)

## Features 🎉

- **Polynomial Operations**: Perform operations like addition, subtraction, and multiplication of polynomials.
- **Interpolation**: Implement Newton and Lagrange interpolation methods.
- **Integration**: Perform numerical integration using different techniques.
- **Spline Interpolation**: Generate and work with spline interpolations.
- **Taylor Series**: Compute and manipulate Taylor polynomials.

## Installation 🛠️

To get started with `k_math_kit`, you need to have Python installed on your system. You can then install the package via pip:

```sh
pip install k_math_kit
```

### Examples 🌟

#### I. Lagrange Interpolations of a given analytic function

##### 0. Definitions of Plotting parameters

```python
import numpy as np

a, b, n_plot = -2, 2, 1000
x_plot = np.linspace(a, b, n_plot)
# print("x_plot =", x_plot)
```

##### 1. Definition of f

```python
from utils import *
from math import exp

# f_exp = "cos(x)" # "1/(1+x**2)"
# def f(x):
    # return eval(f_exp, {"x": x})

f = lambda x: 1/(1+x**2)
# f = lambda x: 1/(1+exp(-x**2))

fig, ax = set_fig()
plot_f(ax, f, x_plot)
```

![png](./readme_images/output_4_0.png)

##### 2. Definition of Interpolation parameters

```python
from k_math_kit.polynomial.utils import *

n = 10

# Defintion of Uniforms points
x_uniform = np.linspace(a, b, n)
y_uniform = [f(x) for x in x_uniform]
print("Uniforms points")
print("x_uniform =", x_uniform)
print("\ny_uniform =", y_uniform)

#Definition of Tchebychev points
x_tchebychev = tchebychev_points(a, b, n)
y_tchebychev = [f(x) for x in x_tchebychev]
print("\nTchebychev points")
print("x_tchebychev =", x_tchebychev)
print("\ny_tchebychev =", y_tchebychev)
```

    Uniforms points
    x_uniform = [-2.         -1.55555556 -1.11111111 -0.66666667 -0.22222222  0.22222222
      0.66666667  1.11111111  1.55555556  2.        ]

    y_uniform = [0.2, 0.2924187725631769, 0.4475138121546961, 0.6923076923076922, 0.9529411764705883, 0.9529411764705883, 0.6923076923076924, 0.44751381215469627, 0.29241877256317694, 0.2]

    Tchebychev points
    x_tchebychev = [-1.9753766811902755, -1.7820130483767358, -1.4142135623730951, -0.9079809994790936, -0.31286893008046185, 0.3128689300804612, 0.9079809994790934, 1.414213562373095, 1.7820130483767356, 1.9753766811902753]

    y_tchebychev = [0.20399366423250215, 0.2394882325425853, 0.33333333333333326, 0.5481165495915764, 0.91084057802358, 0.9108405780235803, 0.5481165495915765, 0.33333333333333337, 0.23948823254258536, 0.20399366423250218]

##### 3. Test of Newton Lagrange Polynomial Representation

```python
from k_math_kit.polynomial.newton_poly import *

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
print("x =", x)
print("y =", y)
polynomial = NewtonInterpolPoly(x, y)
print(polynomial)

x = 11
value = polynomial.horner_eval(x)
print(f"P{x}) = {value}")
```

    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
    P(x) = 1.0 + 3.0 * (x - 1.0) + 1.0 * (x - 1.0)(x - 2.0)
    P11) = 121.0

##### 4. Uniform Lagrange Interpolation of f

```python
uni_lagrange_poly = NewtonInterpolPoly(x_uniform, y_uniform, "Uni_lagrange_poly")

print(uni_lagrange_poly)

x0 = 1
print(f"\nUni_lagrange_poly({x0}) =", uni_lagrange_poly.horner_eval(x0))

# print("\nx_uniform =", x_uniform)
# print("\ny_uniform =", y_uniform)

fig, ax = set_fig()
plot_f(ax, f, x_plot)
uni_lagrange_poly.plot(ax, x_plot, "Uniform Lagrange Interpolation of f")
```

    Uni_lagrange_poly(x) = 0.2 + 0.20794223827 * (x + 2.0) + 0.15864930092 * (x + 2.0)(x + 1.55555555556) + 0.05130066694 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111) + (-0.10772876887) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667) + (-0.04888651791) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222) + 0.1046654664 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222) + (-0.06139237133) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222)(x - 0.66666666667) + 0.01726660444 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222)(x - 0.66666666667)(x - 1.11111111111)

    Uni_lagrange_poly(1) = 0.49544474384530285

![png](./readme_images/output_10_1.png)

##### 5. Tchebychev Lagrange Interpolation of f

```python
tchebychev_lagrange_poly = NewtonInterpolPoly(x_tchebychev, y_tchebychev, "Tchebychev_lagrange_poly")

print(tchebychev_lagrange_poly)

x0 = 1
print(f"\nTchebychev_lagrange_poly({x0}) =", tchebychev_lagrange_poly.horner_eval(x0))

# print("\nx_tchebychev =", x_tchebychev)
# print("\ny_tchebychev =", y_tchebychev)

fig, ax = set_fig()
plot_f(ax, f, x_plot)

uni_lagrange_poly.plot(ax, x_plot, "Uniform Lagrange Interpolation of f")
tchebychev_lagrange_poly.plot(ax, x_plot, "Tchebychev Lagrange Interpolation of f")
```

    Tchebychev_lagrange_poly(x) = 0.20399366423 + 0.18356382632 * (x + 1.97537668119) + 0.12757264074 * (x + 1.97537668119)(x + 1.78201304838) + 0.06176433046 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237) + (-0.04751642364) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948) + (-0.05625745845) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008) + 0.063690232 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008) + (-0.03054788398) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008)(x - 0.90798099948) + 0.0081300813 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008)(x - 0.90798099948)(x - 1.41421356237)

    Tchebychev_lagrange_poly(1) = 0.4959349593495941

![png](./readme_images/output_12_1.png)

##### 6. Test of Gauss Integration

```python
from k_math_kit.integration import *

f_ = lambda x: x**2
start, end = -2, 5
gaus_int_f_ = gauss_integration(f_, -2, 5)
print(f"Gauss Integration of f_ from {start} to {end} =", gaus_int_f_)
```

    Gauss Integration of f_ from -2 to 5 = 44.33333333333334

##### 7. Errors of Lagrange Interpolations of f

```python
func_err_uniform = lambda x: (f(x) - uni_lagrange_poly.horner_eval(x))**2
func_err_tchebychev = lambda x: (f(x) - tchebychev_lagrange_poly.horner_eval(x))**2
err_uniform = sqrt(gauss_integration(func_err_uniform, a, b))
err_tchebychev = sqrt(gauss_integration(func_err_tchebychev, a, b))
print("err_uniform =", err_uniform)
print("err_tchebychev =", err_tchebychev)

fig, ax = set_fig()

plot_f(ax, f, x_plot)
uni_lagrange_poly.plot(ax, x_plot, "Uniform Lagrange Interpolation of f")
tchebychev_lagrange_poly.plot(ax, x_plot, "Tchebychev Lagrange Interpolation of f")

y_uni_plot = [func_err_uniform(x) for x  in x_plot]
ax.plot(x_plot, y_uni_plot, label="Error of Uniform Lagrange Interpolation of f")

y_tche_plot = [func_err_tchebychev(x) for x  in x_plot]
ax.plot(x_plot, y_tche_plot, label="Error of Tchebychev Lagrange Interpolation of f")

ax.legend()

```

    err_uniform = 0.044120898850020976
    err_tchebychev = 0.008834019736683135

    <matplotlib.legend.Legend at 0x780c4001dad0>

![png](./readme_images/output_14_2.png)


### Spline Interpolations of a given analytic function

#### 0. Definitions of Plotting parameters

```python
import numpy as np

a, b, n_plot = -1, 1, 1000
x_plot = np.linspace(a, b, n_plot)
# print("x_plot =", x_plot)
```

#### 1. Definition of f

```python
from utils import *

# f_exp = "cos(x)" # "1/(1+x**2)"
# def f(x):
    # return eval(f_exp, {"x": x})

f = lambda x: 1/(2+x**3)

fig, ax = set_fig()
plot_f(ax, f, x_plot)
```

![png](./readme_images/output_4_0_2.png)

#### 2. Definition of Interpolation parameters

```python
n = 10

# Defintion of Uniforms points
x_uniform = np.linspace(a, b, n)
y_uniform = [f(x) for x in x_uniform]
print("Uniforms points")
print("x_uniform =", x_uniform)
print("\ny_uniform =", y_uniform)
```

    Uniforms points
    x_uniform = [-1.         -0.77777778 -0.55555556 -0.33333333 -0.11111111  0.11111111
      0.33333333  0.55555556  0.77777778  1.        ]

    y_uniform = [1.0, 0.6538116591928251, 0.5468867216804201, 0.5094339622641509, 0.5003431708991077, 0.49965729952021937, 0.49090909090909085, 0.46051800379027164, 0.40477512493059414, 0.3333333333333333]

#### 3. Test of Linear Spline Interpolation

```python
from k_math_kit.polynomial.newton_poly import  Spline1Poly

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
print("x =", x)
print("y =", y)
polynomial = Spline1Poly(x, y)
print(polynomial)

x = 1.5
value = polynomial.horner_eval(x)
print(f"P({x}) = {value}")
```

    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
    P(x) =	 1.0 + 3.0 * (x - 1.0)   if x in [1.0, 2.0]
    	 4.0 + 5.0 * (x - 2.0)   if x in [2.0, 3.0]
    	 9.0 + 7.0 * (x - 3.0)   if x in [3.0, 4.0]
    	 16.0 + 9.0 * (x - 4.0)   if x in [4.0, 5.0]
    	 25.0 + 11.0 * (x - 5.0)   if x in [5.0, 6.0]
    	 36.0 + 13.0 * (x - 6.0)   if x in [6.0, 7.0]
    	 49.0 + 15.0 * (x - 7.0)   if x in [7.0, 8.0]
    	 64.0 + 17.0 * (x - 8.0)   if x in [8.0, 9.0]
    	 81.0 + 19.0 * (x - 9.0)   if x in [9.0, 10.0]

    P(1.5) = 2.5

#### 4. Uniform Linear Spline Interpolation of f

```python
uni_linear_spline_poly = Spline1Poly(x_uniform, y_uniform, "Uni_linear_spline_poly")

print(uni_linear_spline_poly)

x0 = 1
print(f"\nUni_linear_spline_poly({x0}) =", uni_linear_spline_poly.horner_eval(x0))

# print("\nx_uniform =", x_uniform)
# print("\ny_uniform =", y_uniform)

fig, ax = set_fig()
plot_f(ax, f, x_plot)

uni_linear_spline_poly.plot(ax, "Uniform Linear Spline Interpolation of f")
```

    Uni_linear_spline_poly(x) =	 1.0 + (-1.55784753363) * (x + 1.0)   if x in [-1.0, -0.7777777777777778]
    	 0.65381165919 + (-0.48116221881) * (x + 0.77777777778)   if x in [-0.7777777777777778, -0.5555555555555556]
    	 0.54688672168 + (-0.16853741737) * (x + 0.55555555556)   if x in [-0.5555555555555556, -0.33333333333333337]
    	 0.50943396226 + (-0.04090856114) * (x + 0.33333333333)   if x in [-0.33333333333333337, -0.11111111111111116]
    	 0.5003431709 + (-0.0030864212) * (x + 0.11111111111)   if x in [-0.11111111111111116, 0.11111111111111116]
    	 0.49965729952 + (-0.03936693875) * (x - 0.11111111111)   if x in [0.11111111111111116, 0.33333333333333326]
    	 0.49090909091 + (-0.13675989203) * (x - 0.33333333333)   if x in [0.33333333333333326, 0.5555555555555554]
    	 0.46051800379 + (-0.25084295487) * (x - 0.55555555556)   if x in [0.5555555555555554, 0.7777777777777777]
    	 0.40477512493 + (-0.32148806219) * (x - 0.77777777778)   if x in [0.7777777777777777, 1.0]

    Uni_linear_spline_poly(1) = 0.3333333333333333

![png](./readme_images/output_10_1_2.png)

#### 5. Uniform Cubic Spline Interpolation of f

```python
from k_math_kit.polynomial.taylor_poly import Spline3Polys
    
uni_spline3_poly = Spline3Polys(x_uniform, y_uniform, "Uni_spline3_poly")

print(uni_spline3_poly)

x0 = 1
print(f"\nUni_spline3_poly({x0}) =", uni_spline3_poly.horner_eval(x0))

fig, ax = set_fig()
plot_f(ax, f, x_plot)

# print("\nx_uniform =", x_uniform)
# print("\ny_uniform =", y_uniform)

uni_linear_spline_poly.plot(ax, "Uniform Linear Spline Interpolation of f")
uni_spline3_poly.plot(ax, n_plot, "Uniform Cubic Spline Interpolation of f")
```

    Uni_spline3_poly(x) =	 1.0 + (-1.826136) * (x + 1.0) + 5.432837 * (x + 1.0)^3   if x in [-1.0, -0.7777777777777778]
    	 0.653812 + (-1.021271) * (x + 0.777778) + 3.621892 * (x + 0.777778)^2 + (-5.361309) * (x + 0.777778)^3   if x in [-0.7777777777777778, -0.5555555555555556]
    	 0.546887 + (-0.205809) * (x + 0.555556) + 0.047686 * (x + 0.555556)^2 + 0.540173 * (x + 0.555556)^3   if x in [-0.5555555555555556, -0.33333333333333337]
    	 0.509434 + (-0.10459) * (x + 0.333333) + 0.407801 * (x + 0.333333)^2 + (-0.545553) * (x + 0.333333)^3   if x in [-0.33333333333333337, -0.11111111111111116]
    	 0.500343 + (-0.004168) * (x + 0.111111) + 0.044099 * (x + 0.111111)^2 + (-0.176549) * (x + 0.111111)^3   if x in [-0.11111111111111116, 0.11111111111111116]
    	 0.499657 + (-0.010723) * (x - 0.111111) + (-0.0736) * (x - 0.111111)^2 + (-0.248832) * (x - 0.111111)^3   if x in [0.11111111111111116, 0.33333333333333326]
    	 0.490909 + (-0.080298) * (x - 0.333333) + (-0.239488) * (x - 0.333333)^2 + (-0.065651) * (x - 0.333333)^3   if x in [0.33333333333333326, 0.5555555555555554]
    	 0.460518 + (-0.196463) * (x - 0.555556) + (-0.283255) * (x - 0.555556)^2 + 0.173462 * (x - 0.555556)^3   if x in [0.5555555555555554, 0.7777777777777777]
    	 0.404775 + (-0.296656) * (x - 0.777778) + (-0.167613) * (x - 0.777778)^2 + 0.25142 * (x - 0.777778)^3   if x in [0.7777777777777777, 1.0]

    Uni_spline3_poly(1) = 0.3333333333333333

![png](./readme_images/output_12_1_2.png)

#### 6. Errors of SPline Interpolations of f

```python
from k_math_kit.integration import gauss_integration

func_err_spline1 = lambda x: (f(x) - uni_linear_spline_poly.horner_eval(x))**2
func_err_spline3 = lambda x: (f(x) - uni_spline3_poly.horner_eval(x))**2
err_spline1 = sqrt(gauss_integration(func_err_spline1, a, b))
err_spline3 = sqrt(gauss_integration(func_err_spline3, a, b))
print("err_spline1 =", err_spline1)
print("err_spline3 =", err_spline3)

fig, ax = set_fig()

plot_f(ax, f, x_plot)
uni_linear_spline_poly.plot(ax, "Uniform Linear Spline Interpolation of f")
uni_spline3_poly.plot(ax, n_plot, "Uniform Cubic Spline Interpolation of f")

y_uni_plot = [func_err_spline1(x) for x  in x_plot]
ax.plot(x_plot, y_uni_plot, label="Error of Uniform Linear Spline Interpolation of f")

y_tche_plot = [func_err_spline3(x) for x  in x_plot]
ax.plot(x_plot, y_tche_plot, label="Error of Uniform Cubic Spline Interpolation of f")

ax.legend()

```

    err_spline1 = 0.0006928093124588687
    err_spline3 = 0.0005946540406200942

    <matplotlib.legend.Legend at 0x70aea7f31190>

![png](./readme_images/output_14_2_2.png)



For more dynamic tests, check out the `tests` directory, which contains Jupyter notebooks demonstrating various functionalities:

- `lagrange_interpolations.ipynb`
- `spline_interpolations.ipynb`

## Contributing 🤝

We welcome contributions to enhance the functionality of `k_math_kit`. If you have any ideas or improvements, please feel free to fork the repository and submit a pull request. For major changes, please open an issue to discuss what you would like to change.

### Steps to Contribute

1. Fork the repository.
2. Create your feature branch: `git checkout -b feature/your-feature-name`
3. Commit your changes: `git commit -m 'Add some feature'`
4. Push to the branch: `git push origin feature/your-feature-name`
5. Open a pull request.

## License 📜

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

---

Feel free to reach out if you have any questions or feedback. Happy computing! 😊

---

## Author

**KpihX**

---

**Enjoy using k_math_kit and happy computing!** 🧮✨

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "k-math-kit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "KpihX <kapoivha@gmail.com>",
    "keywords": "analysis, integration, math, numerical, polynomial",
    "author": null,
    "author_email": "KpihX <kapoivha@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a1/ea/e28b5e5b135b7973f101e8576b9e55ba7c85df6ffe8ab2c987ce4629a0b9/k_math_kit-0.0.2.tar.gz",
    "platform": null,
    "description": "# \ud83d\udcd0 k_math_kit \ud83d\udcda\n\nWelcome to **k_math_kit**! This toolkit is designed to make advanced mathematical computations and polynomial manipulations easier for you. Whether you are a student, educator, or professional, this library will save you time and effort in performing complex mathematical operations. Created by KpihX.\n\n## Table of Contents\n\n1. [Features](#features)\n2. [Installation](#installation)\n3. [Usage](#usage)\n4. [Examples](#examples)\n5. [Contributing](#contributing)\n6. [License](#license)\n\n## Features \ud83c\udf89\n\n- **Polynomial Operations**: Perform operations like addition, subtraction, and multiplication of polynomials.\n- **Interpolation**: Implement Newton and Lagrange interpolation methods.\n- **Integration**: Perform numerical integration using different techniques.\n- **Spline Interpolation**: Generate and work with spline interpolations.\n- **Taylor Series**: Compute and manipulate Taylor polynomials.\n\n## Installation \ud83d\udee0\ufe0f\n\nTo get started with `k_math_kit`, you need to have Python installed on your system. You can then install the package via pip:\n\n```sh\npip install k_math_kit\n```\n\n### Examples \ud83c\udf1f\n\n#### I. Lagrange Interpolations of a given analytic function\n\n##### 0. Definitions of Plotting parameters\n\n```python\nimport numpy as np\n\na, b, n_plot = -2, 2, 1000\nx_plot = np.linspace(a, b, n_plot)\n# print(\"x_plot =\", x_plot)\n```\n\n##### 1. Definition of f\n\n```python\nfrom utils import *\nfrom math import exp\n\n# f_exp = \"cos(x)\" # \"1/(1+x**2)\"\n# def f(x):\n    # return eval(f_exp, {\"x\": x})\n\nf = lambda x: 1/(1+x**2)\n# f = lambda x: 1/(1+exp(-x**2))\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\n```\n\n![png](./readme_images/output_4_0.png)\n\n##### 2. Definition of Interpolation parameters\n\n```python\nfrom k_math_kit.polynomial.utils import *\n\nn = 10\n\n# Defintion of Uniforms points\nx_uniform = np.linspace(a, b, n)\ny_uniform = [f(x) for x in x_uniform]\nprint(\"Uniforms points\")\nprint(\"x_uniform =\", x_uniform)\nprint(\"\\ny_uniform =\", y_uniform)\n\n#Definition of Tchebychev points\nx_tchebychev = tchebychev_points(a, b, n)\ny_tchebychev = [f(x) for x in x_tchebychev]\nprint(\"\\nTchebychev points\")\nprint(\"x_tchebychev =\", x_tchebychev)\nprint(\"\\ny_tchebychev =\", y_tchebychev)\n```\n\n    Uniforms points\n    x_uniform = [-2.         -1.55555556 -1.11111111 -0.66666667 -0.22222222  0.22222222\n      0.66666667  1.11111111  1.55555556  2.        ]\n\n    y_uniform = [0.2, 0.2924187725631769, 0.4475138121546961, 0.6923076923076922, 0.9529411764705883, 0.9529411764705883, 0.6923076923076924, 0.44751381215469627, 0.29241877256317694, 0.2]\n\n    Tchebychev points\n    x_tchebychev = [-1.9753766811902755, -1.7820130483767358, -1.4142135623730951, -0.9079809994790936, -0.31286893008046185, 0.3128689300804612, 0.9079809994790934, 1.414213562373095, 1.7820130483767356, 1.9753766811902753]\n\n    y_tchebychev = [0.20399366423250215, 0.2394882325425853, 0.33333333333333326, 0.5481165495915764, 0.91084057802358, 0.9108405780235803, 0.5481165495915765, 0.33333333333333337, 0.23948823254258536, 0.20399366423250218]\n\n##### 3. Test of Newton Lagrange Polynomial Representation\n\n```python\nfrom k_math_kit.polynomial.newton_poly import *\n\nx = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\ny = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\nprint(\"x =\", x)\nprint(\"y =\", y)\npolynomial = NewtonInterpolPoly(x, y)\nprint(polynomial)\n\nx = 11\nvalue = polynomial.horner_eval(x)\nprint(f\"P{x}) = {value}\")\n```\n\n    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n    y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n    P(x) = 1.0 + 3.0 * (x - 1.0) + 1.0 * (x - 1.0)(x - 2.0)\n    P11) = 121.0\n\n##### 4. Uniform Lagrange Interpolation of f\n\n```python\nuni_lagrange_poly = NewtonInterpolPoly(x_uniform, y_uniform, \"Uni_lagrange_poly\")\n\nprint(uni_lagrange_poly)\n\nx0 = 1\nprint(f\"\\nUni_lagrange_poly({x0}) =\", uni_lagrange_poly.horner_eval(x0))\n\n# print(\"\\nx_uniform =\", x_uniform)\n# print(\"\\ny_uniform =\", y_uniform)\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\nuni_lagrange_poly.plot(ax, x_plot, \"Uniform Lagrange Interpolation of f\")\n```\n\n    Uni_lagrange_poly(x) = 0.2 + 0.20794223827 * (x + 2.0) + 0.15864930092 * (x + 2.0)(x + 1.55555555556) + 0.05130066694 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111) + (-0.10772876887) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667) + (-0.04888651791) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222) + 0.1046654664 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222) + (-0.06139237133) * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222)(x - 0.66666666667) + 0.01726660444 * (x + 2.0)(x + 1.55555555556)(x + 1.11111111111)(x + 0.66666666667)(x + 0.22222222222)(x - 0.22222222222)(x - 0.66666666667)(x - 1.11111111111)\n\n    Uni_lagrange_poly(1) = 0.49544474384530285\n\n![png](./readme_images/output_10_1.png)\n\n##### 5. Tchebychev Lagrange Interpolation of f\n\n```python\ntchebychev_lagrange_poly = NewtonInterpolPoly(x_tchebychev, y_tchebychev, \"Tchebychev_lagrange_poly\")\n\nprint(tchebychev_lagrange_poly)\n\nx0 = 1\nprint(f\"\\nTchebychev_lagrange_poly({x0}) =\", tchebychev_lagrange_poly.horner_eval(x0))\n\n# print(\"\\nx_tchebychev =\", x_tchebychev)\n# print(\"\\ny_tchebychev =\", y_tchebychev)\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\n\nuni_lagrange_poly.plot(ax, x_plot, \"Uniform Lagrange Interpolation of f\")\ntchebychev_lagrange_poly.plot(ax, x_plot, \"Tchebychev Lagrange Interpolation of f\")\n```\n\n    Tchebychev_lagrange_poly(x) = 0.20399366423 + 0.18356382632 * (x + 1.97537668119) + 0.12757264074 * (x + 1.97537668119)(x + 1.78201304838) + 0.06176433046 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237) + (-0.04751642364) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948) + (-0.05625745845) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008) + 0.063690232 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008) + (-0.03054788398) * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008)(x - 0.90798099948) + 0.0081300813 * (x + 1.97537668119)(x + 1.78201304838)(x + 1.41421356237)(x + 0.90798099948)(x + 0.31286893008)(x - 0.31286893008)(x - 0.90798099948)(x - 1.41421356237)\n\n    Tchebychev_lagrange_poly(1) = 0.4959349593495941\n\n![png](./readme_images/output_12_1.png)\n\n##### 6. Test of Gauss Integration\n\n```python\nfrom k_math_kit.integration import *\n\nf_ = lambda x: x**2\nstart, end = -2, 5\ngaus_int_f_ = gauss_integration(f_, -2, 5)\nprint(f\"Gauss Integration of f_ from {start} to {end} =\", gaus_int_f_)\n```\n\n    Gauss Integration of f_ from -2 to 5 = 44.33333333333334\n\n##### 7. Errors of Lagrange Interpolations of f\n\n```python\nfunc_err_uniform = lambda x: (f(x) - uni_lagrange_poly.horner_eval(x))**2\nfunc_err_tchebychev = lambda x: (f(x) - tchebychev_lagrange_poly.horner_eval(x))**2\nerr_uniform = sqrt(gauss_integration(func_err_uniform, a, b))\nerr_tchebychev = sqrt(gauss_integration(func_err_tchebychev, a, b))\nprint(\"err_uniform =\", err_uniform)\nprint(\"err_tchebychev =\", err_tchebychev)\n\nfig, ax = set_fig()\n\nplot_f(ax, f, x_plot)\nuni_lagrange_poly.plot(ax, x_plot, \"Uniform Lagrange Interpolation of f\")\ntchebychev_lagrange_poly.plot(ax, x_plot, \"Tchebychev Lagrange Interpolation of f\")\n\ny_uni_plot = [func_err_uniform(x) for x  in x_plot]\nax.plot(x_plot, y_uni_plot, label=\"Error of Uniform Lagrange Interpolation of f\")\n\ny_tche_plot = [func_err_tchebychev(x) for x  in x_plot]\nax.plot(x_plot, y_tche_plot, label=\"Error of Tchebychev Lagrange Interpolation of f\")\n\nax.legend()\n\n```\n\n    err_uniform = 0.044120898850020976\n    err_tchebychev = 0.008834019736683135\n\n    <matplotlib.legend.Legend at 0x780c4001dad0>\n\n![png](./readme_images/output_14_2.png)\n\n\n### Spline Interpolations of a given analytic function\n\n#### 0. Definitions of Plotting parameters\n\n```python\nimport numpy as np\n\na, b, n_plot = -1, 1, 1000\nx_plot = np.linspace(a, b, n_plot)\n# print(\"x_plot =\", x_plot)\n```\n\n#### 1. Definition of f\n\n```python\nfrom utils import *\n\n# f_exp = \"cos(x)\" # \"1/(1+x**2)\"\n# def f(x):\n    # return eval(f_exp, {\"x\": x})\n\nf = lambda x: 1/(2+x**3)\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\n```\n\n![png](./readme_images/output_4_0_2.png)\n\n#### 2. Definition of Interpolation parameters\n\n```python\nn = 10\n\n# Defintion of Uniforms points\nx_uniform = np.linspace(a, b, n)\ny_uniform = [f(x) for x in x_uniform]\nprint(\"Uniforms points\")\nprint(\"x_uniform =\", x_uniform)\nprint(\"\\ny_uniform =\", y_uniform)\n```\n\n    Uniforms points\n    x_uniform = [-1.         -0.77777778 -0.55555556 -0.33333333 -0.11111111  0.11111111\n      0.33333333  0.55555556  0.77777778  1.        ]\n\n    y_uniform = [1.0, 0.6538116591928251, 0.5468867216804201, 0.5094339622641509, 0.5003431708991077, 0.49965729952021937, 0.49090909090909085, 0.46051800379027164, 0.40477512493059414, 0.3333333333333333]\n\n#### 3. Test of Linear Spline Interpolation\n\n```python\nfrom k_math_kit.polynomial.newton_poly import  Spline1Poly\n\nx = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\ny = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\nprint(\"x =\", x)\nprint(\"y =\", y)\npolynomial = Spline1Poly(x, y)\nprint(polynomial)\n\nx = 1.5\nvalue = polynomial.horner_eval(x)\nprint(f\"P({x}) = {value}\")\n```\n\n    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n    y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n    P(x) =\t 1.0 + 3.0 * (x - 1.0)   if x in [1.0, 2.0]\n    \t 4.0 + 5.0 * (x - 2.0)   if x in [2.0, 3.0]\n    \t 9.0 + 7.0 * (x - 3.0)   if x in [3.0, 4.0]\n    \t 16.0 + 9.0 * (x - 4.0)   if x in [4.0, 5.0]\n    \t 25.0 + 11.0 * (x - 5.0)   if x in [5.0, 6.0]\n    \t 36.0 + 13.0 * (x - 6.0)   if x in [6.0, 7.0]\n    \t 49.0 + 15.0 * (x - 7.0)   if x in [7.0, 8.0]\n    \t 64.0 + 17.0 * (x - 8.0)   if x in [8.0, 9.0]\n    \t 81.0 + 19.0 * (x - 9.0)   if x in [9.0, 10.0]\n\n    P(1.5) = 2.5\n\n#### 4. Uniform Linear Spline Interpolation of f\n\n```python\nuni_linear_spline_poly = Spline1Poly(x_uniform, y_uniform, \"Uni_linear_spline_poly\")\n\nprint(uni_linear_spline_poly)\n\nx0 = 1\nprint(f\"\\nUni_linear_spline_poly({x0}) =\", uni_linear_spline_poly.horner_eval(x0))\n\n# print(\"\\nx_uniform =\", x_uniform)\n# print(\"\\ny_uniform =\", y_uniform)\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\n\nuni_linear_spline_poly.plot(ax, \"Uniform Linear Spline Interpolation of f\")\n```\n\n    Uni_linear_spline_poly(x) =\t 1.0 + (-1.55784753363) * (x + 1.0)   if x in [-1.0, -0.7777777777777778]\n    \t 0.65381165919 + (-0.48116221881) * (x + 0.77777777778)   if x in [-0.7777777777777778, -0.5555555555555556]\n    \t 0.54688672168 + (-0.16853741737) * (x + 0.55555555556)   if x in [-0.5555555555555556, -0.33333333333333337]\n    \t 0.50943396226 + (-0.04090856114) * (x + 0.33333333333)   if x in [-0.33333333333333337, -0.11111111111111116]\n    \t 0.5003431709 + (-0.0030864212) * (x + 0.11111111111)   if x in [-0.11111111111111116, 0.11111111111111116]\n    \t 0.49965729952 + (-0.03936693875) * (x - 0.11111111111)   if x in [0.11111111111111116, 0.33333333333333326]\n    \t 0.49090909091 + (-0.13675989203) * (x - 0.33333333333)   if x in [0.33333333333333326, 0.5555555555555554]\n    \t 0.46051800379 + (-0.25084295487) * (x - 0.55555555556)   if x in [0.5555555555555554, 0.7777777777777777]\n    \t 0.40477512493 + (-0.32148806219) * (x - 0.77777777778)   if x in [0.7777777777777777, 1.0]\n\n    Uni_linear_spline_poly(1) = 0.3333333333333333\n\n![png](./readme_images/output_10_1_2.png)\n\n#### 5. Uniform Cubic Spline Interpolation of f\n\n```python\nfrom k_math_kit.polynomial.taylor_poly import Spline3Polys\n    \nuni_spline3_poly = Spline3Polys(x_uniform, y_uniform, \"Uni_spline3_poly\")\n\nprint(uni_spline3_poly)\n\nx0 = 1\nprint(f\"\\nUni_spline3_poly({x0}) =\", uni_spline3_poly.horner_eval(x0))\n\nfig, ax = set_fig()\nplot_f(ax, f, x_plot)\n\n# print(\"\\nx_uniform =\", x_uniform)\n# print(\"\\ny_uniform =\", y_uniform)\n\nuni_linear_spline_poly.plot(ax, \"Uniform Linear Spline Interpolation of f\")\nuni_spline3_poly.plot(ax, n_plot, \"Uniform Cubic Spline Interpolation of f\")\n```\n\n    Uni_spline3_poly(x) =\t 1.0 + (-1.826136) * (x + 1.0) + 5.432837 * (x + 1.0)^3   if x in [-1.0, -0.7777777777777778]\n    \t 0.653812 + (-1.021271) * (x + 0.777778) + 3.621892 * (x + 0.777778)^2 + (-5.361309) * (x + 0.777778)^3   if x in [-0.7777777777777778, -0.5555555555555556]\n    \t 0.546887 + (-0.205809) * (x + 0.555556) + 0.047686 * (x + 0.555556)^2 + 0.540173 * (x + 0.555556)^3   if x in [-0.5555555555555556, -0.33333333333333337]\n    \t 0.509434 + (-0.10459) * (x + 0.333333) + 0.407801 * (x + 0.333333)^2 + (-0.545553) * (x + 0.333333)^3   if x in [-0.33333333333333337, -0.11111111111111116]\n    \t 0.500343 + (-0.004168) * (x + 0.111111) + 0.044099 * (x + 0.111111)^2 + (-0.176549) * (x + 0.111111)^3   if x in [-0.11111111111111116, 0.11111111111111116]\n    \t 0.499657 + (-0.010723) * (x - 0.111111) + (-0.0736) * (x - 0.111111)^2 + (-0.248832) * (x - 0.111111)^3   if x in [0.11111111111111116, 0.33333333333333326]\n    \t 0.490909 + (-0.080298) * (x - 0.333333) + (-0.239488) * (x - 0.333333)^2 + (-0.065651) * (x - 0.333333)^3   if x in [0.33333333333333326, 0.5555555555555554]\n    \t 0.460518 + (-0.196463) * (x - 0.555556) + (-0.283255) * (x - 0.555556)^2 + 0.173462 * (x - 0.555556)^3   if x in [0.5555555555555554, 0.7777777777777777]\n    \t 0.404775 + (-0.296656) * (x - 0.777778) + (-0.167613) * (x - 0.777778)^2 + 0.25142 * (x - 0.777778)^3   if x in [0.7777777777777777, 1.0]\n\n    Uni_spline3_poly(1) = 0.3333333333333333\n\n![png](./readme_images/output_12_1_2.png)\n\n#### 6. Errors of SPline Interpolations of f\n\n```python\nfrom k_math_kit.integration import gauss_integration\n\nfunc_err_spline1 = lambda x: (f(x) - uni_linear_spline_poly.horner_eval(x))**2\nfunc_err_spline3 = lambda x: (f(x) - uni_spline3_poly.horner_eval(x))**2\nerr_spline1 = sqrt(gauss_integration(func_err_spline1, a, b))\nerr_spline3 = sqrt(gauss_integration(func_err_spline3, a, b))\nprint(\"err_spline1 =\", err_spline1)\nprint(\"err_spline3 =\", err_spline3)\n\nfig, ax = set_fig()\n\nplot_f(ax, f, x_plot)\nuni_linear_spline_poly.plot(ax, \"Uniform Linear Spline Interpolation of f\")\nuni_spline3_poly.plot(ax, n_plot, \"Uniform Cubic Spline Interpolation of f\")\n\ny_uni_plot = [func_err_spline1(x) for x  in x_plot]\nax.plot(x_plot, y_uni_plot, label=\"Error of Uniform Linear Spline Interpolation of f\")\n\ny_tche_plot = [func_err_spline3(x) for x  in x_plot]\nax.plot(x_plot, y_tche_plot, label=\"Error of Uniform Cubic Spline Interpolation of f\")\n\nax.legend()\n\n```\n\n    err_spline1 = 0.0006928093124588687\n    err_spline3 = 0.0005946540406200942\n\n    <matplotlib.legend.Legend at 0x70aea7f31190>\n\n![png](./readme_images/output_14_2_2.png)\n\n\n\nFor more dynamic tests, check out the `tests` directory, which contains Jupyter notebooks demonstrating various functionalities:\n\n- `lagrange_interpolations.ipynb`\n- `spline_interpolations.ipynb`\n\n## Contributing \ud83e\udd1d\n\nWe welcome contributions to enhance the functionality of `k_math_kit`. If you have any ideas or improvements, please feel free to fork the repository and submit a pull request. For major changes, please open an issue to discuss what you would like to change.\n\n### Steps to Contribute\n\n1. Fork the repository.\n2. Create your feature branch: `git checkout -b feature/your-feature-name`\n3. Commit your changes: `git commit -m 'Add some feature'`\n4. Push to the branch: `git push origin feature/your-feature-name`\n5. Open a pull request.\n\n## License \ud83d\udcdc\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\n---\n\nFeel free to reach out if you have any questions or feedback. Happy computing! \ud83d\ude0a\n\n---\n\n## Author\n\n**KpihX**\n\n---\n\n**Enjoy using k_math_kit and happy computing!** \ud83e\uddee\u2728\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A package with some usual math functions and objects, generally concerning numerical analysis",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://pypi.org/project/k-math-kit/",
        "Issues": "https://github.com/KpihX/k_math_kit/issues",
        "Repository": "https://github.com/KpihX/k_math_kit.git"
    },
    "split_keywords": [
        "analysis",
        " integration",
        " math",
        " numerical",
        " polynomial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23875cad681697af94dfc46c54617e8cb456a15678f9bc379f1682be7eb82907",
                "md5": "2d177bcec759454c42ea45f9127dd5a0",
                "sha256": "06671194ab74bfb4205140b329dbaaf5fb541b379db422cb82caaa8bdfb82373"
            },
            "downloads": -1,
            "filename": "k_math_kit-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2d177bcec759454c42ea45f9127dd5a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15313,
            "upload_time": "2024-07-11T11:51:59",
            "upload_time_iso_8601": "2024-07-11T11:51:59.357599Z",
            "url": "https://files.pythonhosted.org/packages/23/87/5cad681697af94dfc46c54617e8cb456a15678f9bc379f1682be7eb82907/k_math_kit-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1eae28b5e5b135b7973f101e8576b9e55ba7c85df6ffe8ab2c987ce4629a0b9",
                "md5": "fb6cf8c8bb28516684694fc70817d5c7",
                "sha256": "e598a65ba345c564859992233ee365b90e6cbbbc410b087d49bd0451720ccd5d"
            },
            "downloads": -1,
            "filename": "k_math_kit-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "fb6cf8c8bb28516684694fc70817d5c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 508385,
            "upload_time": "2024-07-11T11:52:03",
            "upload_time_iso_8601": "2024-07-11T11:52:03.665367Z",
            "url": "https://files.pythonhosted.org/packages/a1/ea/e28b5e5b135b7973f101e8576b9e55ba7c85df6ffe8ab2c987ce4629a0b9/k_math_kit-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-11 11:52:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "KpihX",
    "github_project": "k_math_kit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "k-math-kit"
}
        
Elapsed time: 5.16114s