Algorithms

Spring 2013
course
navigation

Jan 29

Goals for this week:
$ R > x = seq(0, 2*pi, by=0.1) # an array of numbers > plot(x, sin(x)) # ?plot for more details, i.e. type="l"
Python's [1,2,3] is R's c(1,2,3).
Materials:

minimal interactive version of "generate data and plot"

$ python -ic '' # In python, >>> f = [0,1] # generate data, >>> for i in xrange(2,250): ... f.append(f[i-1] + f[i-2]) ... >>> csv = open('data.csv','w') # output to text file. >>> csv.write("n,fib\n") >>> for j in range(20): ... i = 100 + 7*j ... csv.write("{},{}\n".format(i, f[i])) ... >>> exit() $ R --no-save --quiet # in R, > data = read.csv('data.csv') # read in data, > fit = lm(log(data$fib) ~ data$n) # find best-fit curve, > ypredict = exp(predict(fit)) > plot(data, log="y") # plot it > lines(data$n, ypredict, col="blue") # with best-fit curve. > q()
http://cs.marlboro.edu/ courses/ spring2013/algorithms/ notes/ Jan_29
last modified Monday January 28 2013 1:42 pm EST