Table of Contents

Mathematical Basics

This section explains the mathematical routines used in CGRAPH and the principles underlying them. It also contains a brief introduction to the theory of complex numbers and explains the complex functions that form the basis of all calculations in CGRAPH.

Knowledge of these fundamentals is not necessary for using CGRAPH, but it does answer more advanced questions.

Functions

A function is generally understood to be a mapping that assigns exactly one function value to each vector in the domain. Real-valued functions of one or two variables are used in real-valued graphics. These can be written as

(x,y)^T doubleright ~ f(x,y)

and thus initially represent mappings from ℝ2 to ℝ1. If the function depends on only one variable, only a mapping from ℝ2 to ℝ1 is performed.

Such functions are usually represented by assigning the variable to one axis and the function value to the second axis of ℝ2. For functions with two variables, the variables are assigned a plane and the function value is assigned the third coordinate, so that the following can be written:

y = f(x)

or

z = f(x,y)

CGRAPH also uses this method to represent functions. The 2D Graphics / Functions menu allows you to display f(x), the first and second derivatives, and the integral.

Display of the function

CGRAPH calculates the function values by calculating support values between the start and end values of the variable x. The number of support values can be specified in the Settings tab of the 2D Graphics register.

Derivatives

In CGRAPH, the derivatives are calculated graphically. Since the number of calculated support points is included in the result, a sufficiently high number of support values is a basic requirement for a good match with the actual derivative.

CGRAPH uses the following approximation formula to calculate the first derivative:

f prime(x) ~ approx ~ {f(x_i) ~ - ~ f(x_{i-1})}/{x_i ~ - ~ x_{i-1}}

where the values i and i-1 indicate the respective support values used.

The following approximation formula is used for the second derivative:

f prime prime(x) ~ approx ~ {{{f(x_i) ~ - ~ f(x_{i-1})}/{x_i ~ - ~ x_{i-1}}} ~ - ~ {{f(x_{i-1}) ~ - ~ f(x_{i-2})}}/{x_{i-1} ~ - ~ x_{i-2}}}/ {x_i ~ - ~ x_{i-1}}

In addition to the support value f(xi-1), the support value f(xi-2) is also required here. The first derivative of the initial and final values cannot be determined, nor can their second derivative, as the corresponding curves outside the value range are not considered. This also clearly shows the significant influence that the number of support values has on the exact representation of the derivatives. The support point spacing xi - xi-1 is directly included in the calculation.

Integral

CGRAPH uses a modified bar rule for the (graphical) representation of the integral. The definite integral over the interval limits is calculated using:

I ~ = ~ int{x_1}{x_2}{f(x) ~ dx}

where the integral is approximated by

I ~ approx ~ sum{i=1}{N}{{ ~ f(x_i) + f(x_{i-1})}/{2} (x_1 - x_{i-1})}.

Here, too, the number of sampling points is of crucial importance.

General curves and surfaces

The difference between functions and plane curves lies in the condition that, in the former, only one function value may be assigned to each vector of the preimage space, whereas in the latter this is not the case. In the two-dimensional case, general curves therefore involve a mapping from ℝ1 to ℝ2. In the three-dimensional case, a mapping from ℝ1 to ℝ3 takes place. The corresponding mapping functions are

x ~ = ~ f_1(t)

y ~ = ~ f_2(t)

and, in the three-dimensional case, additionally

z ~ = ~ f_3(t)

Within CGRAPH, these mappings can be found under the menu items 2D Graphics/Plane Curves and 3D Graphics/Spatial Curves. This allows curves to be displayed whose parameter representation is known. Implicit definitions of a curve must be converted into explicit parameter representations.

This does not represent the dependence of the three coordinates on the parameter, but rather the dependence of the three parameter functions on each other.

If surfaces are to be displayed instead of curves in ℝ3, the use of one parameter is not sufficient. The required mapping then leads from ℝ2 to ℝ3, whereby in CGRAPH the dependence of the three mapping functions

x ~ = ~ f_1(t, s)

y ~ = ~ f_2(t, s)

z ~ = ~ f_3(t, s)

. Here, s denotes the second parameter. The mapping procedure is similar to that for spatial curves. Here, support values are calculated with

x(s) ~ = ~ f_1(t_i, s)

y(s) ~ = ~ f_2(t_i, s)

