# Find equation for a function of form: $f(x) = Ae^{kx} \cos(Bx+C)+D.$?

How can I find the equation of this function.

I assume I will need to work out coordinates for each peak?

The function is a decaying cos graph of the form:

$$f(x) = Ae^{kx} \cos(Bx+C)+D.$$

Any help would be appreciated!

-
Looks like a sinusoidal curve; I would expect it to be something of the form $f(x)\sin(\alpha x)$ for suitable $\alpha$ and $f(x)$. –  Arturo Magidin Aug 3 '11 at 11:16
Where does the example come from? If it solves an ODE, then I have a fairly good idea the type of function it might be -- definitely of the form $f(x) \sin(ax)$ as @Arturo points out... Can you take a guess at $f(x)$? It would be a function that decays over time towards $0$... –  Shaun Ault Aug 3 '11 at 11:19
Slight correction... Based on the $y$-values, there must be constant added. $f(x)\sin(ax) + y_0$. –  Shaun Ault Aug 3 '11 at 11:20
Sorry - I've updated the question with the form of the function, it is a decaying cos wave. –  Parachuting Panda Aug 3 '11 at 11:21
@Parachuting Panda сan you calculate values of the function at arbitrary points and with what accuracy? –  Andrew Aug 3 '11 at 12:25

Edited in response to Parachuting Panda's comment, and in the spirit of my comment "If you want to use $f(x)$ as it is, then you could adjust it to let's say $x_{4}$ and $x_{14}$".

If we consider $x_{4}\approx 24.3$, $f(x_{4})\approx 101.4$ and $x_{14}\approx 85.3$, $f(x_{14})\approx 91.4$ and compute in a similar way as below, from

$$\begin{eqnarray*} f(x_{4}) &\approx &101.4\approx Ae^{kx}\cos (Bx)+83.4 \\ f(x_{14}) &\approx &91.4\approx Ae^{kx}\cos (Bx)+83.4 \end{eqnarray*},$$

with the same $B\approx 0.517$, we get $k\approx -1.33x/100$ and $A\approx 24.9$:

$$f(x)\approx 24.9e^{-1.33x/100}\cos (0.517x)+83.4.\qquad (\ast\ast)$$

But $f(0)\approx 108.3$, and $f(x_{18})=f(109.4)\approx 89.2$ which deviates too from the the given curve. My conclusion is that almost for sure $f(x)$ cannot be of the form $$f(x)=Ae^{kx}\cos (Bx+C)+D.$$

Here are the graphs of $(\ast\ast)$ (green) and $(\ast)$ (blue) and the peaks of the given curve (red circles):

The maxima and minima of $f(x)$ are attained at equally spaced points $x_{p}$ ($p=0,1,\ldots$). Since $f(0)$ seems to be the first maximum (in some applications it so happens), then $x_{0}\approx 0,C\approx 0$ and $x_{p}\approx\frac{p\pi }{B}$. The horizontal distance between peaks is $X=\frac{2\pi }{B}$.

Vertical offset $D\approx 83.8$, Distance between two peaks $X\approx 12.2$

To minimize errors we consider the $9^{th}$ maximum after $x_{0}$. It occurs at $x_{18}=\frac{18\pi }{B}\approx 109.4$. Hence $B\approx 0.517$ and $X\approx 12.2$. If we use the $1^{st}$ and $10^{th}$ minima instead, for a function such as $f(x)$ we should have $x_{19}-x_{1}=x_{18}-x_0$. Within the margin of error of this method these differences are equal. Hence

$$f(x)\approx Ae^{kx}\cos (0.517x)+D.$$

Also, on the graph $f(0)\approx 120$, so $A+D\approx 120$. The straight line $y=D$ crosses the graph of $f(x)$ at equally spaced points. Two successive points are $\frac{X}{2}=\frac{\pi }{B}\approx 6.08$ apart. The distance from the first to the $19^{th}$ must be $\frac{18\pi }{B}\approx 109.4$. Using this information we try to adjust the position of that line and find $D\approx 83.4$. Then $A\approx 120-83.4=36.6$ and $f(x)\approx 36.6e^{kx}\cos (0.517x)+83.4$.

For $C\ne 0$ the graphs of the functions $$u(x)=36.6e^{kx}+83.4$$ and $$v(x)=-36.6e^{kx}+83.4$$ would touch the graph of $f(x)$ a little bit after the peaks (see sketch below). But our initial assumption implied that $C=0$, so this does not happen in the present case. From

