Creating Hue Plots in Pari-GP
#1
I've e-mailed sheldonison, but I'm getting the feeling he's super busy. I've scoured throughout the internet looking for help on this. I asked a question on stackoverflow. And now I'm asking this question here.

How do you plot complex valued functions in Pari-GP? Particularly; I mean, how do you create hue plots using Pari-GP? Is there something stupid I'm missing here?

I've got my Pari-gp code as good as I can get it at this point (there are still some jumps which occur because Pari is always choosing the principal branch; but in limited cases everything is working).

Do I make an array of values and use the colour plot function somehow? I'm fairly confused. I'm just wondering how Sheldon produces his graphs in Pari; and I feel I'm missing something stupid..?

Any help is greatly appreciated...

All of this is reminding me of why I dropped my major from computer science years ago. I god damn hate coding (unless it's theory, of course).

Regards, James
Reply
#2
Hi James,

 I don't know at the moment, whether in Sheldon's "fatou.gp" there is also that picture_out routine for creating coloured images for complex coordinates. I remember a similar routine provided by tet-forum member Mike. It takes a matrix of complex values and writes a *.ppm file (some basic graphic-file-format) with rgb-values. File should be findable in appendices of tetration forum.     This is a version from 2010, don't know whether there are updates in the forum available.

Kind regards-

Gottfried

PHP Code:
/* =============================================================================  
** Color graphing system - mike3 - 20.11.10 04:07
** Hi.
** I thought I'd post the code I use to generate the color graphs from Pari/GP.
** Here it is.
**
** Note: the output is in .PPM format. 
** You'll need something else to convert that to .PNG. (I use GIMP.)
** 
** Also, I might warn you: it takes a LONG time to graph a complex function
** with a significantly complicated calculation procedure, as it must be
** evaluated at every pixel of the graph.
** 
** (updated 12/16/2010 -- program was not all good: 
**   * spurious "func" parameter in MakeGraph and "safetyarg" was missing.)
** ------------------------------------------------------------------------------------------ 
**  
** ============================================================================= */

/* =============================== Code: ==================================================== */
/* Complex function magnitude/phase plotter. */

/* To use:
*     1. Define function to graph as func(z).
*     2. Load this program.
*     3. Execute MakeGraph(width, height, x0, y0, x1, y1, filename) with the parameters given as follows:
*        width, height = width/height of image in pixels
*        x0, y0, x1, y1 = rectangle of complex plane to graph: x0 + y0i in upper-left corner to x1 + y1i in lower-right corner
*        filename = name of file to save as.
* Output is in .PPM format.
*/


/* Color conversion (HSB to RGB). */

HSB2RGB(hsb) = {
 
      local(H=hsb[1]);
 
      local(S=hsb[2]);
 
      local(B=hsb[3]);
 
      local(HH);
 
      local(F);
 
      local(P);
 
      local(Q);
 
      local(T);

 
      HH floor(6*H)%6;
 
      F = (6*H) - floor(6*H);
 
      P B*(S);
 
      Q B*(- (F*S));
 
      T B*(- (1-F)*S);
 
      if(1.01.0);
 
      if(0.00.0);
 
      if(1.01.0);
 
      if(0.00.0);
 
      if(1.01.0);
 
      if(0.00.0);
 
      if(1.01.0);
 
      if(0.00.0);

 
      if(HH == 0, return([BTP]));
 
      if(HH == 1, return([QBP]));
 
      if(HH == 2, return([PBT]));
 
      if(HH == 3, return([PQB]));
 
      if(HH == 4, return([TPB]));
 
      if(HH == 5, return([BPQ]));
 
      }

/* Safe argument. */
safetyarg(z) = if(== 00arg(z));

/* Make graph. */
MakeGraph(widthheightx0y0x1y1filename) = {
 
      xstep = (x1 x0)/width;
 
      ystep = (y1 y0)/height;
 
      write(filename"P3");
 
      write(filename"# "filename);
 
      write(filenamewidth" "height);
 
      write(filename"255");

 
      for(y=0height-1,
 
          for(x=0width-1,
 
                 xx x0+(xstep*x);
 
                 yy y0+(ystep*y);
 
              z xx+yy*I;
 
              funcvalue func(z);
 
              mag abs(funcvalue);
 
              phase safetyarg(funcvalue);
 
              H phase/(2*Pi);
 
              S 1/(0.3*log(mag 1));
 
              B 1/(1.1 5*log(mag 1));
 
              RGB HSB2RGB([HSB]);
 
                 Red floor(RGB[1]*255.0);
 
                 Green floor(RGB[2]*255.0);
 
                 Blue floor(RGB[3]*255.0);
 
              write1(filenameRed" "Green" "Blue"  ");
 
             );
 
          write(filename"");
 
      );
 
   
Gottfried Helms, Kassel
Reply
#3
Thanks so much, Gottfried! This works perfectly; albeit, it's a little slow.

I'm going to try and make some graphs now.

Regards, James



I don't think this is the same program Sheldon uses, but god damned is this better.

Here's my solution to the Abel equation with \( \log(2) \) multiplier over \( -1 \le \Re(z) \le 4 \) and \( 0.5 \le \Im(z) \le 2.5 \):

   

EDIT: This is about 8 digit precision; it may dip to 4 occasionally, but it hovers around 12; so let's just say 8.
Reply
#4
(05/12/2021, 04:31 AM)JmsNxn Wrote: I've e-mailed sheldonison, but I'm getting the feeling he's super busy. I've scoured throughout the internet looking for help on this. I asked a question on stackoverflow. And now I'm asking this question here.

How do you plot complex valued functions in Pari-GP? Particularly; I mean, how do you create hue plots using Pari-GP? Is there something stupid I'm missing here?

I've got my Pari-gp code as good as I can get it at this point (there are still some jumps which occur because Pari is always choosing the principal branch; but in limited cases everything is working).

Do I make an array of values and use the colour plot function somehow? I'm fairly confused. I'm just wondering how Sheldon produces his graphs in Pari; and I feel I'm missing something stupid..?

Any help is greatly appreciated...

All of this is reminding me of why I dropped my major from computer science years ago. I god damn hate coding (unless it's theory, of course).

Regards, James

I calculated the value of the function by Pari-GP and then imported the value into Mathematica to export the image.
As I mentioned before, I wouldn't have switched to Pari-GP if MMA didn't have very poor support for large number functions.
This also has the good thing that if I want to make a super high resolution image, I can do it in parallel and support breakpoints. (By fully manual parallel scheduling, of course)

The color scheme I use is Hue[(Abs@rawdata+Pi)/(2 Pi), 1/(1+0.3 Arg@rawdata), 1 - 1/(1.1+5 Arg@rawdata)]. This makes the color scheme of the images I draw look "opposite".

https://upload.wikimedia.org/wikipedia/c...e_to_1.gif
https://upload.wikimedia.org/wikipedia/c...number.gif
https://upload.wikimedia.org/wikipedia/c...10%5E6.gif
https://upload.wikimedia.org/wikipedia/c...29%3De.gif

ps:I am so sorry. is Hue[(Arg@rawdata+Pi)/(2 Pi), 1/(1+0.3 Log@Abs@rawdata), 1 - 1/(1.1+5 Log@Abs@rawdata)].
Reply
#5
(09/24/2021, 06:27 PM)Ember Edison Wrote:
(05/12/2021, 04:31 AM)JmsNxn Wrote: I've e-mailed sheldonison, but I'm getting the feeling he's super busy. I've scoured throughout the internet looking for help on this. I asked a question on stackoverflow. And now I'm asking this question here.

How do you plot complex valued functions in Pari-GP? Particularly; I mean, how do you create hue plots using Pari-GP? Is there something stupid I'm missing here?

I've got my Pari-gp code as good as I can get it at this point (there are still some jumps which occur because Pari is always choosing the principal branch; but in limited cases everything is working).

Do I make an array of values and use the colour plot function somehow? I'm fairly confused. I'm just wondering how Sheldon produces his graphs in Pari; and I feel I'm missing something stupid..?

Any help is greatly appreciated...

All of this is reminding me of why I dropped my major from computer science years ago. I god damn hate coding (unless it's theory, of course).

Regards, James

I calculated the value of the function by Pari-GP and then imported the value into Mathematica to export the image.
As I mentioned before, I wouldn't have switched to Pari-GP if MMA didn't have very poor support for large number functions.
This also has the good thing that if I want to make a super high resolution image, I can do it in parallel and support breakpoints. (By fully manual parallel scheduling, of course)

The color scheme I use is Hue[(Abs@rawdata+Pi)/(2 Pi), 1/(1+0.3 Arg@rawdata), 1 - 1/(1.1+5 Arg@rawdata)]. This makes the color scheme of the images I draw look "opposite".

https://upload.wikimedia.org/wikipedia/c...e_to_1.gif
https://upload.wikimedia.org/wikipedia/c...number.gif
https://upload.wikimedia.org/wikipedia/c...10%5E6.gif
https://upload.wikimedia.org/wikipedia/c...29%3De.gif

Woahhhh, those are really cool!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Brjuno number in Pari-GP Ember Edison 1 2,501 10/24/2021, 03:32 AM
Last Post: Ember Edison
  PARI/gp Xorter 14 39,594 07/09/2018, 08:54 AM
Last Post: Xorter
  Pari-TTY - update Gottfried 0 5,215 10/13/2007, 04:02 PM
Last Post: Gottfried



Users browsing this thread: 1 Guest(s)