Fitting data with Cosine 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...

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).
 A: 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.
A: 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/
A: 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
