W4 Method for Nonlinear Root Finding
Project description
W4
This package provides the W4 method for nonlinear root finding, inspired by the R implementation.
Install
create a virtual environment, activate it and upgrade pip:
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
install from pypi:
pip install w4
or from github repo:
pip install git+https://github.com/gmagno/w4
Usage
import numpy as np
from w4.w4 import w4
from w4.xy import Decomposition
x0: np.ndarray = np.array([0.5, 5.0])
def f(x: np.ndarray) -> np.ndarray:
return np.array([x[0] ** 2 + x[1] ** 2 - 4, x[0] ** 2 * x[1] - 1])
def fa(x: np.ndarray) -> np.ndarray:
return np.array(
[abs(x[0] ** 2) + abs(x[1] ** 2) + abs(-4), abs(x[0] ** 2 * x[1]) + abs(-1)]
)
def jac(x: np.ndarray) -> np.ndarray:
return np.array([[2 * x[0], 2 * x[1]], [2 * x[0] * x[1], x[0] ** 2]])
solution: np.ndarray = w4(
x0=x0, f=f, fa=fa, jac=jac, decomposition=Decomposition.LU, trace=True
)
print(solution)
Output:
[( 0, 7.26495726e-01, 0.5 , 5. )
( 1, 7.26495726e-01, 0.51413317, 4.46733668)
( 2, 6.69713968e-01, 0.52954179, 3.8709697 )
( 3, 5.84735305e-01, 0.54795009, 3.34463474)
( 4, 4.83432079e-01, 0.57024824, 2.91997823)
( 5, 3.77502437e-01, 0.5956425 , 2.59451865)
( 6, 2.78389751e-01, 0.6222772 , 2.3546681 )
( 7, 1.94497674e-01, 0.64795729, 2.18404118)
( 8, 1.29477634e-01, 0.67078251, 2.06671229)
( 9, 8.27001827e-02, 0.68957129, 1.98864688)
(10, 5.10336293e-02, 0.70398283, 1.93831422)
(11, 3.06148582e-02, 0.7143608 , 1.90680022)
(12, 1.79468274e-02, 0.7214358 , 1.88758697)
(13, 1.03240723e-02, 0.7260406 , 1.87614544)
(14, 5.84768757e-03, 0.72892454, 1.86946918)
(15, 3.35778195e-03, 0.73067466, 1.8656404 )
(16, 1.98478537e-03, 0.7317098 , 1.86347648)
(17, 1.14937826e-03, 0.73230941, 1.86226842)
(18, 6.54505913e-04, 0.73265086, 1.86160094)
(19, 3.67583154e-04, 0.73284262, 1.86123535)
(20, 2.04087865e-04, 0.73294908, 1.86103659)
(21, 1.12232060e-04, 0.73300761, 1.86092922)
(22, 6.12220725e-05, 0.73303954, 1.86087154)]
Tests
clone repo:
git clone https://github.com/gmagno/w4
cd w4
create virtual environment and install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements_dev.txt
run tests:
make test
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 w4-0.1.2.tar.gz.
File metadata
- Download URL: w4-0.1.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a867a29155fc15edd3543ec55fd6d4a8210d086dbf83be7eb00626b47127b1
|
|
| MD5 |
83f8b779fc0e12286596db041a9b1c6f
|
|
| BLAKE2b-256 |
cf3ac88ca1edf394104807e81b070ac6bc57977639fcff474404af5909cbb694
|
File details
Details for the file w4-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: w4-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a046f114526ebe18d48c297efb5bfa8d44192c586200e75480e57cb40557e5a4
|
|
| MD5 |
b5095699ea79324daa3a3a40da6ec042
|
|
| BLAKE2b-256 |
4556aa9564a5b9a60366b5bb9a80bc702a839ddf883c3781f08ca1885feacccf
|