Tuesday, 15 January 2013

IT and Business Application lab : Assignment 2


Problem 1
a) Create two matrices
Solution:            
Command
> a<- c(1,2,3,4,5,6,7,8,9)
> b<- c(32,48,1,5,10,12,15,18,23)
> dim(a)<- c(3,3)
> dim(b)<- c(3,3)
> a
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
> b
     [,1] [,2] [,3]
[1,]   32    5   15
[2,]   48   10   18
[3,]    1   12   23  
b) Select 3rd column from first matrix {a} and 1st column from second matrix {b}
Solution:
Command
> a1<-a[ ,3]
> a1
[1] 7 8 9
> b1<-b[ ,1]
> b1
[1] 32  48 1
c) Combine the two matrices
Solution:
Command
> combine<-cbind(a1,b1)
> combine
     a1 b1
[1,]  7 32
[2,]  8 48
[3,]  9 1

Problem 2: Find the product of two matrices
Solution:
Command
> multiple<- a%*%b
> multiple
     [,1] [,2] [,3]
[1,]  231  129  248
[2,]  312  156  304
[3,]  393  183  360

Problem 3: Find the regression using nifty data from 01 Dec 2012 to 31 Dec 2012 ?
Solution:
Command
> nifty<-read.csv(file.choose(),header=T)

> open<- nifty[ ,2]
> high<- nifty[ ,3]
> data<- cbind(open,high)
> reg1<-lm(high~open,data=nifty)
> reg1

Call:
lm(formula = high ~ open, data = nifty)

Coefficients:
(Intercept)        open
  1578.3358       0.7355


Problem 4: Generate and plot a normal distribution curve
Solution:
Command
> x<-seq(0,100)
> y<-dnorm(x,mean=50,sd=5)
> plot(x,y,type="l")

No comments:

Post a Comment