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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 multiplying 2 matrices of complex numbers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bgelloz

Japan
Posts

Posted - 07/03/2006 :  06:18:22 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Deanna

China
Posts

Posted - 07/03/2006 :  9:38:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

bgelloz

Japan
Posts

Posted - 07/05/2006 :  05:15:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

easwar

USA
1965 Posts

Posted - 07/05/2006 :  12:16:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000