Complex number division of matrix over a vector
조회 수: 37 (최근 30일)
이전 댓글 표시
Hi, I am trying to divide a matrix that includes complex numbers with a vector that includes complex numbers. The cells in the resulting matrix are almost all equal to 0+0i. Why is that and how can I fix it to get the correct numbers?
Thanks
댓글 수: 0
채택된 답변
John D'Errico
2022년 10월 11일
편집: John D'Errico
2022년 10월 11일
You SAID divide. You did not say you were solving a linear system of equations, as that is what backslash does. Regardless, I'll assume you really did intend to solve that linear system.
Looking at your arrays, we see:
load a_f
load r_end
load R_nd
whos R_nd r_end a_f
So the computation:
a_f = -R_nd\r_end.';
solves the LINEAR system of equations for the vector x (you called it a_f), such that
(-R_nd)*x == r_end.'
But what does that mean? It needs to solve the problem for a vector of length 90.
You have only 15 equations. So backslash will compute only 15 non-zero unknowns. The other 75 of them will be EXACTLY zero. You don't have sufficient information content in those 15 equations to estimate 90 unknowns. All of those zeros are completely as expected.
nnz(a_f)
In fact, only 12 of them were non-zero, so it would appear that 3 of those equations were superfluous, and provided no additional information. This is consistent with the numerical rank of 12 as reported.
Anyway, why do I say the zeros are to be expected? Suppose I decided to solve a single equation,
x + y = 1
What is the solution? Linear algebra teaches us there are infinitely many choices we can make, infinitely many ways to solve that problem. The standard solution tells us to set some number of the unknowns to zero, since they are completely arbitrary. That is, we can arbitrarily choose to set x==0, and then compute y, or set y==0, and then compute x. Can we infer the value of BOTH x and y? Of course not. With limited informatino content, thus only 1 equation there, I cannot decide what both x and y must be.
There is one other common choice, and that is often called the minimum norm solution. (The minimum norm solution for the 2 variable problem I gave above would have x=y=1/2.) MATLAB returns that from the function lsqminnorm, thus
a_f = lsqminnorm(-R_nd,r_end.');
You could also have used other tools (some might suggest to use pinv, or lsqr, for example), but lsqminnorm may be what you want, and the name is quite descriptive. Really the choice is a bit arbitrary, since you simply do not have sufficient information to solve for all 90 unknowns.
댓글 수: 0
추가 답변 (1개)
David Hill
2022년 10월 11일
편집: David Hill
2022년 10월 11일
Obvisously the size of v must be consistent with the size of m. Attach your variables for additional help.
m=[randi(10,10)+1i*randi(10,10)];
v=[randi(10,1,10)+1i*randi(10,1,10)];
newMatrix=m./v
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!