Problem with complex number multiplication and division

Hello, thanks for looking at this, this is potentially a very stupid question.
I'm having a problem with signs for complex conjugates when I multiply complex numbers two ways. In the first way, I have a simple calculation:
Rws(n,m)+j*w(m)*Iws(n)-Cws(n,m)*j/w(m)
to give me a value (in this case, it was 1.366e+09 + 5.937e+09i). My matrices are [9 800] in size, and I wanted to not do this in loops, but instead vectorize the calculation. So, instead, I change it to this:
Rws+j*Iws*w-bsxfun(@rdivide, Cws*j, w);
and I get the same answer with a small twist: the sign on the complex number was switched (1.366e+09 - 5.937e+09i). This change in sign is prevalent in all other members in the matrix, but the calculation was identical. In this, Rws is a 9x800 matrix, Iws is a 9x1 vector, w is a 1x800 vector, and Cws is a 9x800 matrix.
I can bypass this problem by switching the addition with the subtraction in the second equation, but I wanted to know if there was a reason I was getting this mismatched sign. Any ideas?
Thanks for your help, I think I'm just missing something simple here.
EDIT: Included some matlab files for clarification, use run_it to run the program, check for the variables _forloop and _vectorized for reporting.

3 件のコメント

David Young
David Young 2015 年 10 月 12 日
I can't replicate the problem. This code gives identical results for Result1 and Result2.
Rws = rand(9, 800);
Cws = rand(9, 800);
Iws = rand(9, 1);
w = rand(1, 800);
Result1 = zeros(9, 800);
for n = 1:9
for m = 1:800
Result1(n,m) = Rws(n,m)+j*w(m)*Iws(n)-Cws(n,m)*j/w(m);
end
end
Result2 = Rws+j*Iws*w-bsxfun(@rdivide, Cws*j, w);
John D'Errico
John D'Errico 2015 年 10 月 12 日
My guess is you transposed something along the way. Since you have not actually shown us an explicit example, so we cannot know.
Brian
Brian 2015 年 10 月 13 日
First off, thanks to both for answering. I'll go into a little more of my problem. I can attach the m files I was working on modifying, if that will help you get an idea.
I took a look through it again, and the only thing I can think of is its a multiplication problem when I string along my vectorization.
I included the original MATLAB files: you can run the program with run_it, and the variables to look for are compliance_forloop, compliance_vectorized, inertiance_forloop, inertiance_vectorized. Zws is just a sum of resistance with those two components.
I can bypass this problem by switching addition with subtraction, but I'd rather try to understand the problem.
Thanks!

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2015 年 10 月 12 日

編集済み:

2015 年 10 月 13 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by