I have a 23 constant complex matrix and create a 31 matric created from 3 columns of a data frame(this should be done for each row) and the result is going to be a 2*1 matric called N. This should be applied to all of the rows so I define a while loop. Then N[1,1] and N[2,1] are used to calculate the final thing, but I am not getting the result I want, I calculated Q from each row!!! I put Q like Q[i] inside the loop and still not the result I wanted.
library(dplyr)
library(tidyr)
library(readxl)
library(Matrix)
library(matlib)
library(readxl)
library(MASS)
c1 <- c(2+3i,1+2i,3+4i)
c2 <- c(1+4i,4+6i,7+1i)
c3 <- c(4+5i,2+2i,3+4i)
c4=2
df <- data.frame(c1,c2,c3)
print(df)
a1 <- matrix(c(1+2i,2+4i,5+1i,1+2i,5+4i,2+2i),nrow=3,ncol=2, byrow=T)
a_inv <- ginv(a1)
print(a_inv)
i <-1
while(i <= nrow(df)){
C <- matrix(c(df$c1[1],df$c2[1],df$c3[1]), nrow=3, ncol=1)
N <- a_inv %*% C
N1 <- N[1,1]
N2 <- N[2,1]
i=i+1
}
Q <-((N1+N2)*c4)
print(Q)