# Power curve fitting

Least Squares can be used to fit the following power curve to given data points.

$y=ax^b$ where $a,b$ are constants to be determined by the fitting process as seen here.

Is there a way to fit $y=a\left(x-c\right)^b$ to given data points? where $a,b,c$ are constants to be determined by the fitting process.

Let $\{(x_1,y_1),\ldots,(x_n,y_n)\}$ be your training points.

I think you have two options:

1- Linearizing the log function (as Jean-Claude Arbaut suggests in the comments).

2- Coordinate descent.

I explain the coordinate descent approach in the following:

$$y=a(x-c)^b$$ $$\log y=\log a+b\log(x-c)$$

If you knew $c$, you would let $\theta=\left[ \begin{array}{c} \log a\\ b\end{array} \right]$, $Y=\left[ \begin{array}{c} \log y_1\\ \vdots\\ \log y_n\end{array} \right]$,$X=\left[ \begin{array}{cc} 1 & \log (x_1-c)\\ \vdots\\ 1 & \log (x_n-c)\end{array} \right]$. The you will have $Y=X\theta$, which has a closed-form solution for $\theta$ by least-squares:

$$\theta=(X^TX+\lambda I)^{-1}X^TY$$ (If you have many points you can safely set $\lambda=0$)

You solve for $a$ and $b$ (i.e. $a=e^{\theta_1}$ and $b=\theta_2$), then substitute for each sample: $$y_i=a(x_i-c)^b\Rightarrow c=\frac{1}{n}\sum_{i=1}^n x_i-(y_i/a)^{1/b}$$

Now a coordinate descent algorithm works in the following way:

Step 1: Initilize $c$ (e.g. set $c=0$)
Step 2: Iterate between solving $\theta$ and $c$ until convergence.

I hope it helps.

Here is a short Matlab code that verifies it:

a=1.83;
b=.00085;
c=-9.09;
n=10;
x=rand(n,1)*20;
y=a*(x-c).^b;

Y=log(y);

%figure(1)
%scatter(x,y)
a
b
c

c=0
for i=1:100000
X=[ones(n,1), log(x-c)];
t=(X'*X)^-1*X'*Y;
a=exp(t(1));
b=t(2);
c=mean(x-(y/a).^(1/b));
end

a
b
c
• Coordinate descent worked perfectly using the algorithm you provided :) Mar 31, 2016 at 22:43
• $c=\frac{1}{n}\sum_{i=1}^n x_i-(y_i/a)^{1/b}$ isn't the least squares estimate right? Apr 28, 2023 at 1:24