How to resolve the algorithm Arithmetic/Complex step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Arithmetic/Complex step by step in the F# 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 F# programming language

Source code in the fsharp programming language

> open Microsoft.FSharp.Math;;

> let a = complex 1.0 1.0;;
val a : complex = 1r+1i

> let b = complex 3.14159 1.25;;
val b : complex = 3.14159r+1.25i

> a + b;;
val it : Complex = 4.14159r+2.25i {Conjugate = 4.14159r-2.25i;
                                   ImaginaryPart = 2.25;
                                   Magnitude = 4.713307515;
                                   Phase = 0.497661247;
                                   RealPart = 4.14159;
                                   i = 2.25;
                                   r = 4.14159;}

> a * b;;
val it : Complex = 1.89159r+4.39159i {Conjugate = 1.89159r-4.39159i;
                                      ImaginaryPart = 4.39159;
                                      Magnitude = 4.781649868;
                                      Phase = 1.164082262;
                                      RealPart = 1.89159;
                                      i = 4.39159;
                                      r = 1.89159;}

> a / b;;
val it : Complex =
  0.384145932435901r+0.165463215905043i
    {Conjugate = 0.384145932435901r-0.165463215905043i;
     ImaginaryPart = 0.1654632159;
     Magnitude = 0.418265673;
     Phase = 0.4067140652;
     RealPart = 0.3841459324;
     i = 0.1654632159;
     r = 0.3841459324;}

> -a;;
val it : complex = -1r-1i {Conjugate = -1r+1i;
                           ImaginaryPart = -1.0;
                           Magnitude = 1.414213562;
                           Phase = -2.35619449;
                           RealPart = -1.0;
                           i = -1.0;
                           r = -1.0;}


  

You may also check:How to resolve the algorithm Identity matrix step by step in the Octave programming language
You may also check:How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Zumkeller numbers step by step in the Swift programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the Vedit macro language programming language