Post Reply 
Complex Plotting App
12-30-2014, 09:17 AM
Post: #1
Complex Plotting App
I was interested in exploring the complex roots of polynomials a while back.
Unfortunately the Advanced Graphing app doesn't like imaginary numbers in its equations ( http://h30434.www3.hp.com/t5/Other-HP-Co...-p/4171298 ), so I was left with writing my own program for visualizing such functions.

Specifically, given a function f(x) : C -> C, I wanted to get a two dimensional plot over some domain [a, b] + i[c, d] where different colors correspond to different output values.

The forum didn't allow me to attach the hpapp file, but you can download it here:
http://dmewes.com/~daniel/Complex%20Plot.hpapp

To use it:
1. Go to Symb, enter F1(X)= (for example X^3-1)
2. Optionally: Go to Plot->Setup to set the boundaries for the real part (X Rng) and imaginary part (Y Rng) of the parameter.
3. Press Plot to start plotting
4. Press On to leave the plot

A few additional notes:
* The X axis corresponds to the real part of the input parameter, the Y axis to the imaginary part.
* The current shader uses a logarithmic scale, and ignores the sign of the real and imaginary parts. You can change the line `co:=RGB...` in the code to use a different shader.
* With the default shader, zero appears as black, (mostly) imaginary numbers appear red, and (mostly) real ones appear green. Results with both an imaginary and real part get shades of yellow.
* Because plotting every pixel is relatively slow, the app starts by plotting a low-resolution plot, and then refines it down to pixel resolution if you keep it running.


I've also attached a photo and a screenshot showing the plots of
1. X^5 - 1
2. sin(0.5*X^3 + X) + cos(X^2)
   


Program code (replace i with the proper imaginary i symbol in `va:=F1...`):
Code:

PlotRes(r);
EXPORT Plot()
BEGIN
 RECT();
 PlotRes(16);
 PlotRes(8);
 PlotRes(4);
 PlotRes(2);
 PlotRes(1);
 WHILE 1 DO
  FREEZE();
 END;
END;
EXPORT PlotRes(r)
BEGIN
 LOCAL xi,yi,co,va;
 xi:=(Xmax-Xmin)/320;
 yi:=(Ymax-Ymin)/240;
 FOR X FROM 0 TO 320-r STEP r DO
  FOR Y FROM 0 TO 240-r STEP r DO
   va:=F1(Xmin+xi*X + i*(Ymin+yi*Y));
   co:=RGB(MIN(255,LN(1+ABS(IM(va)))*128),MIN(255,LN(1+ABS(RE(va)))*128),MIN(2​55,MAX(0,(LN(1+ABS(va))-2)*128)));
   RECT_P(G0,X,Y,X+r-1,Y+r-1,co);
  END;
 END;
END;


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Complex Plotting App - danielmewes - 12-30-2014 09:17 AM
RE: Complex Plotting App - dwgg - 02-01-2015, 01:06 AM
RE: Complex Plotting App - Han - 02-01-2015, 04:01 AM
RE: Complex Plotting App - dwgg - 02-01-2015, 06:42 AM
RE: Complex Plotting App - Mark Hardman - 02-01-2015, 11:17 PM
RE: Complex Plotting App - dwgg - 02-02-2015, 03:43 PM
RE: Complex Plotting App - rprosperi - 02-02-2015, 04:54 PM
RE: Complex Plotting App - dwgg - 02-03-2015, 06:56 PM
RE: Complex Plotting App - danielmewes - 02-04-2015, 03:39 AM
RE: Complex Plotting App - dwgg - 02-06-2015, 04:21 AM
RE: Complex Plotting App - Han - 02-06-2015, 08:17 PM
RE: Complex Plotting App - Han - 02-07-2015, 06:02 AM
RE: Complex Plotting App - rprosperi - 02-07-2015, 03:38 PM
RE: Complex Plotting App - Han - 02-07-2015, 06:24 PM
RE: Complex Plotting App - rprosperi - 02-08-2015, 04:06 PM
RE: Complex Plotting App - Eddie W. Shore - 02-12-2015, 03:26 AM
RE: Complex Plotting App - rprosperi - 02-12-2015, 04:02 AM
RE: Complex Plotting App - Eddie W. Shore - 04-02-2015, 02:58 AM
RE: Complex Plotting App - Han - 04-02-2015, 12:10 PM
RE: Complex Plotting App - salvomic - 04-02-2015, 02:48 PM
RE: Complex Plotting App - Eddie W. Shore - 04-04-2015, 03:03 PM
RE: Complex Plotting App - dwgg - 02-12-2015, 06:29 AM
RE: Complex Plotting App - Han - 02-12-2015, 08:23 AM
RE: Complex Plotting App - dwgg - 02-13-2015, 02:52 AM
RE: Complex Plotting App - Han - 02-13-2015, 10:04 PM
RE: Complex Plotting App - dwgg - 02-14-2015, 12:01 AM
RE: Complex Plotting App - dwgg - 02-14-2015, 11:43 AM
RE: Complex Plotting App - salvomic - 04-02-2015, 05:17 PM
RE: Complex Plotting App - Han - 04-02-2015, 05:40 PM
RE: Complex Plotting App - salvomic - 04-02-2015, 05:50 PM
RE: Complex Plotting App - Han - 02-14-2015, 07:14 PM
RE: Complex Plotting App - dwgg - 02-14-2015, 10:18 PM
RE: Complex Plotting App - Han - 02-17-2015, 01:34 AM
RE: Complex Plotting App - dwgg - 02-18-2015, 06:35 AM
RE: Complex Plotting App - Han - 02-18-2015, 04:41 PM
RE: Complex Plotting App - Han - 02-18-2015, 10:08 PM
RE: Complex Plotting App - dwgg - 02-19-2015, 02:06 AM
RE: Complex Plotting App - Han - 02-19-2015, 02:14 AM
RE: Complex Plotting App - Han - 03-17-2017, 07:28 PM
RE: Complex Plotting App - jtm - 06-30-2017, 03:48 AM
RE: Complex Plotting App - Han - 07-01-2017, 12:17 AM
RE: Complex Plotting App - FrankP - 12-25-2019, 12:26 PM



User(s) browsing this thread: 1 Guest(s)