The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 multiplying 2 matrices of complex numbers

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
bgelloz Posted - 07/03/2006 : 06:18:22 AM
Origin Version (Select Help-->About Origin): 7.5
Operating System: Win XP

- I would like to know if matrix defined and used only in the code can handle complex numbers. It seems it can.
- I want to multiply 2 matrices (with complex numbers) in the classic way of multiplying matrices. Should I just do for example Mat=Mat1*Mat2? I ask because I have strange results.
Thanks.
3   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 07/05/2006 : 12:16:58 PM
Hi bgelloz,

You can assign complex values to complex variables, including individual cells of a complex matrix, using the syntax:
complex_var = real_value + 1i * imaginary_value;

Also you can print out complex values using out_complex function.

So you can rewrite your code such as:


matrix<complex> mM(2,2);
mM[0][0] = cos(delta);
mM[0][1] = 1i * sin(delta)/etha;
mM[1][0] = 1i * etha * sin(delta);
mM[1][1] = cos(delta);
// or in this case
// mM[1][1] = mM[0][0];

out_complex("mM[0][0]=", mM[0][0]);
out_complex("mM[0][1]=", mM[0][1]);
out_complex("mM[1][0]=", mM[1][0]);
out_complex("mM[1][1]=", mM[1][1]);



Easwar
OriginLab

bgelloz Posted - 07/05/2006 : 05:15:12 AM
Thank you,
I have found my error: I was not using the "<complex>" after "matrix" in the function definition and imaginary parts were ignored in the result.
matrix<complex> GetMatrix(double delta,double etha)
{
matrix<complex> mM(2,2);
complex a00(cos(delta),0);
mM[0][0]=a00; //(cos(delta),0);
complex a01(0,(sin(delta)/etha));
mM[0][1]=a01; //(0,sin(delta)/etha);
complex a10(0,etha*sin(delta));
mM[1][0]=a10; //(0,etha*sin(delta));
complex a11(cos(delta),0);
mM[1][1]=a11; //(cos(delta),0);
return mM;
}
I could not figure out quickly how to assign directly the complex values to the matrix, so I used the above work around. I would appreciate a way to assign directly complex numbers to the 2X2 matrix.
Deanna Posted - 07/03/2006 : 9:38:46 PM
1. Matrix can handle complex numbers.
For example, you can define a complex matrix like this:
matrix<complex> mComplex = { 1+2i, 3+4i };

2. To multiply 2 matrices, you may use a member function of MatrixBase class--DotMultiply().
The following code shows how to multiply two complex matrix with this function.

void test4()
{
matrix<complex> m1 = { 1+2i, 3+4i };
matrix<complex> m2 = { {4+2i}, {5+4i} };
m2.DotMultiply( m1 );

complex cc=m2[0][0];
out_double("Real part = ", cc.m_re);
out_double("Imaginary part = ", cc.m_im);

cc=m2[0][1];
out_double("Real part = ", cc.m_re);
out_double("Imaginary part = ", cc.m_im);

}


Deanna
OriginLab GZ Office

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000