enter image description here


I want to fit this curve to a cotangent function. I have cot(x/2) but how do I change the curve of the graph?

Thank you!

  • 4
    $\begingroup$ This does not look like a cotangent. $\endgroup$ – Claude Leibovici Aug 26 '19 at 2:56
  • $\begingroup$ Maybe complementary error function erfc(x)? $\endgroup$ – LordVader007 Aug 26 '19 at 3:04
  • $\begingroup$ I do not think that a single function could suffice. Is there any physical problem behind ? $\endgroup$ – Claude Leibovici Aug 26 '19 at 5:44

I agree with the comment from Claude Leibovici : This does not look like a cotangent.

If we draw $\ln(y(x))$ instead of $y(x)$ the function appears more linear for small $x$ and large $x$ with a transition between both.

enter image description here

We can approach the whole function as a sum of two partial functions : $$\ln(y)=(a_1+b_1x)\phi_1(x)+(a_2+b_2x)\phi_2(x) \tag 1$$ with $\phi_1(x)\simeq\begin{cases}1\quad\text{small}\quad x\\ 0\quad\text{large}\quad x \end{cases} \quad\text{and}\quad \phi_2(x)\simeq\begin{cases}0\quad\text{small}\quad x\\ 1\quad\text{large}\quad x\end{cases} $

The functions $\phi(x)$ can be built with functions such as arctan, arctanh, erf, etc.

$$\phi_1(x)=\frac12-\frac{1}{\pi}\tan^{-1}\big(p_1(x-c_1)\big) \quad\text{and}\quad \phi_2(x)=\frac12+\frac{1}{\pi}\tan^{-1}\big(p_2(x-c_2)\big) \tag 2$$ The transition area is characterized with the parameters $c$ (location) and $p$ (extend).

Or alternatively : $$\phi_1(x)=\frac12-\frac{1}{2}\tanh^{-1}\big(p_1(x-c_1)\big) \quad\text{and}\quad \phi_2(x)=\frac12+\frac{1}{2}\tanh^{-1}\big(p_2(x-c_2)\big)$$ $$\phi_1(x)=\frac12-\frac{1}{2}\text{Erf}\big(p_1(x-c_1)\big) \quad\text{and}\quad \phi_2(x)=\frac12+\frac{1}{2}\text{Erf}\big(p_2(x-c_2)\big)$$

For example, with rough data coming from the graph published in the question :

enter image description here

Red curve : from data.

Black dot curve : Computed from equations $(1)$ and $(2)$.

This is not the least mean square fit. This was drawn with $a_1=1.42\:;\:b_1=-0.55\:;\:p_1=30\:;\:c_1=1.6$ and $a_2=2\:;\:b_2=-2.2\:;\:p_2=15\:;\:c_2=1.65$ . These "guessed" values could be used as starting values for non-linear fitting (iterative calculus) which was not done.

Probably simpler mathematical models exist. The best should be to base the mathematical form of equation on a physical model.

| cite | improve this answer | |
  • $\begingroup$ This is a nice answer (not surprising !). Cheers. $\endgroup$ – Claude Leibovici Aug 28 '19 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.