What is happening here is that v is a complex vector so if I perfom v' it results the transposed conjugate vector and that why norm( v' - sum_FR(j:enf)) ~=0. To fix that you just need to calculate the transposed vector using .' instead of '
Can someone explain this?
6 ビュー (過去 30 日間)
古いコメントを表示
Alex Bernadí Forteza
2022 年 7 月 31 日
回答済み: Alex Bernadí Forteza
2022 年 7 月 31 日
Hi everyone,
Something strange is happening in my code and I would like ti figure out. I have a nested loop like this:
sum_F = zeros(2048,188);
% E is a 1x2048 complex vector
for j = 1:188
disp(j)
v = zeros(1,2048);
for i = 1:2048
if find(freqind==i) % condition to reduce the number of points to be calculated
T = mat_T(nodes_steps(:,:,j), points, ka(i)); % nodes_steps is a 2080x3x188 tensor, points is a 3x3 matrix and k is a complex number
R = SL2_r(i).*eye(n_r); % diagonal matrix
R = sparse(R);
F = T.'*(R*sum(T,2)); % F is a 2080x1 complex vector
v(i) = sum(F)*E(i); %<---- case 1.
sum_F(i,j) = sum(F)*E(i); %<---- case 2
end
end
sum_FR(:,j) = v'.*exp(1i*2*pi*(frecs')/ct*z0); % <---- case 1
sum_FR(:,j) = sum_F(:,j).*exp(1i*2*pi*(frecs')/ct*z0); % <----- case 2
end
At first view everyone should think, as I did, that in both cases the value assignated to sum_FR(:,j) in every j-loop should be the same regardless of the case because in case 1 I am multiplying a column vector by a column vector. And in case 2 I am multiplying the same column vector by the other same column vector, and also v and the columns of matrix sum_F are calculated the same way. But in reality the results obtained in the case 1 are simetrics with obtained in case 2. As shown in the pictures:
Case 1

Case 2

When I realized this I started to investigate to see what was going on. And I found out that the norm between v' and sum_FR(:,j) is not 0 but 0.0333 and to me it doesn't make any sense because they should be the same vector. If I declare v as a column vector the norm between both vectors is now 0 as it should be. Can someone explain me what is happening? Why when I transpose the vector their values vary? Or why it has a different value if I declare it as a row vector or as a column vector?
P.S.: The correct result is the case 2
Thank you all!!
2 件のコメント
Jan
2022 年 7 月 31 日
Correct. Please post this as an answer, such that it can be selected as a solution.
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!