📄 z.java
字号:
* <p>
* <pre>
* exp(x + <i><b>i</b></i>*y) = exp(x) * ( cos(y) + <i><b>i</b></i> * sin(y) )
* </pre>
* <p>
* <i><b>Note:</b><ul> The value of <i><b>e</b></i>, a transcendental number, is
* roughly 2.71828182846...
* <p>
*
* Also, the following is quietly amazing:
* <pre>
* <i><b>e</b></i><sup><font size=+0><b>PI</b>*<i><b>i</b></i></font></sup> = - 1
* </pre>
* </ul>
* </i>
* <p>
* @return <i><b>e</b></i> "raised to the power of" this <tt>Complex</tt>
* <p>
* @see Complex#log()
* @see Complex#pow(double, Complex)
**/
public Z exp ()
{
double scalar = Math.exp(re); // e^ix = cis x
return cart( scalar * Math.cos(im), scalar * Math.sin(im) );
}
/**
* Returns the <i>principal</i> natural logarithm of a <tt>Complex</tt>
* number.
*
* <p>
* <pre>
* log(z) = log(abs(z)) + <i><b>i</b></i> * arg(z)
* </pre>
* <p>
* There are infinitely many solutions, besides the principal solution.
* If <b>L</b> is the principal solution of <i>log(z)</i>, the others are of
* the form:
* <p>
* <pre>
* <b>L</b> + (2*k*<b>PI</b>)*<i><b>i</b></i>
* </pre>
* <p>
* where k is any integer.
* <p>
* @return Principal <tt>Complex</tt> natural logarithm
* <p>
* @see Complex#exp()
**/
public Z log()
{
return cart( Math.log(this.abs()), this.arg() ); // principal value
}
/**
* Returns the sine of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* sin(z) = ( exp(<i><b>i</b></i>*z) - exp(-<i><b>i</b></i>*z) ) / (2*<i><b>i</b></i>)
* </pre>
* <p>
* @return The <tt>Complex</tt> sine
* <p>
* @see Complex#asin()
* @see Complex#sinh()
* @see Complex#cosec()
* @see Complex#cos()
* @see Complex#tan()
**/
public Z sin ()
{
Z result;
// sin(z) = ( exp(i*z) - exp(-i*z) ) / (2*i)
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _1: _1.Minus(_2) ...
_re1 = _re1 - _re2; // !!!
_im1 = _im1 - _im2; // !!!
// result: _1.Div(2*i) ...
result = cart( 0.5*_im1, -0.5*_re1 );
// ... result = cart(_re1, _im1);
// Div(result, 0.0, 2.0);
return result;
}
/**
* Returns the cosine of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* cos(z) = ( exp(<i><b>i</b></i>*z) + exp(-<i><b>i</b></i>*z) ) / 2
* </pre>
* <p>
* @return The <tt>Complex</tt> cosine
* <p>
* @see Complex#acos()
* @see Complex#cosh()
* @see Complex#sec()
* @see Complex#sin()
* @see Complex#tan()
**/
public Z cos()
{
Z result;
// cos(z) = ( exp(i*z) + exp(-i*z) ) / 2
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _1: _1.Plus(_2) ...
_re1 = _re1 + _re2; // !!!
_im1 = _im1 + _im2; // !!!
// result: _1.scale(0.5) ...
result = cart( 0.5 * _re1, 0.5 * _im1 );
return result;
}
/**
* Returns the tangent of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* tan(z) = sin(z) / cos(z)
* </pre>
* <p>
* <i><b>Domain Restrictions:</b><ul> tan(z) is undefined whenever z = (k + 1/2) * <tt><b>PI</b></tt><br>
* where k is any integer
* </ul></i>
* <p>
* @return The <tt>Complex</tt> tangent
* <p>
* @see Complex#atan()
* @see Complex#tanh()
* @see Complex#cot()
* @see Complex#sin()
* @see Complex#cos()
**/
public Z tan()
{
Z result;
// tan(z) = sin(z) / cos(z)
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
double _re3, _im3;
double cs_re, cs_im;
// sin() ...
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _3: _1.Minus(_2) ...
_re3 = _re1 - _re2;
_im3 = _im1 - _im2;
// result: _3.Div(2*i) ...
result = cart( 0.5*_im3, -0.5*_re3 );
// result = cart(_re3, _im3);
// Div(result, 0.0, 2.0);
// cos() ...
// _3: _1.Plus(_2) ...
_re3 = _re1 + _re2;
_im3 = _im1 + _im2;
// cs: _3.scale(0.5) ...
cs_re = 0.5 * _re3;
cs_im = 0.5 * _im3;
// result: result.Div(cs) ...
Div(result, cs_re, cs_im);
return result;
}
/**
* Returns the cosecant of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* cosec(z) = 1 / sin(z)
* </pre>
* <p>
* <i><b>Domain Restrictions:</b><ul> cosec(z) is undefined whenever z = k * <tt><b>PI</b></tt><br>
* where k is any integer
* </ul></i>
* <p>
* @return The <tt>Complex</tt> cosecant
* <p>
* @see Complex#sin()
* @see Complex#sec()
* @see Complex#cot()
**/
public Z cosec ()
{
Z result;
// cosec(z) = 1 / sin(z)
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _1: _1.Minus(_2) ...
_re1 = _re1 - _re2; // !!!
_im1 = _im1 - _im2; // !!!
// _result: _1.Div(2*i) ...
result = cart( 0.5*_im1, -0.5*_re1 );
// result = cart(_re1, _im1);
// Div(result, 0.0, 2.0);
// result: one.Div(_result) ...
inv(result);
return result;
}
/**
* Returns the secant of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* sec(z) = 1 / cos(z)
* </pre>
* <p>
* <i><b>Domain Restrictions:</b><ul> sec(z) is undefined whenever z = (k + 1/2) * <tt><b>PI</b></tt><br>
* where k is any integer
* </ul></i>
* <p>
* @return The <tt>Complex</tt> secant
* <p>
* @see Complex#cos()
* @see Complex#cosec()
* @see Complex#cot()
**/
public Z sec ()
{
Z result;
// sec(z) = 1 / cos(z)
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _1: _1.Plus(_2) ...
_re1 = _re1 + _re2;
_im1 = _im1 + _im2;
// result: _1.scale(0.5) ...
result = cart(0.5*_re1, 0.5*_im1);
// result: one.Div(result) ...
inv(result);
return result;
}
/**
* Returns the cotangent of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* cot(z) = 1 / tan(z)
* </pre>
* <p>
* <i><b>Domain Restrictions:</b><ul> cot(z) is undefined whenever z = k * <tt><b>PI</b></tt><br>
* where k is any integer
* </ul></i>
* <p>
* @return The <tt>Complex</tt> cotangent
* <p>
* @see Complex#tan()
* @see Complex#cosec()
* @see Complex#sec()
**/
public Z cot()
{
Z result;
// cot(z) = 1 / tan(z) = cos(z) / sin(z)
double scalar;
double iz_re, iz_im;
double _re1, _im1;
double _re2, _im2;
double _re3, _im3;
double sn_re, sn_im;
// cos() ...
// iz: i.Times(z) ...
iz_re = -im;
iz_im = re;
// _1: iz.exp() ...
scalar = Math.exp(iz_re);
_re1 = scalar * Math.cos(iz_im);
_im1 = scalar * Math.sin(iz_im);
// _2: iz.neg().exp() ...
scalar = Math.exp(-iz_re);
_re2 = scalar * Math.cos(-iz_im);
_im2 = scalar * Math.sin(-iz_im);
// _3: _1.Plus(_2) ...
_re3 = _re1 + _re2;
_im3 = _im1 + _im2;
// result: _3.scale(0.5) ...
result = cart( 0.5*_re3, 0.5*_im3 );
// sin() ...
// _3: _1.Minus(_2) ...
_re3 = _re1 - _re2;
_im3 = _im1 - _im2;
// sn: _3.Div(2*i) ...
sn_re = 0.5 * _im3; // !!!
sn_im = - 0.5 * _re3; // !!!
// result: result.Div(sn) ...
Div(result, sn_re, sn_im);
return result;
}
/**
* Returns the hyperbolic sine of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* sinh(z) = ( exp(z) - exp(-z) ) / 2
* </pre>
* <p>
* @return The <tt>Complex</tt> hyperbolic sine
* <p>
* @see Complex#sin()
* @see Complex#asinh()
**/
public Z sinh ()
{
Z result;
// sinh(z) = ( exp(z) - exp(-z) ) / 2
double scalar;
double _re1, _im1;
double _re2, _im2;
// _1: z.exp() ...
scalar = Math.exp(re);
_re1 = scalar * Math.cos(im);
_im1 = scalar * Math.sin(im);
// _2: z.neg().exp() ...
scalar = Math.exp(-re);
_re2 = scalar * Math.cos(-im);
_im2 = scalar * Math.sin(-im);
// _1: _1.Minus(_2) ...
_re1 = _re1 - _re2; // !!!
_im1 = _im1 - _im2; // !!!
// result: _1.scale(0.5) ...
result = cart( 0.5 * _re1, 0.5 * _im1 );
return result;
}//end sinh()
/**
* Returns the hyperbolic cosine of a <tt>Complex</tt> number.
*
* <p>
* <pre>
* cosh(z) = ( exp(z) + exp(-z) ) / 2
* </pre>
* <p>
* @return The <tt>Complex</tt> hyperbolic cosine
* <p>
* @see Complex#cos()
* @see Complex#acosh()
**/
public Z cosh ()
{
Z result;
// cosh(z) = ( exp(z) + exp(-z) ) / 2
double scalar;
double _re1, _im1;
double _re2, _im2;
// _1: z.exp() ...
scalar = Math.exp(re);
_re1 = scalar * Math.cos(im);
_im1 = scalar * Math.sin(im);
// _2: z.neg().exp() ...
scalar = Math.exp(-re);
_re2 = scalar * Math.cos(-im);
_im2 = scalar * Math.sin(-im);
// _1: _1.Plus(_2) ...
_re1 = _re1 + _re2; // !!!
_im1 = _im1 + _im2; // !!!
// result: _1.scale(0.5) ...
result = cart( 0.5 * _re1, 0.5 * _im1 );
return result;
}//end cosh()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -