w4


Namew4 JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/gmagno/w4
SummaryW4 Method for Nonlinear Root Finding
upload_time2023-03-23 02:22:34
maintainer
docs_urlNone
authorGonçalo Magno
requires_python>=3.9
licenseMIT license
keywords w4
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            W4
===

[![PyPI version shields.io](https://img.shields.io/pypi/v/w4.svg)](https://pypi.python.org/pypi/w4/)

[![PyPI license](https://img.shields.io/pypi/l/w4.svg)](https://pypi.python.org/pypi/w4/)

This package provides the [W4
method](https://doi.org/10.1016/j.apnum.2022.08.019) for nonlinear root finding, inspired by the [R implementation](https://github.com/ramiromagno/w4).

Install
-------

create a virtual environment, activate it and upgrade pip:

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
```

install from pypi:

```bash
pip install w4
```

or from github repo:

```bash
pip install git+https://github.com/gmagno/w4
```

Usage
-----

```python
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:

```bash
[( 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:

```bash
git clone https://github.com/gmagno/w4
cd w4
```

create virtual environment and install dependencies

```python
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements_dev.txt
```

run tests:

```bash
make test
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gmagno/w4",
    "name": "w4",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "w4",
    "author": "Gon\u00e7alo Magno",
    "author_email": "goncalo.magno@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/3a/c88ca1edf394104807e81b070ac6bc57977639fcff474404af5909cbb694/w4-0.1.2.tar.gz",
    "platform": null,
    "description": "W4\n===\n\n[![PyPI version shields.io](https://img.shields.io/pypi/v/w4.svg)](https://pypi.python.org/pypi/w4/)\n\n[![PyPI license](https://img.shields.io/pypi/l/w4.svg)](https://pypi.python.org/pypi/w4/)\n\nThis package provides the [W4\nmethod](https://doi.org/10.1016/j.apnum.2022.08.019) for nonlinear root finding, inspired by the [R implementation](https://github.com/ramiromagno/w4).\n\nInstall\n-------\n\ncreate a virtual environment, activate it and upgrade pip:\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -U pip\n```\n\ninstall from pypi:\n\n```bash\npip install w4\n```\n\nor from github repo:\n\n```bash\npip install git+https://github.com/gmagno/w4\n```\n\nUsage\n-----\n\n```python\nimport numpy as np\nfrom w4.w4 import w4\nfrom w4.xy import Decomposition\n\nx0: np.ndarray = np.array([0.5, 5.0])\n\ndef f(x: np.ndarray) -> np.ndarray:\n    return np.array([x[0] ** 2 + x[1] ** 2 - 4, x[0] ** 2 * x[1] - 1])\n\ndef fa(x: np.ndarray) -> np.ndarray:\n    return np.array(\n        [abs(x[0] ** 2) + abs(x[1] ** 2) + abs(-4), abs(x[0] ** 2 * x[1]) + abs(-1)]\n    )\n\ndef jac(x: np.ndarray) -> np.ndarray:\n    return np.array([[2 * x[0], 2 * x[1]], [2 * x[0] * x[1], x[0] ** 2]])\n\nsolution: np.ndarray = w4(\n    x0=x0, f=f, fa=fa, jac=jac, decomposition=Decomposition.LU, trace=True\n)\n\nprint(solution)\n```\n\nOutput:\n\n```bash\n[( 0, 7.26495726e-01, 0.5       , 5.        )\n ( 1, 7.26495726e-01, 0.51413317, 4.46733668)\n ( 2, 6.69713968e-01, 0.52954179, 3.8709697 )\n ( 3, 5.84735305e-01, 0.54795009, 3.34463474)\n ( 4, 4.83432079e-01, 0.57024824, 2.91997823)\n ( 5, 3.77502437e-01, 0.5956425 , 2.59451865)\n ( 6, 2.78389751e-01, 0.6222772 , 2.3546681 )\n ( 7, 1.94497674e-01, 0.64795729, 2.18404118)\n ( 8, 1.29477634e-01, 0.67078251, 2.06671229)\n ( 9, 8.27001827e-02, 0.68957129, 1.98864688)\n (10, 5.10336293e-02, 0.70398283, 1.93831422)\n (11, 3.06148582e-02, 0.7143608 , 1.90680022)\n (12, 1.79468274e-02, 0.7214358 , 1.88758697)\n (13, 1.03240723e-02, 0.7260406 , 1.87614544)\n (14, 5.84768757e-03, 0.72892454, 1.86946918)\n (15, 3.35778195e-03, 0.73067466, 1.8656404 )\n (16, 1.98478537e-03, 0.7317098 , 1.86347648)\n (17, 1.14937826e-03, 0.73230941, 1.86226842)\n (18, 6.54505913e-04, 0.73265086, 1.86160094)\n (19, 3.67583154e-04, 0.73284262, 1.86123535)\n (20, 2.04087865e-04, 0.73294908, 1.86103659)\n (21, 1.12232060e-04, 0.73300761, 1.86092922)\n (22, 6.12220725e-05, 0.73303954, 1.86087154)]\n```\n\nTests\n-----\n\nclone repo:\n\n```bash\ngit clone https://github.com/gmagno/w4\ncd w4\n```\n\ncreate virtual environment and install dependencies\n\n```python\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -U pip\npip install -r requirements_dev.txt\n```\n\nrun tests:\n\n```bash\nmake test\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "W4 Method for Nonlinear Root Finding",
    "version": "0.1.2",
    "split_keywords": [
        "w4"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4556aa9564a5b9a60366b5bb9a80bc702a839ddf883c3781f08ca1885feacccf",
                "md5": "b5095699ea79324daa3a3a40da6ec042",
                "sha256": "a046f114526ebe18d48c297efb5bfa8d44192c586200e75480e57cb40557e5a4"
            },
            "downloads": -1,
            "filename": "w4-0.1.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b5095699ea79324daa3a3a40da6ec042",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.9",
            "size": 4977,
            "upload_time": "2023-03-23T02:22:32",
            "upload_time_iso_8601": "2023-03-23T02:22:32.645769Z",
            "url": "https://files.pythonhosted.org/packages/45/56/aa9564a5b9a60366b5bb9a80bc702a839ddf883c3781f08ca1885feacccf/w4-0.1.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf3ac88ca1edf394104807e81b070ac6bc57977639fcff474404af5909cbb694",
                "md5": "83f8b779fc0e12286596db041a9b1c6f",
                "sha256": "36a867a29155fc15edd3543ec55fd6d4a8210d086dbf83be7eb00626b47127b1"
            },
            "downloads": -1,
            "filename": "w4-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "83f8b779fc0e12286596db041a9b1c6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6667,
            "upload_time": "2023-03-23T02:22:34",
            "upload_time_iso_8601": "2023-03-23T02:22:34.735885Z",
            "url": "https://files.pythonhosted.org/packages/cf/3a/c88ca1edf394104807e81b070ac6bc57977639fcff474404af5909cbb694/w4-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-23 02:22:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "gmagno",
    "github_project": "w4",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "w4"
}
        
Elapsed time: 0.09318s