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

Published on 12 May 2024 09:40 PM

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

Source code in the yabasic programming language

rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem 	CADDI/CADDR  addition of complex numbers  Z1 + Z2    with Z1 = a1 + b1 *i   Z2 = a2 + b2*i
rem                CADDI returns imaginary part and CADDR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub caddi( a1 , b1 , a2 , b2)
    return (b1 + b2)
end sub
export sub caddr( a1 , b1 , a2 , b2)
    return (a1 + a2)
end sub

rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CDIVI/CDIVR  division of complex numbers  Z1 / Z2        with Z1 = r + s *i   Z2 = t + u*i
rem                CDIVI returns imaginary part and CDIVR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub cdivi(r,s,t,u)
    return ((s*t- u*r) / (t^2 + u^2))
end sub
export sub cdivr( r , s , t , u)
    return ((r*t- s*u) / (t^2 + u^2))
end sub

rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CMULI/CMULR  multiplication of complex numbers  Z1 * Z2, with Z1 = r + s *i   Z2 = t + u*i
rem                CMULI returns imaginary part and CMULR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub cmuli( r , s , t , u)
    return (r * u + s * t)
end sub
export sub cmulr( r , s , t , u)
    return (r * t - s * u)
end sub

rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem   CSUBI/CSUBR  subtraction of complex numbers Z1 - Z2  with Z1 = a1 + b1 *i   Z2 = a2 + b2*i
rem                CSUBI returns imaginary part and CSUBR the real part
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export sub csubi( a1 , b1 , a2 , b2)
    return (b1 - b2)
end sub
export sub csubr( a1 , b1 , a2 , b2)
    return (a1 - a2)
end sub

if (peek$("library") = "main") then
    print "Example: Z1 + Z2 with Z1 = 3 +2i , Z2 = 1-3i: Z1 + Z2 = 4 -1i"
    print caddr(3,2,1,-2), "/", caddi(3,2,1,-3)   //   4/-1
end if

  

You may also check:How to resolve the algorithm Loops/Break step by step in the Objeck programming language
You may also check:How to resolve the algorithm Rep-string step by step in the Raku programming language
You may also check:How to resolve the algorithm Grayscale image step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Extensible prime generator step by step in the Lingo programming language
You may also check:How to resolve the algorithm System time step by step in the LiveCode programming language