Michi

Michi commited on 2012-06-10 12:37:30
Zeige 1 geänderte Dateien mit 16 Einfügungen und 7 Löschungen.

... ...
@@ -7,16 +7,25 @@ y=function(x,m,b) m*x+b
7 7
 x_vec=seq(-1,3,0.1)
8 8
 
9 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
-}
10
+y_vec=y(x_vec,1,0)
14 11
 #plotting x-vector vs. y-vector
15 12
 plot(x_vec, y_vec, type="l", col="black", xlab='x',ylab='f(x)=y')
16 13
 
17 14
 #generating mock data point for 0 <= x <= 2 for 10 equaly spaced points
18 15
 equ_points=10
16
+mock_vec = rep(NA,10)
19 17
 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
-}
18
+mock_vec = rnorm({1:10},mean = x_vec_2, sd =  0.4)
19
+points(x_vec_2,mock_vec, col="red", type="p")
20
+
21
+##Problem2
22
+conrel =function(b) b
23
+linrel =function(x,m,b) m*x+b
24
+quarel =function(x,a,m,b) a*x**2 + m*x+b
25
+
26
+reso = 10  #the resolution
27
+a_val = seq(-4,4,reso)
28
+m_val = seq(-4,8,reso)
29
+b_val = seq(-2,2,reso)
30
+
31
+
23 32