Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler first README example, also ref to Roots.jl. Fixes #264. #271

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ further below for a formal definition and the related commands.

There is also an identical API for solving fixed points (i.e., taking as input a function `F(x)`, and solving `F(x) = x`).

# Simple example
Note, if a single equation and not a system is to be solved and performance is not critical, consider using [Roots.jl](https://github.com/JuliaMath/Roots.jl).
If you want to solve a small system of equations at high performance, consider using [NonlinearSolve.jl](https://github.com/JuliaComputing/NonlinearSolve.jl).

# A super simple example

We consider the following bivariate function of two variables:

```jl
(x, y) -> ((x+3)*(y^3-7)+18, sin(y*exp(x)-1))
(x, y) -> [(x+3)*(y^3-7)+18, sin(y*exp(x)-1)]
```

In order to find a zero of this function and display it, you would write the
Expand All @@ -36,6 +39,27 @@ following program:
```jl
using NLsolve

function f(x)
[(x[1]+3)*(x[2]^3-7)+18,
sin(x[2]*exp(x[1])-1)]
end

sol = nlsolve(f, [ 0.1, 1.2])
sol.zero
```
The first argument to `nlsolve` is the function to be solved which
takes a vector as input and returns the residual as a vector.
The second argument is the starting guess for algorithm.
The `sol.zero` retrieves the solution, if converged.

# A simple example

Continuing on the same system of equations, but now using an in-place
function and a user-specified Jacobian for improved performance:

```jl
using NLsolve

function f!(F, x)
F[1] = (x[1]+3)*(x[2]^3-7)+18
F[2] = sin(x[2]*exp(x[1])-1)
Expand All @@ -58,15 +82,12 @@ Similarly, the function `j!` computes the Jacobian of the system and stores it
in a preallocated matrix passed as first argument. Residuals and Jacobian
functions can take different shapes, see below.

Second, when calling the `nlsolve` function, it is necessary to give a starting
point to the iterative algorithm.

Finally, the `nlsolve` function returns an object of type `SolverResults`. In
Second, the `nlsolve` function returns an object of type `SolverResults`. In
particular, the field `zero` of that structure contains the solution if
convergence has occurred. If `r` is an object of type `SolverResults`, then
`converged(r)` indicates if convergence has occurred.

# Specifying the function and its Jacobian
# Ways to specify the function and its Jacobian

There are various ways of specifying the residuals function and possibly its
Jacobian.
Expand Down