z(s) ~ = ~ f_3(t_i, s)

where ti represents the fixed parameter and s represents the current parameter. This means that not the entire surface is drawn, but only spatial curves on the surface that illustrate its position in space. Combining four such support values into a polygon chain allows CGRAPH to create a surface model in which only the visible edges of the surface are displayed.

For surfaces in space, the parameter representation of the surface must also be known if it is to be displayed in CGRAPH via the menu 3D Graphics/Surfaces in Space.

Surfaces are areas on closed bodies, e.g. spheres. Since these cannot be distinguished mathematically from extended surfaces, they can also be represented in this way. If the surface of a solid is entered in parameter form, CGRAPH therefore displays the structure of the solid.

Interpolation

Using the More Graphics/Interpolation menu, CGRAPH can perform interpolations of curves based on lists of value pairs.

Linear interpolation

For each two pairs (x0,y0) and (xi, yi), the corresponding values for the intercept and slope of the function y = mx + b can be calculated using linear interpolation.

m_i ~ = ~ {y_i ~ - ~ y_0}/{x_i ~ - ~ x_0}

b_i ~ = ~ {y_0 ⋅ x_i ~ - ~ y_i ⋅ x_0}/{x_i ~ - ~ x_0}

The specified values for m and b are defined as arithmetic means of the individual values calculated in this way:

m ~ := ~ {1}/{N-1} sum{i=1}{N-1}{m_i}

b ~ := ~ {1}/{N-1} sum{i=1}{N-1}{b_i}

The sum is calculated over N-1 values because two pairs of values are always required.

Quadratic interpolation

In order to specify the parameters of the quadratic equation

y ~ = ~ a x^2 + bx + c

, two pairs of reference values (x0,y0) and (x1,y1) are required. These two pairs of values are assumed to lie on the curve. Together with the remaining pairs of values, they form the linear equation system

y_0 ~ = ~ a {x_0}^ {2} + bx_0 + c

y_1 ~ = ~ a {x_1}^{2} + bx_1 + c

y_i ~ = ~ a {x_i}^{2} + bx_i + c

which is solved in CGRAPH for all points below each other by determinant calculation. As with linear interpolation, the specified values are formed by calculating the arithmetic mean of the parameters with

p ~ := ~ {1}/{N-2} sum{i=1}{N-2}{p_i}

where p represents the parameters a, b and c. Since two reference values are required, the solution can only comprise N-2 value pairs; therefore, at least three input values are also required. The reference value pairs can be selected in CGRAPH from all the input value pairs; when the function is called for the first time, the first and last pairs of the input list are used.

Exponential interpolation

Here, the function

y ~ = ~ c ⋅ e^{a ⋅ x}

is assumed as the basis for the value pairs. The exact calculation of the parameters a and c leads to a transcendental equation that can only be solved using numerical approximation methods. The method used here provides comparable graphical values with considerable simplification of the calculation.

To do this, CGRAPH takes into account that the first derivative of the exponential function is again the exponential function:

y prime ~ = ~ a ⋅ c ⋅ e^{a ⋅ x}

If we calculate the slope from the given pairs of values, we arrive at the following simple equation:

y - y prime ~ = ~ c ⋅ (1 - a)

From two such pairs of values, yi and yi', values for a and c can then be obtained, the resulting value of which is again calculated by forming the arithmetic mean.

Exponential interpolation with limit value

Here, the function

y ~ = ~ c ⋅ (1 - e^{a ⋅ x})

is taken as the basis for the value pairs. The exact calculation of the parameters a and c also leads to a transcendental equation here, which can only be solved using numerical approximation methods. The method used here provides comparable graphical values with considerable simplification of the calculations.

To do this, CGRAPH takes into account that the first derivative of the exponential function is again the exponential function:

y prime ~ = ~ -a ⋅ c ⋅ e^{a ⋅ x}

If we calculate the slope from the given value pairs, we arrive at the following simple equation:

y - y prime ~ = ~ c ⋅ (1 + a)

From two such pairs of values yi and yi', values for a and c can then be obtained, the resulting value of which is again calculated by forming the arithmetic mean.

Chain line (cosine hyperbolic)

Here, the function

y ~ = ~ c ⋅ cosh(a ⋅ x)

is assumed as the basis for the value pairs. The exact calculation of the parameters a and c also leads to a transcendental equation here, which can only be solved using numerical approximation methods. The method used here provides comparable graphical values with considerable simplification of the calculations.

To this end, CGRAPH takes into account that the second derivative of the cosine hyperbolic is again a cosine hyperbolic:

y prime prime ~ = ~ c ⋅ a^2 ⋅ cosh(a ⋅ x)

If we calculate the second derivative from given triples of values, we arrive at the following simple equation:

y - y prime prime ~ = ~ c ⋅ (1 - a^2)

From each pair of such values yi and yi' ' we can then obtain values for a and c, whose resulting value is again calculated by forming the arithmetic mean.

Fourier series

This type of interpolation is suitable for periodic processes. The individual coefficients of a Fourier series are determined as follows:

y ~ = ~ sum{}{}{c_k ⋅ sin(a_k ⋅ x)}

Akima interpolation

If the aim of interpolation is not to determine the underlying mathematical function but to represent the smoothest possible curve, the algorithm used for interpolation must meet certain requirements.

-There must be no overcurvature at discontinuities.

-Value pairs may only influence a limited interval around the value.

Two methods of numerical mathematics are suitable for this purpose: spline interpolation and Akima interpolation, named after its developer Hiroshi Akima. Both use cubic polynomials of the form

P_i(x) ~ = ~ a_i ~ + ~ b_i ⋅ (x-x_i) ~ + ~ c_i ⋅ (x-x_i)^2 ~ + ~ d_i ⋅ (x-x_i)^3

. Akima interpolation assumes continuity of the first derivative, while spline interpolation additionally requires continuity of the second derivative. However, this leads to slight overshoots, which is why Akima interpolation was used in CGRAPH. In Akima interpolation, two additional points are first extrapolated to the left and right of the actual observation interval, which are required for the internal calculation. They are not shown in the drawing.

The abscissa values of these extrapolated pairs are

x_{-1} ~ = ~ x_0 ~ + ~ x_1 ~ - ~ x_2

x_{-2} ~ = ~ x_{-1} ~ + ~ x_0 ~ - ~ x_1

x_ {N+1} ~ = ~ x_N ~ + ~ x_{N-1} ~ - ~ x_{N-2}

x_{N+2} ~ = ~ x_{N+1} ~ + ~ x_N ~ - ~ x_{N-1}

The slope between two pairs of values is also required for interpolation. This is calculated from

m_i ~ = ~ {y_i ~ - ~ y_{i-1}}/{x_i ~ - ~ x_{i-1}}

The slope can only be calculated from the second to the penultimate pair of values, as the ordinate values of the extrapolated pairs outside the interval are not yet available. They are calculated from the pairs of values known at this point and the calculated slopes to

y_{-1} ~ = ~ (x_0 ~ - ~ x_{-1}) (m_1 ~ - ~ 2m_0) ~ + ~ y_0

m_{-1} ~ = ~ {y_{0} ~ - ~ y_{-1}}/{x_{0} ~ - ~ x_{-1}}

y_{-2} ~ = ~ (x_{-1} ~ - ~ x_{-2}) (m₀ ~ - ~ 2m⁻¹) ~ + ~ y⁻¹

m⁻² ~ = ~ {y⁻¹ ~ - ~ y⁻²}/{x⁻¹ ~ - ~ x⁻²}

y_(N+1) ~ = ~ (x_(N+1) ~ - ~ x_N) (2m_(N-1) ~ - ~ 2m_(N-2)) ~ + ~ y_N

m_{N} ~ = ~ {y_{N+1} ~ - ~ y_{N}}/{x_{N+1} ~ - ~ x_{N}}

y_{N+2} ~ = ~ (x_{N+2} ~ - ~ x_{N+1}) (2m_{N} ~ - ~ 2m_{N-1}) ~ + ~ y_{N+1}

m_{N+1} ~ = ~ {y_{N+2} ~ - ~ y_{N+1}}/{x_{N+2} ~ - ~ x_{N+1}}

After extrapolating these additional values, the individual coefficients of the cubic polynomial can be calculated. To do this, the slope formula used in Akima interpolation is also required. This is

