⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math::complex.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
\&        z1 * z2 = (r1 * r2) * exp(i * (t1 + t2))\&        z1 / z2 = (r1 / r2) * exp(i * (t1 \- t2))\&        z1 ** z2 = exp(z2 * log z1)\&        ~z = a \- bi\&        abs(z) = r1 = sqrt(a*a + b*b)\&        sqrt(z) = sqrt(r1) * exp(i * t/2)\&        exp(z) = exp(a) * exp(i * b)\&        log(z) = log(r1) + i*t\&        sin(z) = 1/2i (exp(i * z1) \- exp(\-i * z))\&        cos(z) = 1/2 (exp(i * z1) + exp(\-i * z))\&        atan2(y, x) = atan(y / x) # Minding the right quadrant, note the order..Ve.PPThe definition used for complex arguments of \fIatan2()\fR is.PP.Vb 1\&       \-i log((x + iy)/sqrt(x*x+y*y)).Ve.PPNote that atan2(0, 0) is not well-defined..PPThe following extra operations are supported on both real and complexnumbers:.PP.Vb 4\&        Re(z) = a\&        Im(z) = b\&        arg(z) = t\&        abs(z) = r\&\&        cbrt(z) = z ** (1/3)\&        log10(z) = log(z) / log(10)\&        logn(z, n) = log(z) / log(n)\&\&        tan(z) = sin(z) / cos(z)\&\&        csc(z) = 1 / sin(z)\&        sec(z) = 1 / cos(z)\&        cot(z) = 1 / tan(z)\&\&        asin(z) = \-i * log(i*z + sqrt(1\-z*z))\&        acos(z) = \-i * log(z + i*sqrt(1\-z*z))\&        atan(z) = i/2 * log((i+z) / (i\-z))\&\&        acsc(z) = asin(1 / z)\&        asec(z) = acos(1 / z)\&        acot(z) = atan(1 / z) = \-i/2 * log((i+z) / (z\-i))\&\&        sinh(z) = 1/2 (exp(z) \- exp(\-z))\&        cosh(z) = 1/2 (exp(z) + exp(\-z))\&        tanh(z) = sinh(z) / cosh(z) = (exp(z) \- exp(\-z)) / (exp(z) + exp(\-z))\&\&        csch(z) = 1 / sinh(z)\&        sech(z) = 1 / cosh(z)\&        coth(z) = 1 / tanh(z)\&\&        asinh(z) = log(z + sqrt(z*z+1))\&        acosh(z) = log(z + sqrt(z*z\-1))\&        atanh(z) = 1/2 * log((1+z) / (1\-z))\&\&        acsch(z) = asinh(1 / z)\&        asech(z) = acosh(1 / z)\&        acoth(z) = atanh(1 / z) = 1/2 * log((1+z) / (z\-1)).Ve.PP\&\fIarg\fR, \fIabs\fR, \fIlog\fR, \fIcsc\fR, \fIcot\fR, \fIacsc\fR, \fIacot\fR, \fIcsch\fR,\&\fIcoth\fR, \fIacosech\fR, \fIacotanh\fR, have aliases \fIrho\fR, \fItheta\fR, \fIln\fR,\&\fIcosec\fR, \fIcotan\fR, \fIacosec\fR, \fIacotan\fR, \fIcosech\fR, \fIcotanh\fR,\&\fIacosech\fR, \fIacotanh\fR, respectively.  \f(CW\*(C`Re\*(C'\fR, \f(CW\*(C`Im\*(C'\fR, \f(CW\*(C`arg\*(C'\fR, \f(CW\*(C`abs\*(C'\fR,\&\f(CW\*(C`rho\*(C'\fR, and \f(CW\*(C`theta\*(C'\fR can be used also as mutators.  The \f(CW\*(C`cbrt\*(C'\fRreturns only one of the solutions: if you want all three, use the\&\f(CW\*(C`root\*(C'\fR function..PPThe \fIroot\fR function is available to compute all the \fIn\fRroots of some complex, where \fIn\fR is a strictly positive integer.There are exactly \fIn\fR such roots, returned as a list. Getting thenumber mathematicians call \f(CW\*(C`j\*(C'\fR such that:.PP.Vb 1\&        1 + j + j*j = 0;.Ve.PPis a simple matter of writing:.PP.Vb 1\&        $j = ((root(1, 3))[1];.Ve.PPThe \fIk\fRth root for \f(CW\*(C`z = [r,t]\*(C'\fR is given by:.PP.Vb 1\&        (root(z, n))[k] = r**(1/n) * exp(i * (t + 2*k*pi)/n).Ve.PPYou can return the \fIk\fRth root directly by \f(CW\*(C`root(z, n, k)\*(C'\fR,indexing starting from \fIzero\fR and ending at \fIn \- 1\fR..PPThe \fIspaceship\fR comparison operator, <=>, is also defined. Inorder to ensure its restriction to real numbers is conform to what youwould expect, the comparison is run on the real part of the complexnumber first, and imaginary parts are compared only when the realparts match..SH "CREATION".IX Header "CREATION"To create a complex number, use either:.PP.Vb 2\&        $z = Math::Complex\->make(3, 4);\&        $z = cplx(3, 4);.Ve.PPif you know the cartesian form of the number, or.PP.Vb 1\&        $z = 3 + 4*i;.Ve.PPif you like. To create a number using the polar form, use either:.PP.Vb 2\&        $z = Math::Complex\->emake(5, pi/3);\&        $x = cplxe(5, pi/3);.Ve.PPinstead. The first argument is the modulus, the second is the angle(in radians, the full circle is 2*pi).  (Mnemonic: \f(CW\*(C`e\*(C'\fR is used as anotation for complex numbers in the polar form)..PPIt is possible to write:.PP.Vb 1\&        $x = cplxe(\-3, pi/4);.Ve.PPbut that will be silently converted into \f(CW\*(C`[3,\-3pi/4]\*(C'\fR, since themodulus must be non-negative (it represents the distance to the originin the complex plane)..PPIt is also possible to have a complex number as either argument of the\&\f(CW\*(C`make\*(C'\fR, \f(CW\*(C`emake\*(C'\fR, \f(CW\*(C`cplx\*(C'\fR, and \f(CW\*(C`cplxe\*(C'\fR: the appropriate component ofthe argument will be used..PP.Vb 2\&        $z1 = cplx(\-2,  1);\&        $z2 = cplx($z1, 4);.Ve.PPThe \f(CW\*(C`new\*(C'\fR, \f(CW\*(C`make\*(C'\fR, \f(CW\*(C`emake\*(C'\fR, \f(CW\*(C`cplx\*(C'\fR, and \f(CW\*(C`cplxe\*(C'\fR will alsounderstand a single (string) argument of the forms.PP.Vb 5\&        2\-3i\&        \-3i\&        [2,3]\&        [2,\-3pi/4]\&        [2].Ve.PPin which case the appropriate cartesian and exponential componentswill be parsed from the string and used to create new complex numbers.The imaginary component and the theta, respectively, will default to zero..PPThe \f(CW\*(C`new\*(C'\fR, \f(CW\*(C`make\*(C'\fR, \f(CW\*(C`emake\*(C'\fR, \f(CW\*(C`cplx\*(C'\fR, and \f(CW\*(C`cplxe\*(C'\fR will alsounderstand the case of no arguments: this means plain zero or (0, 0)..SH "DISPLAYING".IX Header "DISPLAYING"When printed, a complex number is usually shown under its cartesianstyle \fIa+bi\fR, but there are legitimate cases where the polar style\&\fI[r,t]\fR is more appropriate.  The process of converting the complexnumber into a string that can be displayed is known as \fIstringification\fR..PPBy calling the class method \f(CW\*(C`Math::Complex::display_format\*(C'\fR andsupplying either \f(CW"polar"\fR or \f(CW"cartesian"\fR as an argument, youoverride the default display style, which is \f(CW"cartesian"\fR. Notsupplying any argument returns the current settings..PPThis default can be overridden on a per-number basis by calling the\&\f(CW\*(C`display_format\*(C'\fR method instead. As before, not supplying any argumentreturns the current display style for this number. Otherwise whatever youspecify will be the new display style for \fIthis\fR particular number..PPFor instance:.PP.Vb 1\&        use Math::Complex;\&\&        Math::Complex::display_format(\*(Aqpolar\*(Aq);\&        $j = (root(1, 3))[1];\&        print "j = $j\en";               # Prints "j = [1,2pi/3]"\&        $j\->display_format(\*(Aqcartesian\*(Aq);\&        print "j = $j\en";               # Prints "j = \-0.5+0.866025403784439i".Ve.PPThe polar style attempts to emphasize arguments like \fIk*pi/n\fR(where \fIn\fR is a positive integer and \fIk\fR an integer within [\-9, +9]),this is called \fIpolar pretty-printing\fR..PPFor the reverse of stringifying, see the \f(CW\*(C`make\*(C'\fR and \f(CW\*(C`emake\*(C'\fR..Sh "\s-1CHANGED\s0 \s-1IN\s0 \s-1PERL\s0 5.6".IX Subsection "CHANGED IN PERL 5.6"The \f(CW\*(C`display_format\*(C'\fR class method and the corresponding\&\f(CW\*(C`display_format\*(C'\fR object method can now be called usinga parameter hash instead of just a one parameter..PPThe old display format style, which can have values \f(CW"cartesian"\fR or\&\f(CW"polar"\fR, can be changed using the \f(CW"style"\fR parameter..PP.Vb 1\&        $j\->display_format(style => "polar");.Ve.PPThe one parameter calling convention also still works..PP.Vb 1\&        $j\->display_format("polar");.Ve.PPThere are two new display parameters..PPThe first one is \f(CW"format"\fR, which is a \fIsprintf()\fR\-style format stringto be used for both numeric parts of the complex number(s).  The issomewhat system-dependent but most often it corresponds to \f(CW"%.15g"\fR.You can revert to the default by setting the \f(CW\*(C`format\*(C'\fR to \f(CW\*(C`undef\*(C'\fR..PP.Vb 1\&        # the $j from the above example\&\&        $j\->display_format(\*(Aqformat\*(Aq => \*(Aq%.5f\*(Aq);\&        print "j = $j\en";               # Prints "j = \-0.50000+0.86603i"\&        $j\->display_format(\*(Aqformat\*(Aq => undef);\&        print "j = $j\en";               # Prints "j = \-0.5+0.86603i".Ve.PPNotice that this affects also the return values of the\&\f(CW\*(C`display_format\*(C'\fR methods: in list context the whole parameter hashwill be returned, as opposed to only the style parameter value.This is a potential incompatibility with earlier versions if youhave been calling the \f(CW\*(C`display_format\*(C'\fR method in list context..PPThe second new display parameter is \f(CW"polar_pretty_print"\fR, which canbe set to true or false, the default being true.  See the previoussection for what this means..SH "USAGE".IX Header "USAGE"Thanks to overloading, the handling of arithmetics with complex numbersis simple and almost transparent..PPHere are some examples:.PP.Vb 1\&        use Math::Complex;\&\&        $j = cplxe(1, 2*pi/3);  # $j ** 3 == 1\&        print "j = $j, j**3 = ", $j ** 3, "\en";\&        print "1 + j + j**2 = ", 1 + $j + $j**2, "\en";\&\&        $z = \-16 + 0*i;                 # Force it to be a complex\&        print "sqrt($z) = ", sqrt($z), "\en";\&\&        $k = exp(i * 2*pi/3);\&        print "$j \- $k = ", $j \- $k, "\en";\&\&        $z\->Re(3);                      # Re, Im, arg, abs,\&        $j\->arg(2);                     # (the last two aka rho, theta)\&                                        # can be used also as mutators..Ve.Sh "\s-1PI\s0".IX Subsection "PI"The constant \f(CW\*(C`pi\*(C'\fR and some handy multiples of it (pi2, pi4,and pip2 (pi/2) and pip4 (pi/4)) are also available if separatelyexported:.PP.Vb 2\&    use Math::Complex \*(Aq:pi\*(Aq; \&    $third_of_circle = pi2 / 3;.Ve.SH "ERRORS DUE TO DIVISION BY ZERO OR LOGARITHM OF ZERO".IX Header "ERRORS DUE TO DIVISION BY ZERO OR LOGARITHM OF ZERO"The division (/) and the following functions.PP.Vb 5\&        log     ln      log10   logn\&        tan     sec     csc     cot\&        atan    asec    acsc    acot\&        tanh    sech    csch    coth\&        atanh   asech   acsch   acoth.Ve.PPcannot be computed for all arguments because that would mean dividingby zero or taking logarithm of zero. These situations cause fatalruntime errors looking like this.PP.Vb 3\&        cot(0): Division by zero.\&        (Because in the definition of cot(0), the divisor sin(0) is 0)\&        Died at ....Ve.PPor.PP.Vb 2\&        atanh(\-1): Logarithm of zero.\&        Died at....Ve.PPFor the \f(CW\*(C`csc\*(C'\fR, \f(CW\*(C`cot\*(C'\fR, \f(CW\*(C`asec\*(C'\fR, \f(CW\*(C`acsc\*(C'\fR, \f(CW\*(C`acot\*(C'\fR, \f(CW\*(C`csch\*(C'\fR, \f(CW\*(C`coth\*(C'\fR,\&\f(CW\*(C`asech\*(C'\fR, \f(CW\*(C`acsch\*(C'\fR, the argument cannot be \f(CW0\fR (zero).  For thelogarithmic functions and the \f(CW\*(C`atanh\*(C'\fR, \f(CW\*(C`acoth\*(C'\fR, the argument cannotbe \f(CW1\fR (one).  For the \f(CW\*(C`atanh\*(C'\fR, \f(CW\*(C`acoth\*(C'\fR, the argument cannot be\&\f(CW\*(C`\-1\*(C'\fR (minus one).  For the \f(CW\*(C`atan\*(C'\fR, \f(CW\*(C`acot\*(C'\fR, the argument cannot be\&\f(CW\*(C`i\*(C'\fR (the imaginary unit).  For the \f(CW\*(C`atan\*(C'\fR, \f(CW\*(C`acoth\*(C'\fR, the argumentcannot be \f(CW\*(C`\-i\*(C'\fR (the negative imaginary unit).  For the \f(CW\*(C`tan\*(C'\fR,\&\f(CW\*(C`sec\*(C'\fR, \f(CW\*(C`tanh\*(C'\fR, the argument cannot be \fIpi/2 + k * pi\fR, where \fIk\fRis any integer.  atan2(0, 0) is undefined, and if the complex argumentsare used for \fIatan2()\fR, a division by zero will happen if z1**2+z2**2 == 0..PPNote that because we are operating on approximations of real numbers,these errors can happen when merely `too close' to the singularitieslisted above..SH "ERRORS DUE TO INDIGESTIBLE ARGUMENTS".IX Header "ERRORS DUE TO INDIGESTIBLE ARGUMENTS"The \f(CW\*(C`make\*(C'\fR and \f(CW\*(C`emake\*(C'\fR accept both real and complex arguments.When they cannot recognize the arguments they will die with errormessages like the following.PP.Vb 4\&    Math::Complex::make: Cannot take real part of ...\&    Math::Complex::make: Cannot take real part of ...\&    Math::Complex::emake: Cannot take rho of ...\&    Math::Complex::emake: Cannot take theta of ....Ve.SH "BUGS".IX Header "BUGS"Saying \f(CW\*(C`use Math::Complex;\*(C'\fR exports many mathematical routines in thecaller environment and even overrides some (\f(CW\*(C`sqrt\*(C'\fR, \f(CW\*(C`log\*(C'\fR, \f(CW\*(C`atan2\*(C'\fR).This is construed as a feature by the Authors, actually... ;\-).PPAll routines expect to be given real or complex numbers. Don't attempt touse BigFloat, since Perl has currently no rule to disambiguate a '+'operation (for instance) between two overloaded entities..PPIn Cray \s-1UNICOS\s0 there is some strange numerical instability that resultsin \fIroot()\fR, \fIcos()\fR, \fIsin()\fR, \fIcosh()\fR, \fIsinh()\fR, losing accuracy fast.  Beware.The bug may be in \s-1UNICOS\s0 math libs, in \s-1UNICOS\s0 C compiler, in Math::Complex.Whatever it is, it does not manifest itself anywhere else where Perl runs..SH "AUTHORS".IX Header "AUTHORS"Daniel S. Lewart <\fIlewart!at!uiuc.edu\fR>Jarkko Hietaniemi <\fIjhi!at!iki.fi\fR>Raphael Manfredi <\fIRaphael_Manfredi!at!pobox.com\fR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -