commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: [math] Re: complex matrix operation
Date Sat, 16 Oct 2010 18:59:47 GMT
Le 16/10/2010 20:38, Cuong P. Nguyen a écrit :
> Hi Luc and friends, 
> 
> Thanks a lot for the quick response
> 
> Could you give me any simple code example of Complex-type vector-matrix
> multiplication or matrix-matrix multiplication ?

Here is a matrix vector multiplication:

// create a 2x2 complex matrix
Complex[][] matrixData = new Complex[][] {
    { new Complex(1.0,  0.0), new Complex( 0.0, 1.0) },
    { new Complex(0.0, -1.0), new Complex(-1.0, 0.0) }
};
FieldMatrix<Complex> m = new Array2DRowFieldMatrix<Complex>(matrixData);

// create a vector
Complex[] vectorData = new Complex[] {
    new Complex(1.0, 2.0),
    new Complex(3.0, 4.0),
};
FieldVector<Complex> u = new ArrayFieldVector<Complex>(vectorData);

// perform matrix-vector multiplication
FieldVector<Complex> v = m.operate(u);

// print the initial vector
for (int i = 0; i < u.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(u.getEntry(i)));
}

System.out.println();

// print the result
for (int i = 0; i < v.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(v.getEntry(i)));
}



Luc

> 
> I am a new java beginner as well as new to Commons Math community.
> 
> Thanks,
> 
> Cuong
> 
> -----Original Message-----
> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
> Sent: Saturday, October 16, 2010 1:25 PM
> To: Commons Users List
> Subject: [math] Re: complex matrix operation
> 
> Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
>> Hi,
> 
> Hi Cuong,
> 
> First, please use a [math] marker on the subject line when posting to
> this list for the commons-math component. The list is shared among
> several commons components and these markers help filtering.
> 
>> can I use the package for basic complex-number matrix operations
>> (addition, subtraction, multiplication) ?
> 
> You can use the linear algebra packe from commons-math with complex
> matrices. The appropriate interface is FieldMatrix<Complex> which has
> two implementations: Array2DRowFieldMatrix<Complex> and
> BlockFieldMatrix<Complex>. The former should be preferred for small
> sizes and the later for large sizes. You can also use complex vectors
> and LU decomposition with these matrices.
> 
> Luc
> 
>>
>> Thanks
>>
>> Cuong
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message