Non linear curve fitting of a cosine with multiple unknown parameters

78 Views Asked by At

I have an equation that I am able to solve with scipy curve fitting when I have good first guess values, however I was hoping to simplify this equation so that my answers are more reliable. The equation is of the following form: $$ f(x) = p - \frac{1}{a\cdot\bigl(\cos(bx+c)+D\bigr)} $$

Here $D$ is a known constant, $a,b,c,p$ are unknowns but I have a reasonable guess for what the values are with $p$ always close to $1$.

I am hoping to make the solutions to this equation more robust by some form of linear algebra but I cant find any solution. It seems as though all the variables can work against each other to give multiple different solutions.

Are the techniques to cosine curve fitting that I can try out? Thanks

1

There are 1 best solutions below

0
On

Let us say that you have $n$ data points $(x_i,y_i)$ and you want to fit the model $$y = p - \frac{1}{a\,\bigl(\cos(bx+c)+D\bigr)}$$ which is very highly nonlinear. You need to have good guesses before starting the nonlinear regression.

The first thing I should do is to expand the cosine and write the denominator as $$\alpha \cos(bx)+\beta \sin(bx)+\gamma$$ with $$\alpha=a\,\cos (c) \qquad \beta=-a\,\sin(b)\qquad \gamma=a\,D$$

Now, since you know anapproximate value of $p$, rewrite $$z=\frac 1{p-y}=\alpha\,cos(bx)+\beta\,\sin(bx)+\gamma$$

Now, give $b$ a value; the problem is then simple since it is a linear regression of $z_i=\frac 1{p-y_i}$ as a function of $u_i=\cos(bx_i)$ and $v_i=\sin(bx_i)$. So, for this specific value of $b$ you have the sum of squares $SSQ$. Run different values of $b$ until you see the minimum of $SSQ$. When you have the $b_{\text{opt}}$, you have all parameters and you can go back to $$y=p-\frac 1{\alpha\,cos(bx)+\beta\,\sin(bx)+\gamma}$$ When done, go back to $(a,b,c,D)$ using basic trigonometric relations.