﻿ Sample Problems > Usage > Functions > complex_functions

# complex_functions

Navigation:  Sample Problems > Usage > Functions >

# complex_functions

{ COMPLEX_FUNCTIONS.PDE }

TITLE 'complex function test'

COORDINATES cartesian2

VARIABLES       { this test uses no variables, it is a plotting test only }

SELECT  ngrid=40

DEFINITIONS

! sample complex

a=9

b=4

! explicit root computation

z = complex(a,b)

r = sqrt(a^2+b^2)

d = z+r

dabs = sqrt((a+r)^2+b^2)

zscale = sqrt(r)/dabs

zroot = zscale*complex(a+r,b)

! reference value

c = 9+sqrt(97)

xd = sqrt(2*c)

zr = c/xd

zi = 4/xd

! expanded code

zrootf = sqrt(CABS(z))*CEXP(0,0.5*atan2(b,a))

BOUNDARIES

REGION 1

START(-1,-1)

LINE TO (1,-1) TO (1,1) TO (-1,1) TO CLOSE

feature start(-1,0) line to (1,0)

feature start(0,-1) line to (0,1)

PLOTS

contour(atan2(y,x))

contour(CARG(x,y))

contour(CABS(x,y))

contour(CEXP(x,y))

contour(CLOG(x,y))

contour(CSQRT(x,y))

contour(CARG(complex(x,y)))

contour(CABS(complex(x,y)))

contour(CEXP(complex(x,y)))

contour(CLOG(complex(x,y)))

contour(CSQRT(complex(x,y)))

SUMMARY

report("Z=A+i*B")

report(a) as "A"

report(b) as "B"

report(zr) as "test real"

report(REAL(zroot))

report(REAL(CSQRT(z)))   ! test new function

report(REAL(zrootf))

report(REAL(CSQRT(z)*CSQRT(z)))

report("")

report(zi) as "test imag"

report(IMAG(zroot))

report(IMAG(CSQRT(z)))   ! test new function

report(IMAG(zrootf))

report(IMAG(CSQRT(z)*CSQRT(z)))

report("")

report(r) as "test cabs(z)"

report(CABS(z))     ! test new function

report("")

report(sqrt(zr^2+zi^2)) as "test cabs(zroot)"

report(CABS(zroot))     ! test new function

report(CABS(zrootf))     ! test new function

report("")

report(REAL(CLOG(z))) report(IMAG(CLOG(z)))

report(REAL(CEXP(CLOG(z)))) report(IMAG(CEXP(CLOG(z))))

END