3

So I'm trying to wrap my head about Graphing Cos and Sin but I have several questions about graphing. I know that the Formula is

$$Y= A \sin (t \pm h) + K$$

where $A$ is Amplitude , $t$ is Period, $h$ is horizontal shift, $k$ is the mid line.

I have the following data... enter image description here

I know for fact the following...

Highest Point $= 73$

Lowest point $= 43$

Amplitude $= (73 - 43) = 30$

Midline $= (A/2 + 43) = 30/2 + 43 = 58$

Now the problem is putting all the information together...

$y = 15 \cos (t \pm h) + 58$

my question is figuring the Period and Horizontal shift?

I think $t$ (period), is the number of cycles between $0$ and $24$ so it's $24/1$

$t= 24/1 = 24$

but the graph shrinks?

I'm having trouble understanding how to obtain t- period and h- horizontal shift.

Most of the graphs on the internet use $2\pi/$(# of intervals).

Cris
  • 31

3 Answers3

3

The technique for fitting depends on what your goal is and how the data works. Are you just trying to describe the data with some notion of how closely the description matches? Are deviations from your ideal description due to random errors of some sort, or finer detail?

The most basic form of statistic used in these circumstances is the sum of the square deviations:$$s^2 = \sum_{i=1}^N [y_i - f(x_i, \mathbf{a})]^2,$$ where $\mathbf{a}$ is some set of parameters that control the behavior of the model, $f$. Making the model as close to the data as possible, for this definition of closeness, is a minimization problem about which much has been written for least squares in particular and the problem of optimization in general (including when solving the system of equations from taking derivatives is not feasible).

For your particular problem, you can use a trig identity to write the model in another form: $$\begin{align} f(x) & = A \sin\left(\frac{2\pi x}{\lambda} + \phi\right) + K \\ & = B\sin\left(\frac{2\pi x}{\lambda}\right) + C \cos\left(\frac{2\pi x}{\lambda}\right) + K, \end{align}$$ with $\lambda$ the period/wavelength. trig identites relate the constants as:$$\begin{align} B &= A\cos\phi,\ \mathrm{and}\\ C &= A\sin\phi.\end{align}$$ The reason for switching to $B$ and $C$ is because the data is linear in them, making them easier to fix.

Sean Lake
  • 1,737
  • There are ample tools available for this sort of data analysis in software like GNU R ( https://www.r-project.org/ ) and the scipy package ( https://www.scipy.org/ , particularly scipy.optimize http://docs.scipy.org/doc/scipy/reference/optimize.html ) in the Python programming language. – Sean Lake Sep 02 '16 at 19:11
1

I think your formula isn't quite correct with regard to period and horizontal shift.

Here's what it should be:

$$f(x) = A\sin(t+(px))+K$$

Where $A$ is the amplitude, $K$ is the vertical shift, $t$ is the horizontal shift, and $p$ is the frequency (that's the same as $\frac{1}{period}$).

Notice that $t$ is a constant and is always added, but $p$ is a coefficient and is always multiplied by $x$. Don't change up the order!

EDIT: if you want to experiment with this and see how changing the variables changes your sine wave, check out http://fooplot.com/

Newb
  • 17,672
  • 13
  • 67
  • 114
  • So am I heading the right way with the formula I have created ?

    y = 15 Cos (t +(px)) + 58

    – Cris Oct 30 '13 at 01:22
  • Yes, your amplitude and vertical shift are correct. – Newb Oct 30 '13 at 01:23
  • okay thank you .. I will try to figure how to find the "Horizontal" Shift and "P" the frequency. – Cris Oct 30 '13 at 01:24
  • Hint for the horizontal shift: a normal, non-shifted sine-wave has a positive peak at x=0 – Newb Oct 30 '13 at 01:32
  • I understand how to find "Horizontal shift" the problem I'm having is with the period ...I have no idea how to find the period when it has a graph. – Cris Oct 30 '13 at 01:38
  • Do you know how radians work? – Newb Oct 30 '13 at 01:43
  • yes ... and converting degree into radian... – Cris Oct 30 '13 at 01:46
  • Okay. Hint: You know your highest point and your lowest point. On a normal sine wave, those are exactly half a cycle apart. – Newb Oct 30 '13 at 01:47
  • reference to Period is my reference on how to solve for the period. – Cris Oct 30 '13 at 01:54
  • My final answer is y = 15cos(2π / 24 (x + 7.53)) + 58 – Cris Oct 30 '13 at 04:53
  • @Cris I don't have your data, so I can't see if it fits. However, in your formula you have $(2\pi / 24 (x + 7.53))$. That means that for each value of $x$, it first gets $7.53$ added, and then the whole thing is multiplied by $2\pi / 24$. Are you sure that's right? I said in my answer that the stuff inside the parenthesis is usually the (horizontal shift PLUS (x times frequency)) – Newb Oct 30 '13 at 04:57
  • Why did you rename $h$ as $t$ ? –  Sep 02 '16 at 18:56
0

Here's the function in R, which you can use for your purpose.

getMyCosine <- function(lowest_point=c(pi,-1), highest_point=c(0,1)){
  cosine <- list(
    T = pi / abs(highest_point[1] - lowest_point[1]),
    b = - highest_point[1],
    k = (highest_point[2] + lowest_point[2]) / 2,
    A = (highest_point[2] - lowest_point[2]) / 2
  )
  return(cosine)
}

Below it is used to simulate the variation of temperature throughout the day with a cosine function, by entering the hours and temperature values for the lowest and warmest hour:

c <- getMyCosine(c(4,10),c(17,25)) 
# lowest temprature at 4:00 (10 degrees), highest at 17:00 (25 degrees)

x = seq(0,23,by=1);  y = c$A*cos(c$T*(x +c$b))+c$k ; 
library(ggplot2);   qplot(x,y,geom="step")

The qplot from code above

IVIM
  • 101