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

Published on 12 May 2024 09:40 PM
#Ol

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

Source code in the ol programming language

(define A 0+1i) ; manually entered numbers
(define B 1+0i)

(print (+ A B))
; <== 1+i

(print (- A B))
; <== -1+i

(print (* A B))
; <== 0+i

(print (/ A B))
; <== 0+i


(define C (complex 2/7 -3)) ; functional way

(print "real part of " C " is " (car C))
; <== real part of 2/7-3i is 2/7

(print "imaginary part of " C " is " (cdr C))
; <== imaginary part of 2/7-3i is -3


  

You may also check:How to resolve the algorithm Random number generator (included) step by step in the PHP programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the E programming language
You may also check:How to resolve the algorithm Parsing/Shunting-yard algorithm step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Singly-linked list/Element insertion step by step in the Nim programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the Lambdatalk programming language