Skip to content

Commit

Permalink
Simpler README example, also ref to Roots.jl. Fixes JuliaNLSolvers#264.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro3 committed Jun 15, 2021
1 parent 2196728 commit 3f9bf46
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ 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, consider using [Roots.jl](https://github.com/JuliaMath/Roots.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 +38,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 2-vector as input and returns a 2-vector as output.
The second argument is the starting point 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 Down Expand Up @@ -66,7 +89,7 @@ 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

0 comments on commit 3f9bf46

Please sign in to comment.