Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ CurveFit.jl provides the following fitting algorithms:

- **Linear fitting**: `LinearCurveFitAlgorithm` - General linear fits with customizable transformations
- **Log fitting**: `LogCurveFitAlgorithm` - Fits `y = a*log(x) + b`
- **Power fitting**: `PowerCurveFitAlgorithm` - Fits `y = b*x^a`
- **Exponential fitting**: `ExpCurveFitAlgorithm` - Fits `y = b*exp(a*x)`
- **Power fitting**: `PowerCurveFitAlgorithm` - Fits `y = exp(a*log(x) + b)` (returns `(a, b)`; scale factor is `exp(b)`)
- **Exponential fitting**: `ExpCurveFitAlgorithm` - Fits `y = exp(a*x + b)` (returns `(a, b)`; scale factor is `exp(b)`)
- **Polynomial fitting**: `PolynomialFitAlgorithm` - Fits polynomials of arbitrary degree
- **Rational polynomial fitting**: `RationalPolynomialFitAlgorithm` - Fits rational functions p(x)/q(x)
- **Sum of exponentials**: `ExpSumFitAlgorithm` - Fits `y = k + p1*exp(λ1*t) + p2*exp(λ2*t) + ...`
Expand Down
10 changes: 8 additions & 2 deletions docs/src/tutorials/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ println("Prediction at x=5: ", sol(5.0))

## Exponential Fitting

Fit an exponential function `y = b * exp(a * x)`:
Fit an exponential function `y = exp(a * x + b)`. The fit is performed in
log-linear space, so `sol.u = (a, b)` returns the log-space intercept `b`; the
multiplicative scale factor of the equivalent form `y = B * exp(a * x)` is
`B = exp(b)`:

```@example exponential
using CurveFit
Expand All @@ -132,7 +135,10 @@ println("Scale factor (b): ", exp(sol.u[2]))

## Power Law Fitting

Fit a power law `y = b * x^a`:
Fit a power law `y = exp(a * log(x) + b)`. The fit is performed in log-log
space, so `sol.u = (a, b)` returns the log-space intercept `b`; the
multiplicative scale factor of the equivalent form `y = B * x^a` is
`B = exp(b)`:

```@example power
using CurveFit
Expand Down
20 changes: 14 additions & 6 deletions src/common_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,18 @@ to fit. This algorithm does not support passing weights through `sigma` in
We want to solve for `a` and `b` such that:

```math
y = b x^a
y = \exp(a \log(x) + b) = \exp(b)\, x^a
```

This is equivalent to a linear fit in log-log space, i.e.,
This is a linear fit in log-log space, i.e.,

```math
\log(y) = a \log(x) + \log(b)
\log(y) = a \log(x) + b
```

The returned parameters are `(a, b)`, where `b` is the intercept in log space.
The multiplicative scale factor `B` of the equivalent form ``y = B x^a`` is
recovered as ``B = \exp(b)``.
"""
PowerCurveFitAlgorithm() = LinearCurveFitAlgorithm(; xfun = log, yfun = log)

Expand All @@ -274,14 +278,18 @@ fit. This algorithm does not support passing weights through `sigma` in
We want to solve for `a` and `b` such that:

```math
y = b \exp(a x)
y = \exp(a x + b)
```

This is equivalent to a linear fit in log-linear space, i.e.,
This is a linear fit in log-linear space, i.e.,

```math
\log(y) = a x + \log(b)
\log(y) = a x + b
```

The returned parameters are `(a, b)`, where `b` is the intercept in log space.
The multiplicative scale factor `B` of the equivalent form ``y = B \exp(a x)``
is recovered as ``B = \exp(b)``.
"""
ExpCurveFitAlgorithm() = LinearCurveFitAlgorithm(; xfun = identity, yfun = log)

Expand Down
Loading