t_{i} ~ = ~ {delim{|}{m_{i+1} ~ - ~ m_{i}}{|} ⋅ m_{i-1} ~ + ~ delim{|}{m_{i-1} ~ - ~ m_{i-2}}{|} ⋅ m_{i}}/ {delim{|}{m_{i+1} ~ - ~ m_{i}}{|} ~ + ~ delim{|}{m_{i-1} ~ - ~ m_{i-2}}{|}}

where m describes the respective slope that was calculated previously. This results in the coefficients

a_{i} ~ = ~ y_{i}

b_{i} ~ = ~ t_{i}

c_{i} ~ = ~ {3 ⋅ m_{i} ~ - ~ 2 ⋅ t_{i} ~ - ~ t_{i+1}}/{x_{i+1} ~ - ~ x_ {i}}

d_{i} ~ = ~ {t_{i} ~ + ~ t_{i+1} ~ - ~ 2 ⋅ m_{i}}/{(x_{i+1} ~ - ~ x_{i})^2}

These coefficients can now be used to calculate the cubic polynomials that are used for interpolation.

Complex numbers

CGRAPH enables the creation of images of complex functions in the complex plane. This is described as

bbC ~ := ~ bbR ~ * ~ bbR

and thus represents a two-dimensional vector space. The basic mathematical axioms apply in this vector space. In addition to the real axis, which is included as a special case in the complex plane, the imaginary unit i (or j) is introduced, which has the following definition:

i ~ := ~ sqrt{-1}

Numbers are composed of a real part and an imaginary part, whereby the imaginary part is characterised by the addition of the imaginary unit.

z ~ := ~ x ~ + ~ iy

In addition, representation in polar coordinates is possible.

z ~ := ~ delim{|}{z}{|} ~ e^{i varphi}

with

delim{|}{z}{|} ~ = sqrt{x^2 ~ + ~ y^2}

varphi ~ = ~arg(z)

where the angle arg(z) is defined according to the geometric view as

arg(z) ~ = ~ arctan(y/x) ~ + ~ pi ⋅ sgn(y) {1 ~ - ~ sgn(x)}/ {2}

The ambiguity of the arctangent with regard to the quadrants of the complex plane under consideration is described by the second part of the function. CGRAPH uses the Cartesian number format with real and imaginary parts for output.

In contrast to the real vector space ℝ2, all basic arithmetic operations are defined in complex space. With z=x+iy, the following table results:

Arithmetic operation Arithmetic rule
Additionz_1 ~ + ~ z_2 ~ = ~ x_1 ~ + ~x_2 ~ + ~ i(y_1 ~ + ~ y_2)
Subtractionz_1 ~ - ~ z_2 ~ = ~ x_1 ~ - ~x₂ ~ + ~ i(y₁ ~ - ~ y₂)
Multiplicationz₁ ~ ⋅ ~ z₂ ~ = ~ x₁x₂ ~ - ~y₁y₂ ~ + ~ i (x₁y₂ ~ + ~ x₂y₁)
Division{z₁}/{z₂} ~ = ~ {x₁x₂ ~ + ~y₁y₂ ~ + ~ i(x₂y₁ ~ - ~ x₁y₂)}/{{x₂}^2~ + ~ {y_2}^2}

Mappings in the complex plane

Just as in real space, a mapping can be defined for the complex plane. The knowledge gained from real mappings of ℝ2 can be used here.

A mapping is explained by

Z ~ right ~ W,

a number in the complex Z-plane is mapped to another in the complex W-plane. The mapping rule is the complex function

z ~ right ~ f(z)

with

w ~ := ~ f(z)

where z and w are numbers within the complex Z and W planes, respectively.

The function defined in this way can have properties known from real space, such as the ambiguity of the mapping and reversibility.

Functions defined in CGRAPH

The most important elementary functions are already predefined in CGRAPH. Since ambiguities can occur in some cases, the definitions used in the programme are given here.

If ambiguous results are possible, CGRAPH uses the principal value of the function used. The definition of the corresponding real functions is assumed here. The programme uses the following functions to calculate the corresponding complex values:

Function Description
exp(x)real exponential function to the base e
ln(x)real logarithm to the base e
sin(x)real sine function
cos(x)real cosine function
arctan(x)real arctangent function
x^2real square function
sqrt{x}real square root function
delim{|}{x}{|}real absolute value function

Internally, these are used to calculate the two real hyperbolic functions sinh(x) and cosh(x) with

