Dec 152017
Complex Number Calculator Ver. 1.0: evaluates expressions containing real or complex numbers.
File CNC.ZIP from The Programmer’s Corner in
Category Science and Education
Complex Number Calculator Ver. 1.0: evaluates expressions containing real or complex numbers.
File Name File Size Zip Size Zip Type
CNC.DOC 10551 4231 deflated
CNC.EXE 81060 36246 deflated

Download File CNC.ZIP Here

Contents of the CNC.DOC file

Complex Number Calculator version 1.0 by Robert G. Kaires on 3/24/90


If you find this program useful, please register. Registration is only $15.
Your payment is appreciated and necessary for the continued support and
upgrade of this product. If you register you will be put on the mailing list
for future upgrades. Please send your registration fee to: (also questions,

Robert G. Kaires
609 Glover Dr.
Runnemede, NJ 08078


Anyone wishing a disk mailed to them with the latest version of this program
send $5 to the above address requesting a copy of CNC (you do not have to
be a registered user).

Other shareware products from R.G.Kaires

Function Plotter 4.0, (plots functions and data) registration $20, disk $5


The symbol "i" is used to denote the unit imaginary constant and is equal to
the square root of -1. The symbol "z" denotes a complex variable and
z(t) = x(t) + i * y(t). As you can see x(t) is the real part, and y(t) is the
complex part of the complex number, respectively. The symbol "t" is used to
denote a real parameter and will be useful in the discussion of numerical


Complex Number Calculator (CNC) evaluates expressions containing real or
complex numbers. Examples of valid expressions are:

1.23e10/.45e-27 ............. numbers can be entered in exponential format
1 + sin(pi/3) ............... same as 1 + sin(180/3) if "degrees" are set
exp( 2 - (1/2) * exp(3) ) ... functions can, of course, be nested
.5 * ln( (1+z)/(1-z) ) ...... you will be prompted for z
(i+1)/(i-1) ................. "i" is the unit imaginary constant
(z+1)/(z-1) ................. enter any real or complex no. at the prompt
(1+i)^(2+i) ................. exponents can be complex
int( 1 / (1+t^2), 4,0,1) .... numerically integrate f(t) = 1 / ( 1+t^2 )
from 0 to 1 using an approx order of 4
int(cos(t)+j*sin(t),4,0,pi).. numerically integrate cos(t) + i * sin(t)
M_m(2.0) .................... convert 2 miles to meters
kW_hp(4.5) .................. convert 4.5 kilo-Watts to horse power

See the end of this document for a full list of functions, constants, and
conversions available in CNC. Be aware that CNC is case sensitive.

CNC "remembers" previously entered expressions (up to 20), they can be
accessed by using the up and down arrow keys. Expressions can be one full line
in length. When the line is full, CNC will not allow any addition characters
to be inserted until some are deleted. All calculations are performed in
double precision with about 15 significant digits of precision. The number of
displayed digits (default is 6) can be changed using the "dd" command.
When responding to prompts in CNC, the default response is given in square
brackets. Simply hit "Enter" (CR) to respond with the default.

At the top of the screen is a message line which lists some information on
valid editing keys and other commands. At the bottom of the screen is the
status line.


The valid operators are + - * / ^. The operator ^ (exponentiation) has the
highest precedence, followed by the operators * and / which have equal
precedence, followed by + and - which have equal precedence. Operators with
equal precedence are evaluated left to right. Functions (and conversions) have
higher precedence than operators. Therefore sin(pi/6)^2 is evaluated as
(sin(pi/6) )^2 since sin(pi/6) is evaluated before the exponentiation is
performed. Consider the following two expressions:

sin(5) ^ sqrt(2) and
sin(5) ^ 2^.5

The first yields: (-.958924) ^ 1.41421 ( = -0.250921 - i * 0.90839 )
The second gives: ( (-.958924) ^ 2 ) ^ .5 ( = .958924 )

In the first expression sqrt (which IS a function) and sin are evaluated
first, in the second expression sin is evaluated, followed by the operators ^
and ^, which are evaluated left to right. Enough said. As when using any
calculator, when in doubt, use parenthesis. One final note: do not use
operators side by side with no intervening numbers or parenthesis such as
2*-2, you will be surprised at what you get. Instead use 2*(-2)


All calculations are done in double precision and have about 15 digits of
accuracy. Problems that can occur from this finite accuracy are best
illustrated by the following example session:

>sin(z)^2 + cos(z)^2 ...... (user enters expres at > prompt)
z=?>1 ..................... (user enters expres at z=?> prompt)
1 ......................... (result)
z=?>i ..................... (of course you may use complex
1 numbers as well)
z=?>100*i ................. (WHAT HAPPENED HERE!)

This last result is not a bug in CNC! It results because of the finite
precision of this (and any) calculator. The functions sin(z)^2 and cos(z)^2
with purely imaginary arguments are -sinh(y)^2 and cosh(y)^2, respectively.
Now the answer is obvious, for large y we are subtracting two very large
numbers. The answer, of course, becomes very inaccurate.

Floating point numbers can range from 1e-308 to 1e308.


sqrt() square root function
exp() inverse natural log function
real() real part of a complex number
imag() imaginary part of a complex number
mag() magnitude of a complex number
ang() angle of a complex number
ln() natural log
log() log base 10

sin(), cos(), tan() trigonometric functions
asin(), acos(), atan() inverse trigonometric functions
sinh(), cosh(), tanh() hyperbolic functions
asinh(), acosh(), atanh() inverse hyperbolic functions


int( f(t),N,l,u ) numerical integration of a function of a single real
variable (t) using Gaussian Quadrature
- f(t) can evaluate to a complex number
- N is the order of the approximation ( 2,4,8,10,12,16,32 )
- l,u lower and upper integration limits (can be a function of T)

The integration method used is Gaussian Quadrature. The numerical procedure
does not put integration points at the integration limits. Therefore the
integration limit points can be singular. Of course, one must be concerned
about convergence. Some singularities are integrable, some are not. Consider
the following two sessions. In both the function is singular at t=0, but the
first function is integrable and the second is not.

>int(ln(t),8,0,1) ......... The ln function is integrable
-0.991239 from 0 to 1

>int(1/t,8,0,1) ............The 1/t function in not integrable
5.43571 from 0 to 1

We notice that the first integral converges but that the second does not.


Integrating a function of a complex variable in the complex plane is possible
with some work. The function must be parameterized as a function of a real
variable as follows: f(z) = f(x+i*y) = f(x(t) + i*y(t)), where t is real.
We then note that dz = ( x'(t) + i*y'(t) ) dt, where ' denote differentiation
with respect to t. Therefore we have

f(z) dz = f( x(t) + i*y(t) ) * ( x'(t) + i*y'(t) ) dt.

Example: We want to integrate 1/z along the unit circle centered at the
origin. The complex variable z can be described by z = cos(t) + i * sin(t).
Therefore we have

1/z dz = ( 1 / (cos(t) + i * sin(t) ) * ( -sin(t) + i*cos(t) ) dt.

The following is from an actual session:

>int( ( 1 / (cos(t) + i * sin(t) ) ) * ( -sin(t) + i*cos(t) ),4,0,2*pi)
3.73223e-18 + i * 6.28319

With the exception of some small round-off error, we obtain approximately
2*pi*i as expected.


mathematical constants: pi (3.14159...) gamma (.5772...)

physical constants:

c0 speed of light in vacuum (m/s) N Avagadro's constant (1/mole)
h Planck's constant (J-s) R Universal gas constant (J/K-mole)
qe electron charge (C) k Boltzmann's constant (J/K)
eps permittivity constant (F/m) Me electron mass (kg)
mu permeability constant (H/m) Mn neutron mass (kg)
G Grav constant (N-m^2/kg^2) Mp proton mass (kg)
g standard gravity (m/s^2)

CONVERSION FUNCTIONS (must use real arguments)

M_m(), m_M() miles to meters, meters to miles
M_yd(), yd_M() miles to yards, yards to miles
M_ft(), ft_M() miles to feet, ....
m_in(), in_ft() meters to inches, ....
cm_in(), in_cm() cm to inches, ....
F_C(), C_F() degrees Fahrenheit to degrees Celsius, ....
K_C(), C_K() degrees Kelvin to degrees Celsius, ....
K_F(), F_K() degrees Kelvin to degrees Fahrenheit, ....
lb_kg(), kg_lb() pounds to kilograms, .... (under standard gravity)
lb_N(), N_lb() pounds to Newtons, ....
Btu_J(), J_Btu() Btu's to Joules, ....
kWh_J(), J_kWh() kilo-Watt hours to Joules, ....
kW_hp(), hp_kW() kilo-Watt hours to horse-power, ....


You can write data to a file only from the z=?> (or T=?>) prompt. Enter a
function of z, at the z=?> prompt press f , you will be prompted for a
file name and whether you want to write the domain and range or just the
range. If you request the domain and range to be written, the real part of z
will be written to the first column, the imaginary part of z to the second
column, the real part of f(z) to the third column and finally the imaginary
part of f(z) to the fourth column. If you request the range (only) to be
written, the real and imaginary parts of f(z) will be written to the first and
second columns, respectively. The file will be close when you press "q" from
the z=?> (or T=?>) prompt. You can plot your data with any standard plotting
package. A shareware plotting package is available from this author if you are
in need (see beginning of this document).

 December 15, 2017  Add comments

Leave a Reply