$$\frac{f(x_{0})-D}{f(x_{18})-D}=\frac{e^{kx_{0}}}{e^{kx_{18}}}=\frac{1}{e^{kx_{18}}}=\frac{1}{e^{k\frac{18\pi }{B}}}\approx \frac{1}{e^{109.4k}},$$

and using $f(x_{0})\approx f(0)\approx 120$ and $f(x_{18})\approx 90$, $\frac{120-83.4}{90-83.4}\approx \frac{1}{e^{109.4k}}$ we get $k\approx -1.57/100$. Therefore the numerical formula is

$$f(x)\approx 36.6e^{-1.57x/100}\cos (0.517x)+83.4\qquad (\ast)$$

and the corresponding graph

Graph of $f(x),u(x),v(x)$

Sketch of a damped harmonic oscillator for the same type of curve but with "touching" points different from maxima and minima.

Damped harmonic movement. For $C\ne 0$ and $D=0$.

-
+1 I couldn't have said it any better. Kudos. –  ja72 Aug 6 '11 at 23:21
@ja72: Thank you! –  Américo Tavares Aug 6 '11 at 23:24
Thanks Americo! Unfortunately however, your model doesn't actually fit the data particularly well - for the peaks between x=12 and x=85.5 the peak is almost 10 too high, and similar for the bottom peaks in the same area. It only really fits the last two peaks. Do you have any suggestions for creating a more accurate model? –  Parachuting Panda Aug 7 '11 at 4:23
@Para: I've the feeling Américo could do vastly better if you mention the raw data that generated your curve... –  Ｊ. Ｍ. Aug 7 '11 at 5:29
@J.M - Unfortunately I don't have the actual raw data - just the function shown above. –  Parachuting Panda Aug 7 '11 at 7:46

You plug the values into Eureqa (link here) and let it find the function for you.

I pluged the table of values from (my example)

And it found the solution

With pretty good fitting:

The original function I used in Excel was =0.8+0.8*EXP(-'t'/4)*(2*COS(PI()*'t')).

Eureqa solution: 0.80000001 + 0.79978114*cos(-6.2831697*t)*exp(-0.25*t)

The results are impressive as you can see the 0.8 the 2*PI() and the 1/4.

-
+1 your answer suggests to me that the function $f(x)$ may be not of the form OP assumed. –  Américo Tavares Aug 7 '11 at 9:43

One way is to use a multidimensional minimizer: collect a bunch of points, create a function of $A, B, C, D, k$ that sums the squared errors, and minimize it. Such routines are available in any numerical analysis text, or in Excel.

To do it by eye, Eivind gave you a start. It looks like $D$ is about $82$ (taking the center of the wiggles), $C$ is $0$ (assuming the start has a flat tangent-maybe it is $-3$ or so), $9$ waves end at $x=108$ so $B=2\pi/12$, the amplitude drops by about a factor of $4$ in $100,$ so $e^{100k}=0.25, k=-.014$ and from the first wave $A$ is about $35$.

-
This is a practical query. How do you "collect a bunch of points"? I mean, do you know if there is any software that does it, a sort of automatic data acquisition? –  Américo Tavares Aug 3 '11 at 21:55
@Américo Tavaress: I don't know where the curve came from, so maybe a bunch of points were available to be plotted. Otherwise, you could (as OP suggested) read points off the graph, with peaks probably easier than others. –  Ross Millikan Aug 3 '11 at 22:11
I agree, since the line $y=D$ is not drawn, the best would be to read the peaks. Independently from you I found $D\approx 83$, but I assumed $f(0)=120$. For a function such as $f(x)$ the maxima and minima have to occur a little bit to the left of the "touching points" of $f(x)$ with $\pm Ae^{kx}+D$. In this case the difference is particularly small. –  Américo Tavares Aug 3 '11 at 23:18
Implicit in Ross's answer is that you need good starting values for your parameters (doing things by eye works great here) before you perform the nonlinear fitting. Even the best optimization method goes kaput if your seeds suck severely. –  Ｊ. Ｍ. Aug 4 '11 at 5:49
Thanks - I seem to get approximately the same answer as Ross, but I'm not entirely confident - can somebody else confirm that? –  MathsStudent Aug 4 '11 at 11:45