0

I am implementing a code for GP which is an iterative algorithm and I have a few concerns. I was hoping someone can help me figure out the logic:

1) I need to be able to start with an initial starting point b that satisfies the condition of the constraints as Ab = c

Here is the matrix A and vector c

A <- rbind(c(1,1,1),c(-1,1,-1))
c <- c(0,5)

I tried the following 2 approaches to find b0 as an initial point to start the iteration

b0 <- solve(t(A)%*%A)%*%t(A)%*%c
b0 <- ginv(A)%*%c

but when I check the code below, I don't get all the b0 components right.

A %*% b0 == c

Can you help me figure out a better way to obtain the initial point that satisfies the condition Ab=c?

Thanks

Olel Dias
  • 53
  • 6

1 Answers1

0

I suspect your question may be answered by Why are these numbers not equal?. To quote the accepted answer,

Since not all numbers can be represented exactly in IEEE floating point arithmetic (the standard that almost all computers use to represent decimal numbers and do math with them), you will not always get what you expected.

all.equal in this case would return TRUE.

A <- rbind(c(1, 1, 1),c(-1, 1, -1))
C <- matrix(c(0,5), nc = 1)
b0 <- MASS::ginv(A) %*% C

A %*% b0 == C
#       [,1]
# [1,] FALSE
# [2,] FALSE
all.equal(A %*% b0, C)
# [1] TRUE
Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48
  • Thank you, but this is not what I am looking for. I need to find initial point in different way and then check the answer – Olel Dias Apr 13 '18 at 04:46
  • May I make a suggestion? Perhaps you could reword your question. In its current form, you seem to asking why `ginv(A) %*% c` does not yield the right answer. (It does.) If you are looking for an alternative to `ginv(A) %*% c` you should state as such in your question. ("A better way" in what sense?) – Weihuang Wong Apr 13 '18 at 15:00