CS545
Machine Learning

Fall 2009
Department of Computer Science
Link to Colorado State University Home
 Page

Assignment 1: Introduction to R Functions and Plotting

Write an R script file that defines the following functions.
  1. twosines(x) that accepts a sequence of x values and returns the sequence that is the value of sin(x)sin(0.7x), or in R notation sin(x) * sin(0.7 * x). An example of its use is
    > twosines(1:4)
    [1]  0.5420905  0.8960669  0.1218161 -0.2535199
    
  2. sinexp(xs,w) that returns the sequence that is the value of sin(xs) * exp(-(xs-10)^2/w).
  3. graph(xs) that uses your sinexp(xs,w) function and the R functions plot(), lines(), and legend() to produce this graph. This graph uses the sequence of x values x = 1, 1.1, 1.2, ..., 20.0.

Name your script file assign1.R. It must contain the three above function definitions, followed by the lines

print(twosines(c(1, 3, 5.6)))
print(sinexp(seq(10,12,by=0.2), 20))
xs <-    ### You complete this line of R code to generate sequence 1, 1.1, 1.2, ..., 20.0
graph(xs)
When you start R and run your solution by typing
source("assign1.R")
you will see the answers printed and a plot pop up.

Submit your script file through RamCT.