Hi Luc and friends,
I have a question more related to java matrix storage. If I have a
3-dimentional m matrix say 2 by 2 by 2, I want to access the matrix
efficiently so I would like to know the order in which the data is stored in
the memory. I am not sure if it is stored consecutively this way in the
memory register:
m(1,1,1), m(1,1,2), m(1,2,1), m(1,2,2), m(2,1,1), m(2,1,2), m(2,2,1),
m(2,2,2)
I also wonder if the package could store sparse vectors, matrices and
perform basic operations on them?
Thanks,
Cuong
-----Original Message-----
From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr]
Sent: Saturday, October 16, 2010 2:00 PM
To: Commons Users List
Subject: Re: [math] Re: complex matrix operation
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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
|