x <- pi
amp <- 2
freq <- 0.5
y <- amp * sin(freq * x)
y[1] 2Hubert Baechli
March 8, 2025
This set of exercises is not fully ready and will be improved over the next few days. Do at your own risk ;)
This sheet contains an exercise where you can apply and deepen the skills from E002 to E004. The end goal is to be able to plot different Sine curves that differ in amplitude, frequency and offset.
To begin, we need a function that calculates the sine.
Hint: implement at least these parameters, if you like you can also add offsets.
Your function now should do this
and it should also work with a vector
Hint: sequences you learned in E004
 [1]  0.000000e+00  7.653669e-01  1.414214e+00  1.847759e+00  2.000000e+00
 [6]  1.847759e+00  1.414214e+00  7.653669e-01  2.449294e-16 -7.653669e-01
[11] -1.414214e+00 -1.847759e+00 -2.000000e+00 -1.847759e+00 -1.414214e+00
[16] -7.653669e-01 -4.898587e-16Since the previous result is not easy to verify, let’s create a plot of these results.
You are already familiar with functions that return text or numbers. In R, however, it is also possible to write functions that generates directly plots.
You should got a function which does something like that
Hint: Use “E002”-skills for customizing your title
Once the basic building blocks are in place, it becomes easier to add further enhancements. Here, for example, is a reference curve added.