How to resolve the algorithm Arithmetic/Complex step by step in the Nemerle programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic/Complex step by step in the Nemerle programming language
Table of Contents
Problem Statement
A complex number is a number which can be written as:
a + b × i
{\displaystyle a+b\times i}
(sometimes shown as:
b + a × i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typically, complex numbers are represented as a pair of real numbers called the "imaginary part" and "real part", where the imaginary part is the number to be multiplied by
i
{\displaystyle i}
.
By definition, the complex conjugate of
a + b i
{\displaystyle a+bi}
is
a − b i
{\displaystyle a-bi}
Some languages have complex number libraries available. If your language does, show the operations. If your language does not, also show the definition of this type.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Arithmetic/Complex step by step in the Nemerle programming language
Source code in the nemerle programming language
using System;
using System.Console;
using System.Numerics;
using System.Numerics.Complex;
module RCComplex
{
PrettyPrint(this c : Complex) : string
{
mutable sign = '+';
when (c.Imaginary < 0) sign = '-';
$"$(c.Real) $sign $(Math.Abs(c.Imaginary))i"
}
Main() : void
{
def complex1 = Complex(1.0, 1.0);
def complex2 = Complex(3.14159, 1.2);
WriteLine(Add(complex1, complex2).PrettyPrint());
WriteLine(Multiply(complex1, complex2).PrettyPrint());
WriteLine(Negate(complex2).PrettyPrint());
WriteLine(Reciprocal(complex2).PrettyPrint());
WriteLine(Conjugate(complex2).PrettyPrint());
}
}
You may also check:How to resolve the algorithm First-class functions/Use numbers analogously step by step in the Perl programming language
You may also check:How to resolve the algorithm Loops/For step by step in the Ring programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the Frink programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the Liberty BASIC programming language