Creating a sine function with specific parameters Part1(Solved)
Is it possible to create a function that maps x to y as follows:
x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
y 0 1 2 3 4 5 4 3 2 1  0  1  2  3  4  5 ...
So far, this is what I have been able to come up with:
|5 sin ((1/10)pix)|
Which will give the following y's for x = 0 to 10:
 0.00000
 1.5451
 2.9389
 4.0451
 4.7553
 5.0000
 4.7553
 4.0451
 2.9389
 1.5451
 0.00000

This sequence will repeat every 10 steps, with the peak (5) at step 5. This is getting close to what I want so all that is left is to somehow adjust the function so that the required integers appear (1,2,3,4), but I don't know how.
Since the function is cycling through a series of numbers over and over, I figured that it might be possible to write the function in terms of a periodic function and not piece by piece.
Please comment. 
Part2
How would I go about writing a function that produce the following plot:(x is an integer >=0 , the pattern repeats after x = 8)

Can this plot be expressed using a single formula or must it be defined piecewise?
  Thank you.
 A: You ask for a function. A function is a mapping from one set to
another set, but you neglect to specify which sets. Your list of
$x$-values consists of small nonnegative integers together with
an ellipsis. From this, one might surmise that your intended
domain is $\mathbb{N}_0$, the set of nonnegative integers. Likewise
you do not specify a codomain, but let's say for argument's sake
that it is $\mathbb{N}_0$, the same as the domain.
Of course there are uncountably many functions from $\mathbb{N}_0$
to $\mathbb{N}_0$ containing your specified values. But you mention
it has to be a "sine" function. The term sine refers to a particular
function on the real numbers, taking all values between $-1$ and $1$
and having period $2\pi$. Your function cannot have all of these
properties. Perhaps by a "sine" function you mean a periodic function?
If so here is one defined on $\mathbb{N}_0$ which extends your table
of values:
$$f(n)=\begin{cases}
0&\text{if }n\equiv 0 \pmod {10},\\\\
1&\text{if }n\equiv\pm1 \pmod {10},\\\\
2&\text{if }n\equiv\pm2 \pmod {10},\\\\
3&\text{if }n\equiv\pm3 \pmod {10},\\\\
4&\text{if }n\equiv\pm4 \pmod {10},\\\\
5&\text{if }n\equiv 5 \pmod {10}.
\end{cases}$$
Of course, unlike the actual sine function, this never takes negative
values.
Perhaps as in Hans's comment, you want a function on the reals
restricting to your table of values. Here is a piecewise linear
example as Hans suggests:
$$g(x)=
\begin{cases}
10\{x/10\}&\textrm{if }\{x/10\} < 1/2,\\
10-10\{x/10\}&\textrm{if }\{x/10\}\ge 1/2
\end{cases}$$
where $\{t\}$ denotes the fractional part of a real number $t$.
A: $\frac{5}{\pi}\arccos\left(\cos\left(\frac{\pi x}{5}\right)\right)$ seems to do what you want, unless you need something smoother.
A: PART 1 You were close: Look at your values. They rise with slope $1$ till $5$, and then continue with slope $-1$. This may be described by the function
$h(x)'=\text{sgn}(\sin(\pi x/5))\,$.
$\hskip1.7in$
(from W|A).
Integrate this, $h(n)=\int_0^n \text{sgn}(\sin(x))\,dx\,$, and you're done.
Instead of that, you might adapt the Fourier Series for the Triangle Function to your problem:
$$
\begin{align} x_\mathrm{triangle}(t) & {} = \frac {8}{\pi^2} \sum_{k=0}^\infty (-1)^k \, \frac{ \sin \left( (2k+1)\omega t \right)}{(2k+1)^2} \\ & {} = \frac{8}{\pi^2} \left( \sin (\omega t)-{1 \over 9} \sin (3\omega t)+{1 \over 25} \sin (5\omega t) - \cdots \right) \end{align} 
$$
Part 2 Starting from $(n,h(n))=(9,5)$, you have $6$ values decreases, followed by a jump of $+3$ and then $6$ values increasing. So this is essentially the same problem with an additional offset function $\frac32 \left(\text{sgn}(\sin(\pi x/5))+1\right)$...
