📄 rot.java
字号:
package jmathlib.toolbox.jmathlib.matrix._private.Jampack;
/**
Rot generates and manipulates plane rotations. Given a 2-vector
compontents are x and y, there is a unitary matrix P such that
<pre>
* P|x| = | c s||x| = |z|
* |y| |-conj(s) c||y| |0|
</pre>
The number c, which is always real, is the cosine of the rotation.
The number s, which may be complex is the sine of the rotation.
<p>
Comments: This suite will eventually contain methods for real
rotations (two are already in place). The only difference
between real and complex rotations is that si and zi are zero
for the former. The final routines will do the efficient thing.
@version Pre-alpha
@author G. W. Stewart
*/
public class Rot{
/** The cosine of the rotation */
protected double c;
/** The real part of the sine of the rotation */
public double sr;
/** The imaginary part of the sine of the rotation */
public double si;
/** The real part of the first component of the transformed vector*/
public double zr;
/** The imaginary part of the first component of the transformed vector*/
public double zi;
/**
Given the real and imaginary parts of a 2-vector, genc returns
a plane rotation P such that
<pre>
* P|x| = | c s||x| = |z|
* |y| |-conj(s) c||y| |0|
</pre>
@param xr The real part of the first component of the 2-vector
@param xi The imaginary part of the first component of the 2-vector
@param yr The real part of the second component of the 2-vector
@param yi The imaginary part of the second component of the 2-vector
@return The rotation
*/
public static Rot genc(double xr, double xi, double yr, double yi){
double s, absx, absxy;
Rot P = new Rot();
if (xr == 0 && xi==0){
P.c = 0.;
P.sr = 1.;
P.si = 0.;
P.zr = yr;
P.zi = yi;
return P;
}
s = Math.abs(xr) + Math.abs(xi);
absx = s*Math.sqrt((xr/s)*(xr/s) + (xi/s)*(xi/s));
s = Math.abs(s) + Math.abs(yr) + Math.abs(yi);
absxy = s*Math.sqrt((absx/s)*(absx/s) + (yr/s)*(yr/s) + (yi/s)*(yi/s));
P.c = absx/absxy;
xr = xr/absx;
xi = xi/absx;
P.sr = (xr*yr + xi*yi)/absxy;
P.si = (xi*yr - xr*yi)/absxy;
P.zr = xr*absxy;
P.zi = xi*absxy;
return P;
}
/**
Given the real and imaginary parts of a 2-vector, genc generates
a plane rotation P such that
<pre>
* P|x| = | c s||x| = |z|
* |y| |-conj(s) c||y| |0|
</pre>
@param xr The real part of the first component of the 2-vector
@param xi The imaginary part of the first component of the 2-vector
@param yr The real part of the second component of the 2-vector
@param yi The imaginary part of the second component of the 2-vector
@param P The rotation (must be initialized)
*/
public static void genc(double xr, double xi, double yr, double yi, Rot P){
double s, absx, absxy;
if (xr == 0 && xi==0){
P.c = 0.;
P.sr = 1.;
P.si = 0.;
P.zr = yr;
P.zi = yi;
return;
}
s = Math.abs(xr) + Math.abs(xi);
absx = s*Math.sqrt((xr/s)*(xr/s) + (xi/s)*(xi/s));
s = Math.abs(s) + Math.abs(yr) + Math.abs(yi);
absxy = s*Math.sqrt((absx/s)*(absx/s) + (yr/s)*(yr/s) + (yi/s)*(yi/s));
P.c = absx/absxy;
xr = xr/absx;
xi = xi/absx;
P.sr = (xr*yr + xi*yi)/absxy;
P.si = (xi*yr - xr*yi)/absxy;
P.zr = xr*absxy;
P.zi = xi*absxy;
}
/**
Given a real 2-vector, genc returns
a real plane rotation P such that
<pre>
* P|x| = | c s||x| = |z|
* |y| |-s c||y| |0|
</pre>
@param x The first component of the two vector
@param y The second component of the two vector
@return The rotation
*/
public static Rot genc(double x, double y){
Rot P = new Rot();
P.si = 0.;
P.zi = 0.;
if (x==0 & y==0){
P.c = 1;
P.sr = 0.;
P.zr = 0.;
return P;
}
double s = Math.abs(x) + Math.abs(y);
P.zr = s*Math.sqrt((x/s)*(x/s) + (y/s)*(y/s));
P.c = x/P.zr;
P.sr = y/P.zr;
return P;
}
/**
Given a real 2-vectc, genc generates
a real plane rotation P such that
<pre>
* P|x| = | c s||x| = |z|
* |y| |-s c||y| |0|
</pre>
@param x The first component of the two vector
@param y The second component of the two vector
@param P The plane rotation
*/
public static void genc(double x, double y, Rot P){
P.si = 0.;
P.zi = 0.;
if (x==0 & y==0){
P.c = 1;
P.sr = 0.;
P.zr = 0.;
return;
}
double s = Math.abs(x) + Math.abs(y);
P.zr = s*Math.sqrt((x/s)*(x/s) + (y/s)*(y/s));
P.c = x/P.zr;
P.sr = y/P.zr;
}
/**
Given a Zmat A, genc returns a plane rotation that on
premultiplication into rows ii1 and ii2
annihilates A(ii2,jj). The element A(ii2,jj) is
overwriten by zero and the element A(ii1,jj) is
overwritten by its transformed value.
@param A The Zmat (altered)
@param ii1 The row index of the first element
@param ii2 The row index of the second element (the
one that is annihilated
@param jj The column index of the elements
@return The plane rotation
*/
public static Rot genc(Zmat A, int ii1, int ii2, int jj){
A.dirty = true;
int i1 = ii1 - A.basex;
int i2 = ii2 - A.basex;
int j = jj - A.basex;
Rot P = Rot.genc(A.re[i1][j], A.im[i1][j], A.re[i2][j], A.im[i2][j]);
A.re[i1][j] = P.zr;
A.im[i1][j] = P.zi;
A.re[i2][j] = 0;
A.im[i2][j] = 0;
return P;
}
/**
Given a Zmat A, genc generates a plane rotation that on
premultiplication into rows ii1 and ii2
annihilates A(ii2,jj). The element A(ii2,jj) is
overwriten by zero and the element A(ii1,jj) is
overwritten by its transformed value.
@param A The Zmat (altered)
@param ii1 The row index of the first element
@param ii2 The row index of the second element (the
one that is annihilated
@param jj The column index of the elements
@param P The plane rotation (must be initialized)
*/
public static void genc(Zmat A, int ii1, int ii2, int jj, Rot P){
A.dirty = true;
int i1 = ii1 - A.basex;
int i2 = ii2 - A.basex;
int j = jj - A.basex;
Rot.genc(A.re[i1][j], A.im[i1][j], A.re[i2][j], A.im[i2][j], P);
A.re[i1][j] = P.zr;
A.im[i1][j] = P.zi;
A.re[i2][j] = 0;
A.im[i2][j] = 0;
}
/**
Given the real and imaginary parts of a 2-vector, genr returns
a plane rotation such that
<pre>
* |x y|P = |x y|| c s||x| = |z 0|
* |-conj(s) c||y|
</pre>
@param xr The real part of the first component of the 2-vector
@param xi The imaginary part of the first component of the 2-vector
@param yr The real part of the second component of the 2-vector
@param yi The imaginary part of the second component of the 2-vector
@return The rotation
*/
public static Rot genr(double xr, double xi, double yr, double yi){
double s, absx, absxy;
Rot P = new Rot();
if (xr == 0 && xi==0){
P.c = 0.;
P.sr = 1.;
P.si = 0.;
P.zr = yr;
P.zi = yi;
return P;
}
s = Math.abs(xr) + Math.abs(xi);
absx = s*Math.sqrt((xr/s)*(xr/s) + (xi/s)*(xi/s));
s = Math.abs(s) + Math.abs(yr) + Math.abs(yi);
absxy = s*Math.sqrt((absx/s)*(absx/s) + (yr/s)*(yr/s) + (yi/s)*(yi/s));
P.c = absx/absxy;
xr = xr/absx;
xi = xi/absx;
P.sr = -(xr*yr + xi*yi)/absxy;
P.si = (xi*yr - xr*yi)/absxy;
P.zr = xr*absxy;
P.zi = xi*absxy;
return P;
}
/**
Given the real and imaginary parts of a 2-vector, genr generates
a plane rotation such that
<pre>
* |x y|P = |x y|| c s||x| = |z 0|
* |-conj(s) c||y|
</pre>
@param xr The real part of the first component of the 2-vector
@param xi The imaginary part of the first component of the 2-vector
@param yr The real part of the second component of the 2-vector
@param yi The imaginary part of the second component of the 2-vector
@param P The plane rotation (must be initialized)
*/
public static void genr(double xr, double xi, double yr, double yi, Rot P){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -