1

I am currently using the Eigen library to convert some Matlab code to c++. I have been given the matlab code and it's as follows:

I have 2 Matrices N_R, G_R.

N_R is a 8 row 10 col matrix while

G_R is a diagonal matrix of an 8 value vector

There is a system matrix that has the term N_R .' * G_R * N_R in it.

I am having real trouble with this term and haven't been able to find what this combination of . ' * actually does.

I'm guessing it's some kind of transpose and multiply but I keep getting errors about the dimensions being mismatched.

Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
Vakath
  • 11
  • 2
  • 2
    `N_R . ' * G_R * N_R` is not valid MATLAB syntax. I almost felt sorry for your confusion. – Andras Deak -- Слава Україні Jul 22 '16 at 22:33
  • @AndrasDeak. Well, the only problem with it is the space between . and ', and that may be an editorial issue. – Johan Lundberg Jul 22 '16 at 22:39
  • @Johan I agree. But here's my train of thought: "Oh, basic syntax question, answered by 10k user, *bah*." --> "Oh, is *that* how the MATLAB code was written? Diabolical, who would do such a thing? Poor OP." --> "Waaaait a minute, that's not even valid MATLAB syntax. So why is somebody asking for syntax not even using the syntax they're asking about?". (I admit my grumpiness might have been effected by complications with SO Docs) – Andras Deak -- Слава Україні Jul 22 '16 at 22:43

2 Answers2

4

The ' operator in matlab is performing matrix conjugate, while .' performs a simple transposition, as explained at Using transpose versus ctranspose in MATLAB. Note that . ' is not valid, but .' is.

N_R.' * G_R * N_R

would with Eigen (Tutorial Matrix Arithmetic) be

N_R.transpose() * G_R * N_R

(Thanks @Dev-iL for pointing out that I swapped the two meanings in the original version of the answer)

Community
  • 1
  • 1
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
3

As you said, .' is the transpose operator (notice: it does not contain spaces) in MATLAB, while * is matrix multiplication.

Now, let's review the rest (I took the liberty to put parentheses for clarity):

(N_R.') * (G_R) * (N_R)
  • N_R is 8x10, so N_RT is 10x8.
  • (N_R.') * (G_R) is 10x8 * 8x8, so 10x8.
  • (N_R.') * (G_R) * N_R is therefore 10x8 * 8x10, so 10x10.
Graham
  • 7,431
  • 18
  • 59
  • 84
Dev-iL
  • 23,742
  • 7
  • 57
  • 99