Exponential regression

86 Views Asked by At

I am trying to figure out a way to get the function parameters from the different points of an exponential function $f(x)=ab^x + c$. I figured it out for $f(x) = ab^x$, but can't find the answer when the function contains $c$. So I need to solve for $a$,$b$ and $c$ in the system of equations:

$$\left\{\begin{aligned} ab^{x_1} + c = y_1\\ ab^{x_2} + c = y_2\\ ab^{x_3} + c = y_3\\ \end{aligned}\right.$$

I was able to reduce the equation to one unknown: $\frac{b^{x_1}-b^{x_2}}{b^{x_2}-b^{x_3}} = \frac{y_1-y_2}{y_2-y_3}$
I don't know how to solve for $b$ in this equation and I have tried solving for other variables, which all didn't work. Is this system of equations even solvable? All help is appreciated. Please excuse my bad formatting, I don't know how to type math equations.

2

There are 2 best solutions below

1
On

You said in a comment that you are familiar with Python. Here is how to numerically solve this system of nonlinear equations with Python:

import numpy as np
from scipy.optimize import fsolve

x1 = 2
y1 = 7
x2 = 4
y2 = 19
x3 = 6
y3 = 67

# for a given variable w, this function returns F(w)
# if w is the solution of the nonlinear system, then 
# F(w)=0
# with your notations, w = [a, b, c]
def nonlinearEquation(w):
    F = np.zeros(3)
    F[0] = w[0]*w[1]**x1 + w[2] - y1
    F[1] = w[0]*w[1]**x2 + w[2] - y2
    F[2] = w[0]*w[1]**x3 + w[2] - y3
    return F

# generate an initial guess of the solution
initialGuess = np.random.rand(3)    
 
# solve the problem    
solutionInfo = fsolve(nonlinearEquation, initialGuess, full_output=1)

See here for details. The solution of the system is returned in the first component of solutionInfo.

2
On

The headline of your query is "Exponential regression" what smells like overdetermined system, more equations than unkown vars. But then you present three equations and ask if this is solvable for a,b and c. Sure it is.

According your description you already solved for a and c. In that case I'd suggest to change the origingal function $f(x)=ab^x+c$ to $g(x)=f(x)-c=ab^x$. Thus your modified equation system is now $$\displaystyle y_i - c = a\cdot b^x_i$$ Taking the log of it gives $$log(y_i - c) = log(a) + x\cdot log(b)$$ what is pretty linear and NP that way.
But... what if any $y_i\le c$? Well, in that case call Houston, we have a problem