[ 
https://issues.apache.org/jira/browse/MATH-1557?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Randy Strauss updated MATH-1557:
--------------------------------
    Description: 
I have a real hamiltonian matrix and need to get complex eigenvalues and 
eigenvectors, just like MatLab produces (I'm moving code from MatLab to Java).

To give you a test case:

I wrap a RealMatrix in an RMatrix and add a name, to help with testing
 and use this to set a single or multiple values on a single row, starting at 
col c:
 {{   public void set(int r, int c, double...val) {...
 }}

Methods to create the hamiltonian matrix, the real and imaginary parts of the 
eigenvectors (which this library creates) and the real and imaginary parts of 
the eigenvectors follow.  Note that the eigenvalues (evals) come as a diagonal 
matrix.

(Meanwhile, I'll try the ojAlg library...  The only other one I haven't 
investigated is JEigen, a wrapper around the C++ eigen library...)

 

  was:
I have a real hamiltonian matrix and need to get complex eigenvalues and 
eigenvectors, just like MatLab produces (I'm moving code from MatLab to Java).

To give you a test case:

I wrap a RealMatrix in an RMatrix and add a name, to help with testing
and use this to set a single or multiple values on a single row, starting at 
col c:
{{   public void set(int r, int c, double...val) {...
}}

Methods to create the hamiltonian matrix, the real and imaginary parts of the 
eigenvectors (which this library creates) and the real and imaginary parts of 
the eigenvectors follow.  Note that the eigenvalues (evals) come as a diagonal 
matrix.

(Meanwhile, I'll try the ojAlg library...  The only other one I haven't 
investigated is JEigen, a wrapper around the C++ eigen library...)

{{RMatrix getHam() {}}
{{ RMatrix mm = RMatrix.zeros(24,24).setName("ml:Ham()");}}
{{ mm.set(0,9, 1.0);}}
{{ mm.set(1,10, 1.0);}}
{{ mm.set(2,11, 1.0);}}
{{ mm.set(3,6, 1.0);}}
{{ mm.set(4,7, 1.0);}}
{{ mm.set(5,8, 1.0);}}
{{ mm.set(6,18, -50.2882527112151934);}}
{{ mm.set(7,19, -50.2882527112151934);}}
{{ mm.set(8,20, -104.6706084865823385);}}
{{ mm.set(9,3, -0.0000000000000012, -9.8066499999999994);}}
{{ mm.set(10,3, 9.8066499999999994, -0.0000000000000012);}}
{{ mm.set(11,23, -2.6882428037761028);}}
{{ mm.set(12,0, -1000.0);}}
{{ mm.set(13,1, -1000.0);}}
{{ mm.set(14,2, -50000.0);}}
{{ mm.set(15,3, -1000.0);}}
{{ mm.setRow(15,21, 0.0000000000000012, -9.8066499999999994);}}
{{ mm.set(16,4, -1000.0);}}
{{ mm.setRow(16,21, 9.8066499999999994, 0.0000000000000012);}}
{{ mm.set(17,5, -20.0);}}
{{ mm.set(18,6, -10.0);}}
{{ mm.set(18,15, -1.0);}}
{{ mm.set(19,7, -10.0);}}
{{ mm.set(19,16, -1.0);}}
{{ mm.set(20,8, -5.0);}}
{{ mm.set(20,17, -1.0);}}
{{ mm.set(21,9, -100.0);}}
{{ mm.set(21,12, -1.0);}}
{{ mm.set(22,10, -100.0);}}
{{ mm.set(22,13, -1.0);}}
{{ mm.set(23,11, -4000.0);}}
{{ mm.set(23,14, -1.0);}}
{{return mm;}}
{{ }}}

{{RMatrix getRealEvals() {
 RMatrix mm = RMatrix.zeros(24,24).setName("ml:realEvals");
 mm.set(0,0, -19.2515559709009736);
 mm.set(1,1, 19.2515559709010127);
 mm.set(2,2, -11.0808348997399158);
 mm.set(3,3, 11.0808348997399193);
 mm.set(4,4, -2.7428623037015809);
 mm.set(5,5, -2.7428623037015809);
 mm.set(6,6, 2.7428623037015827);
 mm.set(7,7, 2.7428623037015827);
 mm.set(8,8, -103.636174429371124);
 mm.set(9,9, 103.6361744293712093);
 mm.set(10,10, -19.251555970901066);
 mm.set(11,11, 19.2515559709010518);
 mm.set(12,12, -11.0808348997399442);
 mm.set(13,13, 11.0808348997399424);
 mm.set(14,14, -22.7886373854221205);
 mm.set(15,15, 22.7886373854220921);
 mm.set(16,16, -2.7428623037015889);
 mm.set(17,17, -2.7428623037015889);
 mm.set(18,18, 2.742862303701588);
 mm.set(19,19, 2.742862303701588);
 mm.set(20,20, -3.5375930728932987);
 mm.set(21,21, -2.0077471326476353);
 mm.set(22,22, 2.0077471326476282);
 mm.set(23,23, 3.5375930728932929);
 return mm;
}
RMatrix getImagEvals() {
 RMatrix mm = RMatrix.zeros(24,24).setName("ml:imagEvals");
 mm.set(4,4, 1.6690370723880767);
 mm.set(5,5, -1.6690370723880767);
 mm.set(6,6, 1.6690370723880767);
 mm.set(7,7, -1.6690370723880767);
 mm.set(16,16, 1.6690370723880816);
 mm.set(17,17, -1.6690370723880816);
 mm.set(18,18, 1.6690370723880807);
 mm.set(19,19, -1.6690370723880807);
 return mm;
}

RMatrix getRealEvecs() {
 RMatrix mm = RMatrix.zeros(24,24).setName("ml:realEvecs");
 mm.set(0,0, 0.0004832230449602, -0.0004832230449602, -0.0009379501782333, 
0.0009379501782333, 0.0025918144777927, 0.0025918144777927, 0.0025918144777927, 
0.0025918144777927, -0.0, 0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0, 0.0, 0.0, 
-0.0, -0.0, 0.0, -0.0, 0.0, -0.0);
 mm.set(1,8, -0.0, 0.0, 0.0004832230449602, 0.0004832230449602, 
-0.0009379501782333, 0.0009379501782333, -0.0, -0.0, -0.0025918144777927, 
-0.0025918144777927, 0.0025918144777927, 0.0025918144777927, 0.0, 0.0, -0.0, 
-0.0);
 mm.set(2,8, 0.0002484038122836, -0.0002484038122836, 0.0, -0.0, 0.0, -0.0, 
0.0, 0.0, 0.0, 0.0, -0.0, -0.0, 0.0000707518552269, 0.0, -0.0, 
0.0000707518552269);
 mm.set(3,0, -0.0, 0.0, 0.0, -0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.0, 
0.0182624329599153, 0.0182624329599153, -0.0117436760551143, 
0.0117436760551143, 0.0, -0.0, 0.0002203558678773, 0.0002203558678773, 
-0.0002203558678772, -0.0002203558678772, -0.0, -0.0, -0.0, -0.0);
 mm.set(4,0, -0.0182624329599153, 0.0182624329599153, 0.0117436760551143, 
-0.0117436760551143, 0.0002203558678772, 0.0002203558678772, 
0.0002203558678772, 0.0002203558678772, 0.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 
0.0, -0.0, -0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.0);
 mm.set(5,0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, 0.0, 
0.0000000000000002, 0.0, -0.0000000000000001, -0.0000000000000001, -0.0, 
-0.0428074741554847, -0.0428074741554848, -0.0000000000000001, 
-0.0000000000000001, -0.0, -0.0, -0.0, 0.0979346456757011, 0.097934645675701, 
-0.0);
 mm.set(6,0, 0.0, 0.0, -0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0000000000000002, 
-0.0000000000000002, -0.3515802502926373, 0.3515802502926377, 
0.1301297354827506, 0.1301297354827507, -0.0000000000000002, -0.0, 
-0.0059148347790043, -0.0059148347790043, -0.0059148347790042, 
-0.0059148347790042, 0.0, -0.0, 0.0, -0.0);
 mm.set(7,0, 0.3515802502926374, 0.3515802502926376, -0.1301297354827509, 
-0.1301297354827506, -0.0059148347790042, -0.0059148347790042, 
0.0059148347790041, 0.0059148347790041, 0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 
0.0000000000000001, 0.0000000000000001, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, -0.0, 
-0.0);
 mm.set(8,8, 0.0000000000000001, -0.0000000000000023, -0.0000000000000002, 
-0.0000000000000003, 0.0, 0.0, 0.9755240059151693, -0.9755240059151695, 
-0.0000000000000002, -0.0000000000000002, -0.0000000000000002, 
-0.0000000000000002, 0.0, -0.196628004042251, 0.1966280040422509, -0.0);
 mm.set(9,0, -0.0093027954964812, -0.0093027954964812, 0.0103932710691854, 
0.0103932710691854, -0.0044767115132939, -0.0044767115132939, 
0.0044767115132939, 0.0044767115132939, 0.0, 0.0, 0.0, -0.0, 0.0, 0.0, -0.0, 
-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0);
 mm.set(10,0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, 
-0.0093027954964812, 0.0093027954964812, 0.0103932710691854, 
0.0103932710691854, -0.0, -0.0, 0.0044767115132939, 0.0044767115132939, 
0.0044767115132939, 0.0044767115132939, 0.0, 0.0, -0.0, -0.0);
 mm.set(11,8, -0.0257436208187483, -0.0257436208187483, -0.0, -0.0, 0.0, 0.0, 
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0002502912729449, -0.0, 0.0, 
0.0002502912729449);
 mm.set(12,0, 0.0251004669799487, 0.0251004669799487, -0.0846461649072455, 
-0.0846461649072456, 0.9449305837536955, 0.9449305837536955, 
-0.9449305837536957, -0.9449305837536957, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, -0.0, 0.0);
 mm.set(13,8, -0.0000000000000015, -0.0000000000000004, 0.0251004669799488, 
-0.0251004669799487, -0.0846461649072455, -0.0846461649072455, 
-0.0000000000000004, 0.0000000000000001, -0.9449305837536948, 
-0.9449305837536948, -0.9449305837536955, -0.9449305837536955, 
0.0000000000000001, 0.0000000000000013, 0.0000000000000009, 0.0000000000000005);
 mm.set(14,8, 0.1198441633200829, 0.1198441633200825, -0.0, -0.0, -0.0, 0.0, 
0.0000000000000001, -0.0000000000000001, 0.0000000000000006, 
0.0000000000000006, 0.0000000000000005, 0.0000000000000005, 0.9999999119316623, 
-0.0000000000000004, -0.0000000000000014, -0.9999999119316623);
 mm.set(15,0, -0.0000000000000001, -0.0000000000000001, 0.0000000000000001, 
0.0000000000000001, 0.0, 0.0, -0.0, -0.0, -0.0000000000000047, 
0.0000000000000008, 0.9246701470035759, -0.9246701470035759, 
-0.9835697352164537, -0.9835697352164535, 0.0000000000000004, 
-0.0000000000000002, 0.0570691616413982, 0.0570691616413982, 
0.0570691616413963, 0.0570691616413963, -0.0000000000000002, 
-0.0000000000000001, -0.0000000000000001, 0.0000000000000001);
 mm.set(16,0, -0.9246701470035759, -0.9246701470035759, 0.9835697352164536, 
0.9835697352164536, 0.0570691616413962, 0.0570691616413962, 
-0.0570691616413952, -0.0570691616413952, 0.0, 0.0, -0.0000000000000001, 
0.0000000000000001, 0.0000000000000002, 0.0000000000000002, 
-0.0000000000000001, -0.0000000000000001, -0.0, -0.0, -0.0, -0.0, 0.0, 
0.0000000000000001, 0.0000000000000001, -0.0);
 mm.set(17,8, -0.0000000000000004, 0.0000000000000007, 0.0000000000000001, 
0.0000000000000001, -0.0000000000000001, 0.0000000000000001, 
-0.0375691388927618, 0.0375691388927611, -0.0000000000000005, 
-0.0000000000000005, 0.0000000000000003, 0.0000000000000003, 
-0.0000000000000001, 0.9755675312214632, -0.9755675312214632, 
0.0000000000000002);
 mm.set(18,0, 0.0, -0.0, -0.0, 0.0, -0.0, -0.0, -0.0, -0.0, 
-0.0000000000000002, -0.0, -0.1345933990914463, -0.1345933990914461, 
0.0286736173299098, -0.0286736173299096, -0.0000000000000001, 0.0, 
-0.0006000508905014, -0.0006000508905014, 0.0006000508905015, 
0.0006000508905015, -0.0, -0.0, -0.0, 0.0);
 mm.set(19,0, 0.1345933990914462, -0.1345933990914462, -0.0286736173299099, 
0.0286736173299098, -0.0006000508905014, -0.0006000508905014, 
-0.0006000508905014, -0.0006000508905014, 0.0, 0.0, 0.0, 0.0, -0.0, 0.0, 0.0, 
-0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, -0.0, 0.0);
 mm.set(20,8, -0.0000000000000001, 0.0000000000000003, -0.0, 
0.0000000000000001, 0.0, -0.0, 0.2123887799355335, 0.2123887799355333, 
-0.0000000000000001, -0.0000000000000001, -0.0, -0.0, 0.0, -0.0037716348172817, 
-0.0037716348172816, -0.0);
 mm.set(21,0, -0.0470184895203464, 0.0470184895203463, 0.0861560478654635, 
-0.0861560478654635, -0.0077681276851642, -0.0077681276851642, 
-0.0077681276851642, -0.0077681276851642, 0.0, -0.0, 0.0, 0.0, 0.0, -0.0, -0.0, 
0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0);
 mm.set(22,8, -0.0000000000000011, -0.0000000000000002, -0.0470184895203463, 
-0.0470184895203464, 0.0861560478654634, -0.0861560478654634, 
-0.0000000000000001, 0.0, 0.007768127685165, 0.007768127685165, 
-0.0077681276851632, -0.0077681276851632, 0.0000000000000002, 
0.0000000000000007, -0.0000000000000001, 0.0000000000000001);
 mm.set(23,8, -0.9924588559737858, 0.9924588559737859, -0.0, 0.0, 
-0.0000000000000001, -0.0, -0.0, -0.0000000000000001, -0.0, -0.0, 0.0, 0.0, 
-0.0003293707964667, -0.0, 0.0, -0.0003293707964667);
 return mm;
}
@Override RMatrix getImagEvecs() {
 RMatrix mm = RMatrix.zeros(24,24).setName("ml:imagEvecs");
 mm.set(0,4, -0.0015771241751182, 0.0015771241751182, 0.0015771241751182, 
-0.0015771241751182);
 mm.set(0,16, 0.0, -0.0, -0.0, 0.0);
 mm.set(1,16, 0.0015771241751182, -0.0015771241751182, 0.0015771241751182, 
-0.0015771241751182);
 mm.set(2,16, -0.0, 0.0, 0.0, -0.0);
 mm.set(3,4, 0.0, -0.0, -0.0, 0.0);
 mm.set(3,16, 0.0031817321876536, -0.0031817321876536, 0.0031817321876535, 
-0.0031817321876535);
 mm.set(4,4, 0.0031817321876535, -0.0031817321876535, -0.0031817321876535, 
0.0031817321876535);
 mm.set(4,16, -0.0, 0.0, -0.0, 0.0);
 mm.set(5,4, 0.0, -0.0, 0.0, -0.0);
 mm.set(5,16, 0.0, -0.0, -0.0, 0.0);
 mm.set(6,4, -0.0, 0.0, -0.0, 0.0);
 mm.set(6,16, -0.0083592711653836, 0.0083592711653836, 0.0083592711653836, 
-0.0083592711653836);
 mm.set(7,4, -0.0083592711653836, 0.0083592711653836, -0.0083592711653835, 
0.0083592711653835);
 mm.set(7,16, 0.0, -0.0, -0.0, 0.0);
 mm.set(8,16, 0.0000000000000001, -0.0000000000000001, 0.0000000000000001, 
-0.0000000000000001);
 mm.set(9,4, 0.0086516688963765, -0.0086516688963765, 0.0086516688963765, 
-0.0086516688963765);
 mm.set(9,16, 0.0, -0.0, -0.0, 0.0);
 mm.set(10,4, -0.0, 0.0, -0.0, 0.0);
 mm.set(10,16, -0.0086516688963765, 0.0086516688963765, 0.0086516688963765, 
-0.0086516688963765);
 mm.set(11,16, -0.0, 0.0, 0.0, -0.0);
 mm.set(12,16, 0.0, -0.0, -0.0, 0.0);
 mm.set(14,16, 0.0000000000000003, -0.0000000000000003, -0.0000000000000007, 
0.0000000000000007);
 mm.set(15,4, 0.0, -0.0, 0.0, -0.0);
 mm.set(15,16, 0.0838820942848218, -0.0838820942848218, -0.0838820942848232, 
0.0838820942848232);
 mm.set(16,4, 0.0838820942848225, -0.0838820942848225, 0.0838820942848227, 
-0.0838820942848227);
 mm.set(16,16, -0.0, 0.0, 0.0, -0.0);
 mm.set(17,16, 0.0, -0.0, 0.0, -0.0);
 mm.set(18,4, -0.0, 0.0, 0.0, -0.0);
 mm.set(18,16, -0.0002596282538929, 0.0002596282538929, -0.0002596282538928, 
0.0002596282538928);
 mm.set(19,4, -0.000259628253893, 0.000259628253893, 0.000259628253893, 
-0.000259628253893);
 mm.set(19,16, 0.0, -0.0, 0.0, -0.0);
 mm.set(20,16, 0.0, -0.0, 0.0, -0.0);
 mm.set(21,4, 0.310697914145376, -0.310697914145376, -0.3106979141453762, 
0.3106979141453762);
 mm.set(21,16, 0.0, -0.0, 0.0, -0.0);
 mm.set(22,16, -0.310697914145378, 0.310697914145378, -0.310697914145376, 
0.310697914145376);
 mm.set(23,16, 0.0000000000000001, -0.0000000000000001, -0.0, 0.0);
 return mm;
}
}}


> Enhancement request: Complex Eigen Vectors
> ------------------------------------------
>
>                 Key: MATH-1557
>                 URL: https://issues.apache.org/jira/browse/MATH-1557
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.6.1
>            Reporter: Randy Strauss
>            Priority: Major
>         Attachments: real-eigen-vectors-test-case.txt
>
>
> I have a real hamiltonian matrix and need to get complex eigenvalues and 
> eigenvectors, just like MatLab produces (I'm moving code from MatLab to Java).
> To give you a test case:
> I wrap a RealMatrix in an RMatrix and add a name, to help with testing
>  and use this to set a single or multiple values on a single row, starting at 
> col c:
>  {{   public void set(int r, int c, double...val) {...
>  }}
> Methods to create the hamiltonian matrix, the real and imaginary parts of the 
> eigenvectors (which this library creates) and the real and imaginary parts of 
> the eigenvectors follow.  Note that the eigenvalues (evals) come as a 
> diagonal matrix.
> (Meanwhile, I'll try the ojAlg library...  The only other one I haven't 
> investigated is JEigen, a wrapper around the C++ eigen library...)
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to