First define the DPC function to return SIR and P(t+1) given the gain matrix, target SIR vector and initial power values vector
dpc = function(g, p.current, rho, e, gdim) {
tmpSIR = matrix(rep(0, gdim), ncol = gdim)
tmpP = matrix(rep(0, gdim), ncol = gdim)
for (i in 1:gdim) {
numerator = g[i, i] * p.current[i]
denominator = e
for (j in 1:gdim) {
if (i != j)
denominator = denominator + g[i, j] * p.current[j]
}
# print(c(numerator,denominator))
tmpSIR[i] = numerator/denominator
}
tmpP = rho * p.current/tmpSIR
list(tmpSIR, tmpP)
}
Initialize the Gain matrix, initial power vector, target SIR Call the DPC function defined 10 times for 10 iterations
g = matrix(c(1, 0.2, 0.2, 0.1, 1, 0.2, 0.3, 0.3, 1), ncol = 3)
loopn = dim(g)[1]
p = matrix(c(rep(1, 3)), ncol = loopn)
rho = matrix(c(1, 1.5, 1), ncol = loopn)
pt = matrix(c(rep(0, 30)), ncol = loopn)
SIR = matrix(c(rep(0, 30)), ncol = loopn)
noise = 0.1
pnext = p
for (i in 1:10) {
tmp.result = dpc(g, pnext, rho, noise, loopn)
SIR[i, ] = tmp.result[[1]]
pt[i, ] = tmp.result[[2]]
pnext = pt[i, ]
# print(pnext) 1.5 * 1/1.66666 1.5*0.9/2.5714
}
Show the initialized variables and the results for assignment 1a
g
## [,1] [,2] [,3]
## [1,] 1.0 0.1 0.3
## [2,] 0.2 1.0 0.3
## [3,] 0.2 0.2 1.0
p
## [,1] [,2] [,3]
## [1,] 1 1 1
rho
## [,1] [,2] [,3]
## [1,] 1 1.5 1
pt
## [,1] [,2] [,3]
## [1,] 0.5000 0.9000 0.5000
## [2,] 0.3400 0.5250 0.3800
## [3,] 0.2665 0.4230 0.2730
## [4,] 0.2242 0.3528 0.2379
## [5,] 0.2067 0.3243 0.2154
## [6,] 0.1971 0.3089 0.2062
## [7,] 0.1928 0.3019 0.2012
## [8,] 0.1905 0.2984 0.1989
## [9,] 0.1895 0.2967 0.1978
## [10,] 0.1890 0.2959 0.1972
SIR
## [,1] [,2] [,3]
## [1,] 2.000 1.667 2.000
## [2,] 1.471 2.571 1.316
## [3,] 1.276 1.862 1.392
## [4,] 1.189 1.798 1.148
## [5,] 1.085 1.632 1.104
## [6,] 1.049 1.575 1.045
## [7,] 1.022 1.535 1.025
## [8,] 1.012 1.518 1.011
## [9,] 1.005 1.508 1.006
## [10,] 1.003 1.504 1.003
Plot the powers and SIR at end of each iteration
plot(1:10, pt[, 1], ylim = c(0.1, 0.5), xlab = "iteration", ylab = "power(mW)",
col = "red", type = "l", lty = 2, main = "assignment 1a")
points(pt[, 2], col = "dark green", type = "l", lty = 2)
points(pt[, 3], col = "blue", type = "l", lty = 2)
legend("top", c("Link 1", "Link 2", "Link 3"), col = c("red", "dark green",
"blue"), lty = 2, text.width = 0.5, text.col = c("red", "dark green", "blue"),
cex = 0.6, bty = "n")
plot(1:10, SIR[, 1], ylim = c(0.6, 2.5), xlab = "iteration", ylab = "SIR", col = "red",
type = "l", lty = 2, main = "assignment 1a")
points(SIR[, 2], col = "dark green", type = "l", lty = 2)
points(SIR[, 3], col = "blue", type = "l", lty = 2)
legend("top", c("Link 1", "Link 2", "Link 3"), col = c("red", "dark green",
"blue"), lty = 2, text.width = 0.5, text.col = c("red", "dark green", "blue"),
cex = 0.6, bty = "n")
Plot for new gain matrix Assigment 1b Initialize the Gain matrix, initial power vector, target SIR Call the DPC function defined 10 times for 10 iterations
g1 = matrix(c(1, 0.2, 0.2, 0.1, 0.1, 1, 0.2, 0.1, 0.3, 0.3, 1, 0.1, 0.1, 0.1,
0.1, 1), ncol = 4)
loopn1 = dim(g1)[1]
p1 = matrix(c(pt[10, ], 1), ncol = loopn1)
rho1 = matrix(c(1, 1.5, 1, 1), ncol = loopn1)
pt1 = matrix(c(rep(0, loopn1 * 10)), ncol = loopn1)
SIR1 = matrix(c(rep(0, loopn1 * 10)), ncol = loopn1)
pnext = p1
for (i in 1:10) {
tmp.result = dpc(g1, pnext, rho1, noise, loopn1)
SIR1[i, ] = tmp.result[[1]]
pt1[i, ] = tmp.result[[2]]
pnext = pt1[i, ]
# print(pnext) 1.5 * 1/1.66666 1.5*0.9/2.5714
}
Show the initialized variables and the results for assignment 1b
g1
## [,1] [,2] [,3] [,4]
## [1,] 1.0 0.1 0.3 0.1
## [2,] 0.2 1.0 0.3 0.1
## [3,] 0.2 0.2 1.0 0.1
## [4,] 0.1 0.1 0.1 1.0
p1
## [,1] [,2] [,3] [,4]
## [1,] 0.189 0.2959 0.1972 1
rho
## [,1] [,2] [,3]
## [1,] 1 1.5 1
pt1
## [,1] [,2] [,3] [,4]
## [1,] 0.2888 0.4455 0.2970 0.1682
## [2,] 0.2505 0.3955 0.2637 0.2031
## [3,] 0.2390 0.3743 0.2495 0.1910
## [4,] 0.2314 0.3626 0.2417 0.1863
## [5,] 0.2274 0.3561 0.2374 0.1836
## [6,] 0.2252 0.3526 0.2351 0.1821
## [7,] 0.2240 0.3507 0.2338 0.1813
## [8,] 0.2233 0.3496 0.2331 0.1808
## [9,] 0.2230 0.3490 0.2327 0.1806
## [10,] 0.2228 0.3487 0.2325 0.1805
SIR1
## [,1] [,2] [,3] [,4]
## [1,] 0.6545 0.9962 0.6642 5.9450
## [2,] 1.1529 1.6895 1.1263 0.8281
## [3,] 1.0481 1.5851 1.0568 1.0637
## [4,] 1.0328 1.5482 1.0321 1.0252
## [5,] 1.0174 1.5273 1.0182 1.0147
## [6,] 1.0098 1.5150 1.0100 1.0081
## [7,] 1.0054 1.5083 1.0055 1.0045
## [8,] 1.0030 1.5046 1.0031 1.0025
## [9,] 1.0016 1.5025 1.0017 1.0014
## [10,] 1.0009 1.5014 1.0009 1.0007
Plot the powers and SIR at end of each iteration
plot(1:10, pt1[, 1], ylim = c(0.1, 0.5), xlab = "iteration", ylab = "power (mW)",
col = "red", type = "l", lty = 2, main = "assignment 1b")
points(pt1[, 2], col = "dark green", type = "l", lty = 2)
points(pt1[, 3], col = "blue", type = "l", lty = 2)
points(pt1[, 4], col = "orange", type = "l", lty = 2)
legend("top", c("Link 1", "Link 2", "Link 3", "Link 4"), col = c("red", "dark green",
"blue", "orange"), lty = 2, text.width = 0.5, text.col = c("red", "dark green",
"blue", "orange"), cex = 0.6, bty = "n")
plot(1:10, SIR1[, 1], ylim = c(0.6, 2.5), xlab = "iteration", ylab = "SIR",
col = "red", type = "l", lty = 2, main = "assignment 1b")
points(SIR1[, 2], col = "dark green", type = "l", lty = 2)
points(SIR1[, 3], col = "blue", type = "l", lty = 2)
points(SIR1[, 4], col = "orange", type = "l", lty = 2)
legend("top", c("Link 1", "Link 2", "Link 3", "Link 4"), col = c("red", "dark green",
"blue", "orange"), lty = 2, text.width = 0.5, text.col = c("red", "dark green",
"blue", "orange"), cex = 0.6, bty = "n")