diff --git a/README.md b/README.md index 283a2837..d45e2c2c 100644 --- a/README.md +++ b/README.md @@ -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) + ...` diff --git a/docs/src/tutorials/getting_started.md b/docs/src/tutorials/getting_started.md index 2c850d27..f9c37f98 100644 --- a/docs/src/tutorials/getting_started.md +++ b/docs/src/tutorials/getting_started.md @@ -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 @@ -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 diff --git a/src/common_interface.jl b/src/common_interface.jl index f0d938ff..6f14adc3 100644 --- a/src/common_interface.jl +++ b/src/common_interface.jl @@ -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) @@ -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)