Site hosted by Angelfire.com: Build your free website today!

Plotting complex functions

(Back)
Email the author:Paolo Bonzini


This program samples the value of a complex function for regularly spaced points of the complex plane and then uses the resulting values to plot a diagram of the value of the complex function.

Actually it is made of TWO programs. One stores in some variables and matrices the values of the function, the other plots the data. This allows to change the window without recalculating everything.

The parameters that the first program asks are NOT related to the display window, instead they are the parameters of the grid used to sample the function. The function currently in the program is tan x/2. To change it, change the statements after Label EQ in the calculation program: it receives the real part in R and the imaginary part in I, and gives out the real part in A and the imaginary part in B. Example (with tan x/2): enter {-2.4,2.4,7} for both L1 and L2. Use a window around the origin, -1<X<1 and -1<Y<1 is good.

Calculation program (note: Xmin, Xmax, Ymin, Ymax, and n, which appear in the Print statements, can be found under the VARS menu; <> means MATH/F/2):

Goto INR
Label EQ
cos R+cosh I=>C
sin R/C=>A
sinh I/C=>B
Return

Label INR
Print "{Xmin,Xmax,Xn}"
Input L1
If dim(L1)<>3 Goto INR
Label INI
Print "{Ymin,Ymax,Yn}"
Input L2
If dim(L2)<>3 Goto INI

(L1(2)-L1(1))/(L1(3)-1)=>S
(L2(2)-L2(1))/(L2(3)-1)=>J
{L1(3),L2(3)}=>dim(mat A)
dim(mat A)=>dim(mat B)

L1(3)=>T
L1(1)=>R
Label R
L2(3)=>K
L2(1)=>I
Label I
Gosub EQ
A=>mat A(T,K)
B=>mat B(T,K)
I+J=>I
K-1=>K
If K>0 Goto I
Print R
R+S=>R
T-1=>T
If T>0 Goto R

Plotting program:

ClrDraw
DispG

L1(3)=>R
R=>T
Label R
L2(3)=>I
I=>K
Label I
Line(mat A(T,I),mat B(T,I),mat A(R,I), mat B(R,I))
Line(mat A(R,K),mat B(R,K),mat A(R,I), mat B(R,I))
I=>K
I-1=>I
If I>0 Goto I
R=>T
R-1=>R
If R>0 Goto R