📄 complex.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Math::Complex - complex numbers and associated mathematical functions</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>Math::Complex - complex numbers and associated mathematical functions</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#operations">OPERATIONS</a></li>
<li><a href="#creation">CREATION</a></li>
<li><a href="#displaying">DISPLAYING</a></li>
<ul>
<li><a href="#changed_in_perl_5_6">CHANGED IN PERL 5.6</a></li>
</ul>
<li><a href="#usage">USAGE</a></li>
<li><a href="#errors_due_to_division_by_zero_or_logarithm_of_zero">ERRORS DUE TO DIVISION BY ZERO OR LOGARITHM OF ZERO</a></li>
<li><a href="#errors_due_to_indigestible_arguments">ERRORS DUE TO INDIGESTIBLE ARGUMENTS</a></li>
<li><a href="#bugs">BUGS</a></li>
<li><a href="#authors">AUTHORS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<hr />
<h1><a name="name">NAME</a></h1>
<p>Math::Complex - complex numbers and associated mathematical functions</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">Math::Complex</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$z</span> <span class="operator">=</span> <span class="variable">Math::Complex</span><span class="operator">-></span><span class="variable">make</span><span class="operator">(</span><span class="number">5</span><span class="operator">,</span> <span class="number">6</span><span class="operator">);</span>
<span class="variable">$t</span> <span class="operator">=</span> <span class="number">4</span> <span class="operator">-</span> <span class="number">3</span><span class="variable">*i</span> <span class="operator">+</span> <span class="variable">$z</span><span class="operator">;</span>
<span class="variable">$j</span> <span class="operator">=</span> <span class="variable">cplxe</span><span class="operator">(</span><span class="number">1</span><span class="operator">,</span> <span class="number">2</span><span class="variable">*pi</span><span class="operator">/</span><span class="number">3</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This package lets you create and manipulate complex numbers. By default,
<em>Perl</em> limits itself to real numbers, but an extra <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> statement brings
full complex support, along with a full set of mathematical functions
typically associated with and/or extended to complex numbers.</p>
<p>If you wonder what complex numbers are, they were invented to be able to solve
the following equation:</p>
<pre>
x*x = -1</pre>
<p>and by definition, the solution is noted <em>i</em> (engineers use <em>j</em> instead since
<em>i</em> usually denotes an intensity, but the name does not matter). The number
<em>i</em> is a pure <em>imaginary</em> number.</p>
<p>The arithmetics with pure imaginary numbers works just like you would expect
it with real numbers... you just have to remember that</p>
<pre>
i*i = -1</pre>
<p>so you have:</p>
<pre>
5i + 7i = i * (5 + 7) = 12i
4i - 3i = i * (4 - 3) = i
4i * 2i = -8
6i / 2i = 3
1 / i = -i</pre>
<p>Complex numbers are numbers that have both a real part and an imaginary
part, and are usually noted:</p>
<pre>
a + bi</pre>
<p>where <code>a</code> is the <em>real</em> part and <a href="../../lib/Pod/perlguts.html#item_b"><code>b</code></a> is the <em>imaginary</em> part. The
arithmetic with complex numbers is straightforward. You have to
keep track of the real and the imaginary parts, but otherwise the
rules used for real numbers just apply:</p>
<pre>
(4 + 3i) + (5 - 2i) = (4 + 5) + i(3 - 2) = 9 + i
(2 + i) * (4 - i) = 2*4 + 4i -2i -i*i = 8 + 2i + 1 = 9 + 2i</pre>
<p>A graphical representation of complex numbers is possible in a plane
(also called the <em>complex plane</em>, but it's really a 2D plane).
The number</p>
<pre>
z = a + bi</pre>
<p>is the point whose coordinates are (a, b). Actually, it would
be the vector originating from (0, 0) to (a, b). It follows that the addition
of two complex numbers is a vectorial addition.</p>
<p>Since there is a bijection between a point in the 2D plane and a complex
number (i.e. the mapping is unique and reciprocal), a complex number
can also be uniquely identified with polar coordinates:</p>
<pre>
[rho, theta]</pre>
<p>where <code>rho</code> is the distance to the origin, and <code>theta</code> the angle between
the vector and the <em>x</em> axis. There is a notation for this using the
exponential form, which is:</p>
<pre>
rho * exp(i * theta)</pre>
<p>where <em>i</em> is the famous imaginary number introduced above. Conversion
between this form and the cartesian form <code>a + bi</code> is immediate:</p>
<pre>
a = rho * cos(theta)
b = rho * sin(theta)</pre>
<p>which is also expressed by this formula:</p>
<pre>
z = rho * exp(i * theta) = rho * (cos theta + i * sin theta)</pre>
<p>In other words, it's the projection of the vector onto the <em>x</em> and <em>y</em>
axes. Mathematicians call <em>rho</em> the <em>norm</em> or <em>modulus</em> and <em>theta</em>
the <em>argument</em> of the complex number. The <em>norm</em> of <code>z</code> will be
noted <a href="../../lib/Pod/perlfunc.html#item_abs"><code>abs(z)</code></a>.</p>
<p>The polar notation (also known as the trigonometric
representation) is much more handy for performing multiplications and
divisions of complex numbers, whilst the cartesian notation is better
suited for additions and subtractions. Real numbers are on the <em>x</em>
axis, and therefore <em>theta</em> is zero or <em>pi</em>.</p>
<p>All the common operations that can be performed on a real number have
been defined to work on complex numbers as well, and are merely
<em>extensions</em> of the operations defined on real numbers. This means
they keep their natural meaning when there is no imaginary part, provided
the number is within their definition set.</p>
<p>For instance, the <a href="../../lib/Pod/perlfunc.html#item_sqrt"><code>sqrt</code></a> routine which computes the square root of
its argument is only defined for non-negative real numbers and yields a
non-negative real number (it is an application from <strong>R+</strong> to <strong>R+</strong>).
If we allow it to return a complex number, then it can be extended to
negative real numbers to become an application from <strong>R</strong> to <strong>C</strong> (the
set of complex numbers):</p>
<pre>
sqrt(x) = x >= 0 ? sqrt(x) : sqrt(-x)*i</pre>
<p>It can also be extended to be an application from <strong>C</strong> to <strong>C</strong>,
whilst its restriction to <strong>R</strong> behaves as defined above by using
the following definition:</p>
<pre>
sqrt(z = [r,t]) = sqrt(r) * exp(i * t/2)</pre>
<p>Indeed, a negative real number can be noted <code>[x,pi]</code> (the modulus
<em>x</em> is always non-negative, so <code>[x,pi]</code> is really <a href="../../lib/Pod/perlrun.html#item__2dx"><code>-x</code></a>, a negative
number) and the above definition states that</p>
<pre>
sqrt([x,pi]) = sqrt(x) * exp(i*pi/2) = [sqrt(x),pi/2] = sqrt(x)*i</pre>
<p>which is exactly what we had defined for negative real numbers above.
The <a href="../../lib/Pod/perlfunc.html#item_sqrt"><code>sqrt</code></a> returns only one of the solutions: if you want the both,
use the <code>root</code> function.</p>
<p>All the common mathematical functions defined on real numbers that
are extended to complex numbers share that same property of working
<em>as usual</em> when the imaginary part is zero (otherwise, it would not
be called an extension, would it?).</p>
<p>A <em>new</em> operation possible on a complex number that is
the identity for real numbers is called the <em>conjugate</em>, and is noted
with a horizontal bar above the number, or <code>~z</code> here.</p>
<pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -