LJIWY

Problem 1

1)Solve and plot the solution:

A1 <- matrix(c(3,6,2,5), nrow = 2, ncol = 2,byrow = T)
b1 <- c(3,2)
solution1 <- solve(A1,b1)
print (solution1)
## [1] 1 0

2) Solve and plot the solution:

A2 <- matrix(c(1,-2,2,-3), nrow = 2, ncol = 2,byrow = T)
b2 <- c(1,2)
solution2 <- solve(A2,b2)
print (solution2)
## [1] 1 0

Problem 2

1)

A21 <- matrix(c(1,-1,0,1,0,1,1,-1,-2), nrow = 3, byrow = T)
b21 <- c(3,6,0)
solution21 <- solve(A21,b21)
print (solution21)
## [1] 4.5 1.5 1.5

2)

A22 <- matrix(c(1,1,1,2,1,0,4,3,3), nrow = 3, byrow = T)
b22 <- c(1,3,4)
solution22 <- solve(A22,b22)
print (solution22)
## [1]  1  1 -1

Problem 3

Model this question as solving four unknowns with four functions. Four unkowns a,b,c,d each represents the amount of money invested in each type of loans.

\[a + b + c + d = 250.......(1)\]

\[0.45a - 0.55b + 0*c + 0*d = 0 .......(2)\]

\[0*a + b + 0*c + 0*d = 250 * 0.25 .......(3)\]

\[0.14a + 0.2b + 0.2c + 0.1d = 250*0.15 .......(4)\]

A3 <- matrix(c(1,1,1,1,
              0.45,-0.55,0,0,
              0,1,0,0,
              0.14,0.2,0.2,0.1),             
             nrow = 4, byrow = T)
b3 <- c(250,0,250*0.25,250*0.15)
solution3 <- solve(A3,b3)
print (solution3)
## [1] 76.38889 62.50000 31.94444 79.16667

So the initial portfolio is:

Problem 4

It can be easily infered from the first two equations that the first row of A is (1,2,3) and the second row of A is (2,3,4); From the third equation, we know the second and third row of A add up to (3,5,7)

row3 <- c(3,5,7) - c(2,3,4)
print (row3)
## [1] 1 2 3

Therefore, matrix A is

##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    2    3    4
## [3,]    1    2    3

Problem 5

Rewrite the vectors in function forms: \[ c + 2d = 2.......(1) \] \[ c + 3d = -4.......(2) \] \[ 4d = a.......(3) \] \[ c + 5d = b.......(4) \]

, which is equivalent to: \[ 0*a + 0*b + c + 2d = 2.......(1) \] \[ 0*a + 0*b + c + 3d = -4.......(2) \] \[ a + 0*b + 0*c - 4d = 0.......(3) \] \[ 0*a + b - c - 5d = 0.......(4) \]

A5 <- matrix(c(0,0,1,2,
               0,0,1,3,
               1,0,0,-4,
               0,1,-1,-5),
             nrow = 4, byrow = T)
b5 <- c(2,-4,0,0)
solution5 <- solve(A5,b5)
print (solution5)
## [1] -24 -16  14  -6