sinh(x) ~ = ~ {e^x ~ - ~ e^{-x}}/{2}

and

cosh(x) ~ = ~ {e^x ~ + ~ e^{-x}}/{2}

This results in the specified complex functions with

exp(z) ~ = ~ e^x ⋅ (cos(y) ~ + ~ i ⋅ sin(y))

log(z) ~ = ~ 1/2 ln(x^2 + y^2) ~ + ~ i ⋅ arctan(x/y) ~ + ~ 2k pi

The ambiguity of the logarithm function is described by the constant k. It is assumed to be zero within CGRAPH, so the summand k must be added if necessary.

Angle and hyperbolic functions

sin(z) ~ = ~ sin(x) cosh(y) ~ + ~ i ⋅ cos(x) sinh (y)

cos(z) ~ = ~ cos(x) cosh(y) ~ - ~ i ⋅ sin(x) sinh(y)

sinh(z) ~ = ~ sinh(x) cos(y) ~ + ~ i ⋅ cosh(x) sin(y)

cosh(z) ~ = ~ cosh(x) cos(y) ~ + ~ i ⋅ sinh(x) sin(y)

tan(z) ~ = ~ {sin(2x) ~ + ~ i ⋅ sinh(2y)}/{cos(2x) ~ + ~ cosh(2y)}

tanh(z) ~ = ~ {sinh(2x) ~ + ~ i ⋅ sin(2y)}/{cosh(2x) ~ + ~ cos(2y)}

Inverse functions

The inverse functions can be calculated using the complex logarithm log(z).

arcsin(z) ~ = ~ - i ⋅ ln(i ⋅ z ~ + ~ sqrt{1-z^2})

arccos(z) ~ = ~ - i ⋅ ln( z ~ + ~ i ⋅ sqrt{1-z^2})

arctan(z) ~ = ~ - i/2 ⋅ ln({1 ~ + ~ i ⋅ z}/ {1 ~ - ~ i ⋅ z})

arcsinh(z) ~ = ~ ln(z ~ + ~ sqrt{z^2+1})

arccosh(z) ~ = ~ ln( z ~ + ~ sqrt{z^2-1})

arctanh(z) ~ = ~ 1/2 ⋅ ln({1 ~ + ~ z}/{1 ~ - ~ z})

Functions for processing complex numbers and special functions

CGRAPH defines several functions that can be used to split complex numbers or to process and convert complex and real numbers.

abs(z) ~ = ~ sqrt{x^2 ~ + ~ y^2}

arg(z) ~ = ~ arctan(y/x) ~ + ~ pi ⋅ sgn(y) {1 ~ - ~ sgn(x)}/{2}

Re(z) ~ = ~ x ~ = ~ ℜ(z)

Im(z) ~ = ~ y ~ = ~ ℑ(z)

kart(z) ~ = ~ x ⋅ cos(y) ~ + ~ i ⋅ x ⋅ sin(y)

pole(z) ~ = ~ x^2 ~ + ~ y^2 ~ + ~ i ⋅ arg(z)

inv(z) ~ = ~ 1/z ~ = ~ {x ~ - ~ i ⋅ y}/{ x^2 ~ + ~ y^2}

conj(z) ~ = ~ x ~ - ~ i ⋅ y

The functions sigma(x), delta(x), int(x) and frac(x) only evaluate the real part of the argument. They return a number whose imaginary part is always zero.

sigm a(z) ~ = ~ delim{lbrace}{matrix{2}{3}{0 for {x<0} 1 for {x>=0}}}{~}

delt a(z) ~ = ~ delim{lbrace}{matrix {2}{3}{0 for {x<>0} 1 for {x=0}}}{~}

i nt(z) ~ = ~ delim{lbrace}{matrix{2}{3}{{delim{[}{x+1}{]}} for {x<0} {delim{[}{x} {]}} for {x>=0}}}{~}

frac(z) ~ = ~ delim{lbrace}{matrix{2}{3}{{x - delim{[}{x+1}{]}} for {x<0} {x - delim{[}{x}{]}} for {x>=0}}}{~}

Power functions

The square of a complex number is reduced to multiplication.

sqr(z) ~ = ~ x^2 ~ - ~ y^2 ~ + ~ 2ixy

The complex general power function, which is explained in CGRAPH by the symbol “^”, is calculated using the exponential function.

