# LsqFit example

**URL:** https://discourse.julialang.org/t/lsqfit-example/135621
**Category:** Statistics
**Created:** [February 13, 2026, 6:06pm UTC](https://discourse.julialang.org/t/lsqfit-example/135621 "2026-02-13T18:06:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)
#### Post date: [February 13, 2026, 6:06pm UTC](https://discourse.julialang.org/t/lsqfit-example/135621/1 "2026-02-13T18:06:12Z")

</div>

I am working through the initial example in [GitHub - JuliaNLSolvers/LsqFit.jl: Simple curve fitting in Julia](https://github.com/JuliaNLSolvers/LsqFit.jl) and don’t know where the function model comes from.

```julia-auto
julia> using LsqFit

julia> xdata = range(0, stop=10, length=20);

julia> ydata = model(xdata, [1.0 2.0]) + 0.01*randn(length(xdata));
ERROR: UndefVarError: `model` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

julia>

```

Any suggestions?

---

<div class="post-metadata">

### Author: ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)
#### Post date: [February 13, 2026, 6:19pm UTC](https://discourse.julialang.org/t/lsqfit-example/135621/2 "2026-02-13T18:19:49Z")

</div>

I didn’t think the line

```julia-auto
@. model(x, p) = p[1]*exp(-x*p[2])

```

above what I typed was pertinent in the example but it is.
