3
$\begingroup$

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!

  • 0
    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)$.2011-08-03
  • 0
    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$...2011-08-03
  • 0
    Slight correction... Based on the $y$-values, there must be constant added. $f(x)\sin(ax) + y_0$.2011-08-03
  • 0
    Sorry - I've updated the question with the form of the function, it is a decaying cos wave.2011-08-03
  • 0
    $D$ is the function value when $\cos{(Bx+C)} = 0$. Since the function has a maximum at $0$, $C = 0$. You can find $B$ by finding the period of the function. At each maximum $\cos (Bx+C)$ = 1, so $Ae^{kx}$ decides the height at the maximums.2011-08-03
  • 4
    @Parachuting Panda сan you calculate values of the function at arbitrary points and with what accuracy?2011-08-03
  • 0
    The value of $D$ looks like about 83 or 84; you can get things like that by staring at it. Horizontal distances from trough to trough and from peak to peak will tell you what number $B$ is.2011-08-04

3 Answers 3

10

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):

enter image description here


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}$.

enter image description here 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

enter image description here 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.

enter image description here Damped harmonic movement. For $C\ne 0$ and $D=0$.

  • 0
    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?2011-08-07
  • 0
    @Para: I've the feeling Américo could do *vastly* better if you mention the raw data that generated your curve...2011-08-07
  • 0
    @J.M - Unfortunately I don't have the actual raw data - just the function shown above.2011-08-07
  • 0
    @Parachuting Panda: You are right! I would say that $f(x)\ne Ae^{kx} \cos(Bx+C)+D$. There could be a small error due to my initial assumption which implied $C=0$. If $f'(0)=0$, then the horizontal deviation between maxima/minima and contact points is $-CA/(2\pi)$, I think. Or it might be that $f'(0)\ne 0$, but I am inclined to think that $f(x)$ is not of the form you have assumed and that is the major cause for the errors.2011-08-07
  • 0
    @Parachuting Panda: Have you checked Ross Millikan's solution? If the deviations are of the same magnitude I would say that $f(x)$ is not of the form you have assumed.2011-08-07
  • 0
    @Parachuting Panda: If you want to use $f(x)$ as it is, then you could adjust it to let's say $x_4$ and $x_{14}$.2011-08-07
  • 0
    @J. M.: Thanks! It seems to me that the best I can is to conclude that "almost for sure $f(x)$ cannot be of the form $f(x)=Ae^{kx}cos(Bx+C)+D$.2011-08-07
6

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) Decaying Function

And it found the solution

Solutions

With pretty good fitting:

Calculation Output

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.

  • 0
    +1 your answer suggests to me that the function $f(x)$ may be not of the form OP assumed.2011-08-07
4

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$.

  • 0
    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?2011-08-03
  • 0
    @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.2011-08-03
  • 0
    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.2011-08-03
  • 0
    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.2011-08-04
  • 0
    Thanks - I seem to get approximately the same answer as Ross, but I'm not entirely confident - can somebody else confirm that?2011-08-04
  • 0
    @MathsStudent: you could just plug my values into your equation, plot the result, and see if it comes close. If it doesn't, it may be clear what to change. If the wavelength is wrong, change B. If the die-off is wrong, change k, etc.2011-08-04
  • 0
    I correct myself. If $C=0$ "the maxima and minima" do not "occur a little bit to the left of the touching points of f(x)".2011-08-05