a^z ~ = ~ e^{ln (a^z)} ~ = ~ e^{z ⋅ ln(a)}

It is continuous in the domain [-𝜋,𝜋] in the complex plane.

The square root is traced back to Moivre's formula, as it is often required in the domain [𝜋,2𝜋]. The following applies

sqr t(z) ~ = ~ sqrt{z} ~ = ~ sqrt{r} ~ ⋅ ~ e^{0.5}

If the root function is required in the domain [-𝜋,𝜋], the general exponential function can be used with

z wedge {0.5} ~ = ~ e^{0.5 ⋅ ln(z)}

.

Calculation accuracy and exception handling

CGRAPH uses a floating point format internally for calculations, which allows real numbers to be represented up to an exponent of 101000. The calculation accuracy is approximately 19 decimal places. This format can be limited to a maximum of 15 decimal places for output via the settings in the Mathematics tab. However, inputs can be made with higher accuracy.

Calculations for drawings are performed with full accuracy. The graphics are displayed with an accuracy that is below the maximum magnification.

Some functions, such as the hyperbolic sine in the real domain or the sine in the imaginary domain, implicitly or explicitly involve exponential calculations. The maximum domain of these functions is therefore limited to the maximum or minimum exponent 2839 on the corresponding axes.

Fourier transforms

In CGRAPH, More graphics / One-dimensional FFT . The corresponding equation for the forward transform from the time domain to the image domain is

y_{mu} ~ = ~ T sum{nu =0}{N-1}{x_{nu} ~ ⋅ ~ e^{{-j 2 pi mu nu}/{N}}} ~ ~ with ~ mu ~ = ~ 0, 1, cdots, N-1

The inverse transform is calculated using the equation

x_{nu} ~ = ~ {1}/{NT} sum{mu =0}{N-1}{y_{mu} ~ ⋅ ~ e^{{j 2 pi mu nu}/{N}}} ~ ~ with ~ nu ~ = ~ 0, 1, cdots, N-1

where the constant T is set to 1 in CGRAPH. CGRAPH uses a radix-2 algorithm according to Cooley-Tukey to calculate the FFT.

The required sample values are obtained in CGRAPH from functions. Support values are calculated in a specified interval of the function. Now the first sample value is shifted to 0 and the last to 2𝜋. The sampled values always represent a function starting at zero.

According to Shannon's sampling theorem, the calculated FFT can only be calculated up to half the interval width. In CGRAPH, however, the complete interval [-𝜋,𝜋] is always displayed, showing the mirrored parts of the FFT between 0 and 𝜋 in the range between -𝜋 and 0. This display makes it easier to view the calculated Fourier transform.

Convergence analyses

The convergence of a function for a given starting value is examined through multiple iterations. The calculated function value is taken as the new starting value and the iteration is continued until divergence or convergence can be determined.

z_{n+1} ~ = ~ f(z_n)

CGRAPH calculates the distance between the calculated number zn+1 and the initial number zn and its predecessor zn-1. If this distance increases, divergence is present. Otherwise, the function converges or alternates.

System functions

In many mechanical or electrical systems, the variables of the system are independent of what happens at the input and output of the system. The system function is defined as the quotient of the input and output signals:

H(z) ~ := ~ {Y(z)}/{X(z)}

If the frequency response of the system is to be determined, the complex component j𝜔 can be used instead of the complex variable z. The following conversions are used for the amplitude response a, the attenuation d and the phase response 𝜑:

a ~ = ~ delim{|}{H(j omega)}{|}

d delim{[}{dB}{]} ~ := ~ - 20 ⋅ log_{10} delim{|}{H(j omega)}{|}

varphi ~ = ~ arg(H(j omega))

Fractals

CGRAPH uses two different mapping rules for fractals. In both cases, a function containing a parameter is required.

z_{n+1} ~ = ~ f(z_n, ~ p)

After each iteration, a check is performed to see whether the result lies outside the specified decision limit. If this is the case, the result is transferred to the position of the initial value z0. Otherwise, the calculation is performed up to the specified maximum value n.

When calculating Julia sets, the parameter p is kept constant during the iteration. It must therefore be entered before the fractal is generated.

For Mandelbrot sets, the parameter p is varied across all displayable points in the window, while the starting point z0 is kept constant.

Back to overview