<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>complex number division Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/complex-number-division/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/complex-number-division</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Mon, 15 Feb 2010 18:06:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Complex numbers in .NET with NMath</title>
		<link>https://www.centerspace.net/complex-numbers-in-net-with-nmath</link>
					<comments>https://www.centerspace.net/complex-numbers-in-net-with-nmath#respond</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Mon, 07 Dec 2009 22:20:44 +0000</pubDate>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[complex number c#]]></category>
		<category><![CDATA[complex number division]]></category>
		<category><![CDATA[complex number multiplication]]></category>
		<category><![CDATA[complex numbers .NET]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=661</guid>

					<description><![CDATA[<p>A set of classes for working with complex numbers is not including in the .NET framework. These classes are frequently hand rolled by programmers to fill an immediate need, but this forces the developer into an on-going task developing compatible numeric algorithms with these custom classes. CenterSpace&#8217;s NMath libraries solve this issue by providing a [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-numbers-in-net-with-nmath">Complex numbers in .NET with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A set of classes for working with complex numbers is not including in the .NET framework.  These classes are frequently hand rolled by programmers to fill an immediate need, but this forces the developer into an on-going task developing compatible numeric algorithms with these custom classes.  CenterSpace&#8217;s NMath libraries solve this issue by providing a framework with an extensive set of numeric classes that work natively with complex numbers.</p>
<h3>Complex Number Classes</h3>
<p>The CenterSpace NMath framework contains two classes to represent complex numbers at two different levels of precision.  Additionally, classes are included for supporting vectors and matrices of complex numbers which are integrated into NMath&#8217;s extensive linear algebra classes.</p>
<pre lang="csharp"> 
FloatComplex
DoubleComplex
FloatComplexVector
DoubleComplexVector
FloatComplexMatrix
DoubleComplexMatrix
</pre>
<p>Each class supports a natural set of overloaded operations<span id="more-661"></span> that include testing for equality, and inequality, along with addition, subtraction, multiplication, and division where appropriate.  Here&#8217;s a simple example are some basic uses cases with these classes.</p>
<pre lang="csharp">
DoubleComplex dc1 = new DoubleComplex(1, 1);
DoubleComplex dc2 = new DoubleComplex(2, 2);
 
DoubleComplex dc_add = dc1 - dc2;
DoubleComplex dc_div = dc1 / dc2;
DoubleComplex dc_sin = NMathFunctions.Sin(dc1);
 
DoubleComplexVector dcv1 = new DoubleComplexVector([(1,3.3) (2,3) (3,5)];
DoubleComplexVector dcv2 = new DoubleComplexVector([(1,1) (-2,3) (3,-5.7)];
 
DoubleComplexVector dcv = dcv1 + dcv2;
DoubleComplex dcv_dot = NMathFunctions.Dot(dcv1, dcv2);
</pre>
<h3>Basic Supporting Functions</h3>
<p>The NMath numerical framework contains a static class called <code> NMathFunctions </code> that provides fast implementations of dozens of common functions for all of the basic NMath types, including all of the complex types.  Frequently, new NMath user&#8217;s often wish they had discovered this class sooner than they did.</p>
<p>Below is a brief summary of the functions available in the NMathFunction class that operate on complex types.  These functions span the range from basic operations such as Abs, to a variety to vector helper functions such as the Dot product, to more advanced functions such as computing the determinate of a matrix, or solving a set of linear equations.  Using these functions will help you create correct, efficient, and more compact code.</p>
<ul>
<li> <code> Abs, AbsSum, Sum </code>
<li> <code> Exp, Expm, Log, Pow, Sqrt, Arg </code>
<li> <code> Imag, Real, Conj </code>
<li> <code> ConjDot, OuterProduct, Dot </code>
<li> <code> Transpose, ConjTranspose, TransposeProduct, ConjTransposeProduct </code>
<li> <code> Cos, Cosh, Sin, Sinh, Tan, Tanh </code>
<li> <code> SumOfSquares, Variance </code>
<li> <code> MaxAbsIndex, MinAbsIndex, Median, Mean </code>
<li> <code> ConditionNumber, Determinant, Inverse, Solve </code>
</ul>
<h3> Summary </h3>
<p>The CenterSpace framework for computation on the .NET platform seamless integrates complex types.  While most of our customers are leveraging more sophisticated classes in NMath, a complete set of complex types with a surrounding framework is a key component to getting the job done quickly and accurately.</p>
<p><em> -Paul </em></p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-numbers-in-net-with-nmath">Complex numbers in .NET with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/complex-numbers-in-net-with-nmath/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">661</post-id>	</item>
		<item>
		<title>Complex division by zero</title>
		<link>https://www.centerspace.net/complex-division-by-zero</link>
					<comments>https://www.centerspace.net/complex-division-by-zero#comments</comments>
		
		<dc:creator><![CDATA[Steve Sneller]]></dc:creator>
		<pubDate>Fri, 05 Dec 2008 18:31:31 +0000</pubDate>
				<category><![CDATA[Object-Oriented Numerics]]></category>
		<category><![CDATA[complex number divide by zero]]></category>
		<category><![CDATA[complex number division]]></category>
		<category><![CDATA[complex numbers]]></category>
		<category><![CDATA[computing with complex numbers]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=4</guid>

					<description><![CDATA[<p>An NMath customer submitted the following support question: I&#8217;m working on the primitives (NMathCoreShared.dll) and have found a rather odd &#8216;quirk&#8217; with complex division by zero: DoubleComplex aa = new DoubleComplex(0.0, 0.0); DoubleComplex bb = new DoubleComplex(5.2, -9.1); DoubleComplex cc = new DoubleComplex(); cc = bb/aa; Console.WriteLine(cc); // (NaN,NaN) double g = -5.0 / 0.0; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-division-by-zero">Complex division by zero</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>An NMath customer submitted the following support question:</p>
<blockquote><p>I&#8217;m working on the primitives (NMathCoreShared.dll) and have found a rather odd &#8216;quirk&#8217; with complex division by zero:</p>
<pre>DoubleComplex aa = new DoubleComplex(0.0, 0.0);
DoubleComplex bb = new DoubleComplex(5.2, -9.1);
DoubleComplex cc = new DoubleComplex();

cc = bb/aa;
Console.WriteLine(cc);  // (NaN,NaN)

double g = -5.0 / 0.0;
Console.WriteLine(g);   // -Infinity</pre>
<p>On my machine (Athlon FX), I get the value NaN back when I&#8217;m pretty sure it should be &#8216;Inf&#8217;?</p></blockquote>
<p>The code implementing complex division in the NMath complex number class does not check to see if the divisor is zero. It just applies the formula for complex division in terms of the operands&#8217; real and imaginary parts:</p>
<pre lang="eq.latex">\frac{a + bi}{c + di} = \frac{ac + bd}{c^2 + d^2} + i\frac{bc - ad}{c^2 + d^2}     (1)</pre>
<p>As you can see, when <em>c = d = 0 </em> both the real and imaginary components of the quotient take the form 0/0. Now the IEEE standard says that for real numbers <em>a/0</em>, <em>a</em> not equal to 0, should yield +∞ or -∞ where the sign depends on whether <em>a &gt; 0</em> or <em>a &lt; 0</em> and 0/0 should yield NaN (Not a Number). So a direct application of the formulas for division of complex number, without “special casing” the zero denominator case, will yield a result of (NaN, NaN).</p>
<p>One might be tempted to say “OK, that&#8217;s the end of that. (NaN, NaN) is obviously the correct behavior”. However, this does not set very well with intuition. If I have a fixed complex number <em>w</em> which is divided by another variable complex number <em>z</em>, it seems that as <em>z</em> gets smaller and smaller, the quotient should get bigger and bigger. There is a slight technicality here&#8211;there really is no notion of bigger and smaller for the complex number. That is, there is no ordering of the complex numbers that is consistent with its algebraic structure. In particular there is no notion of negative and positive complex numbers, so the concept of positive and negative infinity are not well defined. Let&#8217;s take a look at some theoretical stuff in the hopes it will help to guide our thinking.</p>
<p>Let&#8217;s start with something more familiar. What does it mean to divide a real number by zero? From a purely algebraic sense if <em>a</em> and <em>b</em> are two real numbers then the number <em>a ÷ b</em> is the solution to the equation <em>b * x = a</em>. When <em>b = 0</em> this equation has no solution and so the quotient is not defined (unless we extend the real numbers to include infinity and define algebraic operations that include infinity, but let&#8217;s not go there now as it isn&#8217;t really germane to our conversation). Where does infinity come in? Well, one can also look at the question from an analysis point of view, where one deals in functions and limits. With this perspective, given a real number <em>a</em> one defines a <em>division</em> function <em>f<sub>a</sub>(x) = a ÷ x</em>. This function is well defined for all <em>x</em> not equal to 0. But, analysis deals also with <em>limits</em>, and one would naturally ask what happens when <em>x</em> gets <em>close</em> to 0. The answer is as <em>x → 0, f<sub>a</sub> → ∞</em>. Formally, this means the following: Given any real number <em>M&gt;0</em>, there exists a corresponding real number <em>δ &gt; 0</em> such that |<em>fa </em>|<em> &gt; M</em> whenever |<em>x</em>|<em> &lt; δ</em>. Now, we can apply this definition to complex numbers since we have a notion of absolute value for complex numbers: if <em>z = a + ib</em> is a complex number, then the modulus of <em>z</em>, |<em>z</em>|, is defined as</p>
<pre lang="eq.latex">|z|=\sqrt{a^2 + b^2}</pre>
<p>That is it&#8217;s the euclidean distance from the point <em>z = (a,b)</em> to the origin in the complex plane. From this it is clear that as a complex number tends to zero, so must its real and imaginary parts. So as the denominator in equation (1) above tends to zero, so do its real and imaginary parts <em>c</em> and <em>d</em>. The fact that <em>c</em> and <em>d</em> are squared in the denominator of the real and imaginary parts of the quotient means that they will tend to zero faster than the their corresponding numerators and hence, using a L&#8217;Hôpital&#8217;s Rule based argument, or a straight <em>δ, M</em> based argument, we can see that both the real and imaginary parts of the quotient tend to infinity as the denominator tends towards zero. Whether it is positive or negative infinity is another question.</p>
<p>But enough theoretical talk. Let&#8217;s look at something concrete. Unlike C#, the standard C++ library includes a complex number class. What do they do when dividing by zero? Here&#8217;s the result I get with Microsoft&#8217;s C++ complex class:</p>
<p>Microsoft Visual C++ 15.0</p>
<pre>(1,1)/(0,0) = (1.#QNAN,1.#QNAN)
(0,0)/(0,0) = (1.#QNAN,1.#QNAN)
1/0 = 1.#INF
0/0 = -1.#IND</pre>
<p>Hmm. They seem to just apply the formulas and get 0/0 for the real and imaginary parts. How about the GNU C++ compiler?</p>
<p>g++ 4.3.2</p>
<pre>(1,1)/(0,0) = (inf,inf)
(0,0)/(0,0) = (nan,nan)
1/0 = inf
0/0 = nan</pre>
<p>Interesting. They return infinite real and imaginary parts. What&#8217;s more interesting is that the two compilers do not agree. And just for fun, here&#8217;s the result with the complex class included in Microsoft&#8217;s F# compiler:</p>
<p>F#</p>
<pre>(1,1)/(0,0) = NaNr+NaNi
(0,0)/(0,0) = NaNr+NaNi
1/0 = Infinity
0/0 = NaN</pre>
<p>No surprise here. At least Microsoft is consistent.</p>
<p>What does the GNU compiler do about positive and negative infinity in its results?</p>
<pre>(1,1)/(0,0) = (inf,inf)
(-1,-1)/(0,0) = (-inf,-inf)
(1,-1)/(0,0) = (inf,-inf)
(-1,1)/(0,0) = (-inf,inf)</pre>
<p>Apparently, they have adopted the convention that the sign of infinity in the real and imaginary parts of the quotient is the same as the signs of the real and imaginary parts of the numerator, respectively.</p>
<p>So, what should NMath do? On the one hand .NET is a Microsofty kind of thing, so maybe we should be consistent with their C++ implementation. On the other hand g++ is a widely distributed compiler and they seem to take the moral high road here. What would you do?</p>
<p>Steve</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-division-by-zero">Complex division by zero</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/complex-division-by-zero/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4</post-id>	</item>
	</channel>
</rss>
