Browse code

add sheet 7

Michi authored on10/06/2012 11:57:51
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+#Problem 1
2
+
3
+#definition of a straight line function
4
+y=function(x,m,b) m*x+b
5
+
6
+#definition x-Vctor
7
+x_vec=seq(-1,3,0.1)
8
+
9
+#definition y-vector
10
+y_vec=array(0,dim=c(length(x_vec)))
11
+for (i in (0:length(x_vec))){
12
+            y_vec[i]=y(x_vec[i],1,0)
13
+}
14
+#plotting x-vector vs. y-vector
15
+plot(x_vec, y_vec, type="l", col="black", xlab='x',ylab='f(x)=y')
16
+
17
+#generating mock data point for 0 <= x <= 2 for 10 equaly spaced points
18
+equ_points=10
19
+x_vec_2=seq(0,2, 2/(equ_points-1))
20
+for (i in x_vec_2){
21
+    points(i,rnorm(1, sd =  0.4), col="red", type="p")
22
+}