Post Reply 
Complex Plotting App
02-13-2015, 10:04 PM (This post was last modified: 02-13-2015 10:06 PM by Han.)
Post: #21
RE: Complex Plotting App
Your coloring function could be made to run faster. It's essentially the same algorithm repeated three times. Your k value can be computed using logarithms which would be much faster than using a while loop.

Code:

k:=2*m; // k:=(m-0)/(0.5-0) as the initial k value; if m>0.5 then modify k accordingly
if m>0.5 then
  k:=m/(.5e^FLOOR(LN(m)-LN(.5))*(e-1)) - 1/(e-1);
end;

If ranges:=0 and rangee:=C (C is a constant) then we are essentially finding the exponent x such that \(Ce^x < m \le Ce^{x+1} \).

\[ Ce^x = m \Rightarrow \ln C + x = \ln m \Rightarrow x = \ln m - \ln C \]

Secondly, k:=(m-ranges)/(rangee-ranges) simplifies to:
\[ k = \frac{m-Ce^x}{Ce^{x+1}-Ce^x} = \frac{m-Ce^x}{Ce^x(e-1)}
= \frac{m}{Ce^x(e-1)} - \frac{Ce^x}{Ce^x(e-1)} = \frac{m}{Ce^x}-\frac{1}{e-1} \]

The code could be made smaller by creating a function that computes and returns v.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-14-2015, 12:01 AM
Post: #22
RE: Complex Plotting App
(02-13-2015 10:04 PM)Han Wrote:  Your coloring function could be made to run faster. It's essentially the same algorithm repeated three times. Your k value can be computed using logarithms which would be much faster than using a while loop.

Code:

k:=2*m; // k:=(m-0)/(0.5-0) as the initial k value; if m>0.5 then modify k accordingly
if m>0.5 then
  k:=m/(.5e^FLOOR(LN(m)-LN(.5))*(e-1)) - 1/(e-1);
end;

If ranges:=0 and rangee:=C (C is a constant) then we are essentially finding the exponent x such that \(Ce^x < m \le Ce^{x+1} \).

\[ Ce^x = m \Rightarrow \ln C + x = \ln m \Rightarrow x = \ln m - \ln C \]

Secondly, k:=(m-ranges)/(rangee-ranges) simplifies to:
\[ k = \frac{m-Ce^x}{Ce^{x+1}-Ce^x} = \frac{m-Ce^x}{Ce^x(e-1)}
= \frac{m}{Ce^x(e-1)} - \frac{Ce^x}{Ce^x(e-1)} = \frac{m}{Ce^x}-\frac{1}{e-1} \]

The code could be made smaller by creating a function that computes and returns v.

Thank you for the recommendation. That part of code was just a port of Domain coloring code from wiki commons. I tried the modification and I think I see improvement of couple of seconds (for the same previous plot of (X+2)^2*(X-1-2*i)*(X+i)) in the simulator. I have not tried on actual HP Prime yet since I left it at home today.

Code:

// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring

SetHSV(h,s,v);
GetColor(v);
EvalF();

EXPORT Plot()
BEGIN
  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z1;
  local a,b,b1,d,k,x,y;
  local r:=4;  //r is size of initial square which is 2^r by 2^r pixels

  d:=2^r;
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;
IF r THEN
  FOR k FROM 1 TO r DO
    d:=2^(r-k);
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
      END;
    END;
  END;
END;
WHILE 1 DO
  FREEZE;
END;
//  WAIT(-1);
END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := FLOOR(h*6);
        i := IP(z);
        f := h*6 - z;
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,k,sat,val;
    LOCAL c:=.01;

    IF v≠0 THEN a:=ARG(v); END;
    WHILE (a<0) DO a := a+ (2*π); END;
    a := a/(2*π);

// RE Contour
    m := ABS(RE(v));
    IF m>c then
      k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
    ELSE
      k:=m/c;
    END;
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;
    IF (val > 0.9999) OR (sat >0.9999) THEN 
      return SetHSV(a/6,sat,val);
      //return RGB(200,200,200); 
    END;

//IM Contour
    m := ABS(IM(v));
    IF m>c then
      k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
    ELSE
      k:=m/c;
    END;
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;
    IF (val > 0.9999) OR (sat >0.9999) THEN 
      return SetHSV(a/6,sat,val);
      //return RGB(255,255,255); 
    END;

//Domain Coloring
    m := ABS(v); 
    IF m>c then
      k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
    ELSE
      k:=m/c;
    END;
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;

    return SetHSV(a/6,sat,val);
END;
Find all posts by this user
Quote this message in a reply
02-14-2015, 11:43 AM (This post was last modified: 02-14-2015 11:47 AM by dwgg.)
Post: #23
RE: Complex Plotting App
I did some further major improvement on the complex plotting app today, as listed below:

1. Implemented Plot Setup Menu to select X min/max, Y min/max, pixel box size, contour/magmitude mask resolution, Coloring scheme, contour grid on/off. I referenced functions in Graph3D as templates for overriding the Plot Setup menu.
   
There is a small issue where the drop-down box implementation for coloring scheme is not working on the simulater.. but it works fine on the actual HP Prime. Graph3D is also showing the same problem with the "Type", so I guess maybe this is an issue with the simulator.

2. the program now uses PIXELON_P for the last sweep or when r is set to 0 (single sweep)

code below:
Code:

// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring

//Global variables
initComp:=0;
r;  //r is size of initial square which is 2^r by 2^r pixels
c;
coloring;
REGridOn;
IMGridOn;


SetHSV(h,s,v);
GetColor(v);
EvalF();
gComp_setdefault();
gComp_getsettings();

PlotSetup()
begin
  if initComp==0 then
    gComp_setdefault();
  end;
  gComp_getsettings();
end;

gComp_setdefault()
BEGIN
  Xmin:=-4; Xmax:=4;
  Ymin:=-3; Ymax:=3;
  r:=4;
  c:=.01;
  coloring:=1;
  initComp:=1;
  REGridOn:=1;
  IMGridOn:=1;
end;


view "Set Plot Options",gComp_getsettings()
begin
  local j;

  if initComp==0 then
    gComp_setdefault();
  end;

  local xmintemp:=Xmin,xmaxtemp:=Xmax;
  local ymintemp:=Ymin,ymaxtemp:=Ymax;
  local coloringtemp:=coloring;
  local rtemp:=r,ctemp:=c,REGridOntemp:=REGridOn,IMGridOntemp:=IMGridOn;

  if input(
    {
      {xmintemp,[0],{15,30,0}},
      {xmaxtemp,[0],{65,30,0}},
      {ymintemp,[0],{15,30,1}},
      {ymaxtemp,[0],{65,30,1}},
      {rtemp,[0],{15,20,2}},
      {ctemp,[0],{65,30,2}},
      {coloringtemp,{"Red-Yellow Domain Coloring","HSV Domain Coloring", "Logarithmic"},{20,30,3}},
      {REGridOntemp,0,{90,10,4}},
      {IMGridOntemp,0,{90,10,5}}
    },
    "Plot Setup",
    {
      "Xmin=", "Xmax=",
      "Ymin=", "Ymax=",
      "Box=", "Resolution=",
      "Coloring",
      "RE Contour Grid",
      "IM Contour Grid"
    },
    {
      "Enter minimum horizontal value",
      "Enter maximum horizontal value",
      "Enter minimum vertical value",
      "Enter maximum vertical value",
      "Initial pixel square width. Enter 0 for one pass",
      "Resolution for contour grid & magnitude mask",
      "Select coloring scheme",
      "Draw Real Contour Grids",
      "Draw Imaginary Contour Grids"
     })
  then

    textout_p("Applying plot options...",G0,1,1,1,0,320,#FFFFFFh);
    if xmintemp>=xmaxtemp then
      msgbox("Warning: Invalid Xmin/Xmax! Setting Xmax:=Xmin+1");
      xmaxtemp:=xmintemp+1;
    end;

    if ymintemp>=ymaxtemp then
      msgbox("Warning: Invalid Ymin/Ymax! Setting Ymax:=Ymin+1");
      ymaxtemp:=ymintemp+1;
    end;

    if rtemp<0 then
      msgbox("Warning: Box size must be >= 0; reset to 4");
      rtemp:=4;
    end;

    if (xmintemp<>Xmin) OR (xmaxtemp<>Xmax) OR
      (ymintemp<>Ymin) OR (ymaxtemp<>Ymax)
    then
      Xmax:=xmaxtemp; Xmin:=xmintemp;
      Ymax:=ymaxtemp; Ymin:=ymintemp;
    end;

    if rtemp<>r then
      r:=rtemp;
    end;

    if ctemp<>c then
      c:=ctemp;
    end;

    if coloringtemp<>coloring then
      coloring:=coloringtemp;
    end;

    if REGridOntemp<>REGridOn then
      REGridOn:=REGridOntemp;
    end;

    if IMGridOntemp<>IMGridOn then
      IMGridOn:=IMGridOntemp;
    end;

  end;

end;

EXPORT Plot()
BEGIN
  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z1;
  local a,b,b1,d,k,x,y;
 // local r:=4;  //r is size of initial square which is 2^r by 2^r pixels

  d:=2^r;
IF r>0 THEN
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;
  FOR k FROM 1 TO r-1 DO
    d:=2^(r-k);
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
      END;
    END;
  END;
    d:=1;
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
        PIXON_P(G0,a,b,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        PIXON_P(G0,a+d,b,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        PIXON_P(G0,a+d,b-d,co);
      END;
    END;
ELSE
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      PIXON_P(G0,x,y,co); 
    END;
  END;
END;
WHILE 1 DO
  FREEZE;
END;
//  WAIT(-1);
END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := FLOOR(h*6);
        i := IP(z);
        f := h*6 - z;
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,k,sat,val;
   // LOCAL c:=.01;

    IF v≠0 THEN a:=ARG(v); END;
    WHILE (a<0) DO a := a+ (2*π); END;
    a := a/(2*π);

// RE Contour
    IF REGridOn then
      m := ABS(RE(v));
      IF m>c then
        k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
      ELSE
        k:=m/c;
      END;
      IF (k<0.5) THEN
          sat:=k*2;
      ELSE
          sat:=1 -(k -0.5) *2;
      END;
      val := sat;

      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      val := 1 - val;
      val := 1 - (1-val)^3;
      val := 0.6 + val*0.4;
      IF (val > 0.9999) OR (sat >0.9999) THEN
        IF coloring==1 THEN a:=a/6; ELSE IF coloring==3 THEN return RGB(200,200,200); END; END;
        return SetHSV(a,sat,val);
      END;
  END;

//IM Contour
    IF IMGridOn then
      m := ABS(IM(v));
      IF m>c then
        k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
      ELSE
        k:=m/c;
      END;
      IF (k<0.5) THEN
          sat:=k*2;
      ELSE
          sat:=1 -(k -0.5) *2;
      END;
      val := sat;

      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      val := 1 - val;
      val := 1 - (1-val)^3;
      val := 0.6 + val*0.4;
      IF (val > 0.9999) OR (sat >0.9999) THEN 
        IF coloring==1 THEN a:=a/6; ELSE IF coloring==3 THEN return RGB(255,255,255); END; END;
        return SetHSV(a,sat,val);
      END;
  END;

//Domain Coloring
    IF coloring==3 THEN
      return RGB(MIN(255,LN(1+ABS(IM(v)))*128),MIN(255,LN(1+ABS(RE(v)))*128),MIN(255,MAX​(0,(LN(1+ABS(v))-2)*128)));
    END; 
    m := ABS(v); 
    IF m>c then
      k:=m/(c*e^FLOOR(LN(m)-LN(c))*(e-1)) - 1/(e-1);
    ELSE
      k:=m/c;
    END;
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;

    IF coloring==1 THEN a:=a/6; END;
    return SetHSV(a,sat,val);
END;
Find all posts by this user
Quote this message in a reply
02-14-2015, 07:14 PM
Post: #24
RE: Complex Plotting App
Does PIXELON_P make any difference in speed vs RECT_P for the final sweep?

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-14-2015, 10:18 PM
Post: #25
RE: Complex Plotting App
Well.. I tried and it seems to give about 15 percent boost for single pass... The thing though is that the result is not consistent.. Sometimes the times come out to be almost the same. At least, I never saw the change making the plot go slower, so I put it in. Please try it and let me know if you see improvement.
Find all posts by this user
Quote this message in a reply
02-17-2015, 01:34 AM (This post was last modified: 02-17-2015 08:17 PM by Han.)
Post: #26
RE: Complex Plotting App
I only did a few tests but it seemed that using PIXON_P added a few seconds on the virtual calc; perhaps it's machine/OS dependent? Anyway, here's a slightly faster code (for me, anyway) while cleaning up the code a bit. I basically tried to reduce the number of floating point operations; I'm sure more could be done, though.

This doesn't incorporate the fancier features you've added such as the settings etc.

Code:
// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring


SetHSV(h,s,v);
GetColor(v);
EvalF();

em1:=1/(e-1);

EXPORT Plot(r)
BEGIN
  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z0,z1;
  local a,b,d,k,x,y;

  d:=2^r;
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymax-y*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;

IF r THEN
  FOR k FROM 1 TO r DO
    d:=2^(r-k);
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d+d;
        z1:=Xmin+a*dx+i*(Ymax-b*dy);
        co:=EvalF(z1);
        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
      END;
    END;
  END;
END;

  FREEZE;
//  WAIT(-1);
END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := h*6;
        i := IP(z);
        f := FP(z);
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,ranges,rangee,k,sat,val;

    IF v≠0 THEN a:=ARG(v); END;
    a:=a MOD (2*π);
    a := a/(2*π);

// RE Conformal mapping
    m := ABS(RE(v));
    k:=m;
    IF m>1 THEN
      k:=(m/e^(FLOOR(LN(m)))-1)*em1;
    END;
    sat := 2*k;
    IF k>=0.5 THEN sat := 2-sat; END;
    val := 1-0.4*sat^3;
    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;
    IF (val > 0.9999) OR (sat >0.9999) THEN return SetHSV(a,sat,val); END;

//IM Conformal mapping
    m := ABS(IM(v));
    k:=m;
    IF m>1 THEN
      k:=(m/e^(FLOOR(LN(m)))-1)*em1;
    END;
    sat:=2*k;
    IF k>=0.5 THEN sat:=2-sat; END;
    val := 1-0.4*sat^3;
    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;
    IF (val > 0.9999) OR (sat >0.9999) THEN return SetHSV(a,sat,val); END;

//Domain Coloring
    m := ABS(v);
    k:=m;
    IF m>1 THEN
      k:=(m/e^(FLOOR(LN(m)))-1)*em1;
    END;
    sat := 2*k;
    IF k>=0.5 THEN sat:=2-sat; END;
    val := 1-0.4*sat^3;
    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;
    return SetHSV(a,sat,val);
END;

EDIT: Also, the issues you are seeing with the choose field in the INPUT() command can be resolved by placing it last. It appears to be a bug in the virtual calc, and seemingly only on Windows 7.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-18-2015, 06:35 AM (This post was last modified: 02-18-2015 08:01 AM by dwgg.)
Post: #27
RE: Complex Plotting App
I integrated Han's latest changes into my latest code and did some measurement on my HP Prime. Function used for testing was (X^2-1)*(X-2-i)^2/(X^2+2+2*i), and plot setting was X= -4 to 4, Y= -3 to 3, Box=4, Resolution=0.01, Coloring: Red-Yellow, RE/IM Contour enabled.

[EDITED with new test result] I tested couple of times more after I initially uploaded test result, and the times were not coming in consistently.. I tested some more and found out:
1. There seems to be some performance degradation after running calculator some time.. maybe there is a memory leak or something like that.. so I did reset (symb+on key) for each test run to counter this.

2. if you leave the calculator without touching key or screen while doing the plot, it seems to take longer time.. probably there is some power saving routine that comes in when screen/key is not pressed for some period. I countered by periodically touching the screen to prevent power saving.

With 1 and 2 additional conditions above, I ran each case twice and I am now getting consistent results. Times below:

1. new code (inc. Han's improvements), single sweep with PIXELON_P(box=0): 1st run=4:58, 2nd run=5:01
2. new code, PIXELON_P for last sweep: 1st=5:02, 2nd=5:00
3. new code, RECT_P for all sweep: 1st=5:05, 2nd=5:05
4. old code, PIXELON_P for last sweep: 1st=5:19, 2nd=5:18

So, Han's code change does show good improvement, and PIXELON_P change also shows improvement, although it's a very minimal improvement.

I am attaching the new code below, so if anyone is interested feel free to test and let us know the result (after all, our focus should be the best performance on the actual calculator).

Code:

// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring

//Global variables
initComp:=0;
r;  //r is size of initial square which is 2^r by 2^r pixels
c;
coloring;
REGridOn;
IMGridOn;
em1:=1/(e-1);


SetHSV(h,s,v);
GetColor(v);
EvalF();
gComp_setdefault();
gComp_getsettings();

PlotSetup()
begin
  if initComp==0 then
    gComp_setdefault();
  end;
  gComp_getsettings();
end;

gComp_setdefault()
BEGIN
  Xmin:=-4; Xmax:=4;
  Ymin:=-3; Ymax:=3;
  r:=4;
  c:=.01;
  coloring:=1;
  initComp:=1;
  REGridOn:=1;
  IMGridOn:=1;
end;


view "Set Plot Options",gComp_getsettings()
begin
  local j;

  if initComp==0 then
    gComp_setdefault();
  end;

  local xmintemp:=Xmin,xmaxtemp:=Xmax;
  local ymintemp:=Ymin,ymaxtemp:=Ymax;
  local coloringtemp:=coloring;
  local rtemp:=r,ctemp:=c,REGridOntemp:=REGridOn,IMGridOntemp:=IMGridOn;

  if input(
    {
      {xmintemp,[0],{15,30,0}},
      {xmaxtemp,[0],{65,30,0}},
      {ymintemp,[0],{15,30,1}},
      {ymaxtemp,[0],{65,30,1}},
      {rtemp,[0],{15,20,2}},
      {ctemp,[0],{65,30,2}},
      {coloringtemp,{"Red-Yellow Domain Coloring","HSV Domain Coloring", "Logarithmic"},{20,30,3}},
      {REGridOntemp,0,{90,10,4}},
      {IMGridOntemp,0,{90,10,5}}
    },
    "Plot Setup",
    {
      "Xmin=", "Xmax=",
      "Ymin=", "Ymax=",
      "Box=", "Resolution=",
      "Coloring",
      "RE Contour Grid",
      "IM Contour Grid"
    },
    {
      "Enter minimum horizontal value",
      "Enter maximum horizontal value",
      "Enter minimum vertical value",
      "Enter maximum vertical value",
      "Initial pixel square width. Enter 0 for one pass",
      "Resolution for contour grid & magnitude mask",
      "Select coloring scheme",
      "Draw Real Contour Grids",
      "Draw Imaginary Contour Grids"
     })
  then

    textout_p("Applying plot options...",G0,1,1,1,0,320,#FFFFFFh);
    if xmintemp>=xmaxtemp then
      msgbox("Warning: Invalid Xmin/Xmax! Setting Xmax:=Xmin+1");
      xmaxtemp:=xmintemp+1;
    end;

    if ymintemp>=ymaxtemp then
      msgbox("Warning: Invalid Ymin/Ymax! Setting Ymax:=Ymin+1");
      ymaxtemp:=ymintemp+1;
    end;

    if rtemp<0 then
      msgbox("Warning: Box size must be >= 0; reset to 4");
      rtemp:=4;
    end;

    if (xmintemp<>Xmin) OR (xmaxtemp<>Xmax) OR
      (ymintemp<>Ymin) OR (ymaxtemp<>Ymax)
    then
      Xmax:=xmaxtemp; Xmin:=xmintemp;
      Ymax:=ymaxtemp; Ymin:=ymintemp;
    end;

    if rtemp<>r then
      r:=rtemp;
    end;

    if ctemp<>c then
      c:=ctemp;
    end;

    if coloringtemp<>coloring then
      coloring:=coloringtemp;
    end;

    if REGridOntemp<>REGridOn then
      REGridOn:=REGridOntemp;
    end;

    if IMGridOntemp<>IMGridOn then
      IMGridOn:=IMGridOntemp;
    end;

  end;

end;

EXPORT Plot()
BEGIN
  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z1;
  local a,b,b1,d,k,x,y;

  d:=2^r;
IF r>0 THEN
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;
  FOR k FROM 1 TO r-1 DO
    d:=2^(r-k);
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
      END;
    END;
  END;
    d:=1;
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
//        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        PIXON_P(G0,a,b,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
//        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        PIXON_P(G0,a+d,b,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
//        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
        PIXON_P(G0,a+d,b-d,co);
      END;
    END;
ELSE
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      PIXON_P(G0,x,y,co); 
    END;
  END;
END;
WHILE 1 DO
  FREEZE;
END;
//  WAIT(-1);
END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := h*6;
        i := IP(z);
        f := FP(z);
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,k,sat,val;

    IF v≠0 THEN a:=ARG(v); END;
    a:=a MOD (2*π);
    a := a/(2*π);

// RE Contour
    IF REGridOn then
      m := ABS(RE(v));
      k:=m/c;
      IF m>c then
        k:=(m/(c*e^FLOOR(LN(m)-LN(c)))-1)*em1;
      END;
      sat:=2*k;
      IF k>=0.5 THEN sat:=2-sat; END;
      val := 1-0.4*sat^3;

      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      IF (val > 0.9999) OR (sat >0.9999) THEN
        IF coloring==1 THEN a:=a/6; ELSE IF coloring==3 THEN return RGB(200,200,200); END; END;
        return SetHSV(a,sat,val);
      END;
  END;

//IM Contour
    IF IMGridOn then
      m := ABS(IM(v));
      k:=m/c;
      IF m>c then
        k:=(m/(c*e^FLOOR(LN(m)-LN(c)))-1)*em1;
      END;
      sat:=2*k;
      IF k>=0.5 THEN sat:=2-sat; END;
      val := 1-0.4*sat^3;

      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      IF (val > 0.9999) OR (sat >0.9999) THEN 
        IF coloring==1 THEN a:=a/6; ELSE IF coloring==3 THEN return RGB(255,255,255); END; END;
        return SetHSV(a,sat,val);
      END;
  END;

//Domain Coloring
    IF coloring==3 THEN
      return RGB(MIN(255,LN(1+ABS(IM(v)))*128),MIN(255,LN(1+ABS(RE(v)))*128),MIN(255,MAX​(0,(LN(1+ABS(v))-2)*128)));
    END; 
    m := ABS(v); 
    k:=m/c;
    IF m>c then
      k:=(m/(c*e^FLOOR(LN(m)-LN(c)))-1)*em1;
    END;
    sat:=2*k;
    IF k>=0.5 THEN sat:=2-sat; END;
    val := 1-0.4*sat^3;
    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    IF coloring==1 THEN a:=a/6; END;
    return SetHSV(a,sat,val);
END;
Find all posts by this user
Quote this message in a reply
02-18-2015, 04:41 PM (This post was last modified: 02-18-2015 05:06 PM by Han.)
Post: #28
RE: Complex Plotting App
Some minor suggestions that may (or may not) give a tiny bit of speed boost:

1. Originally, my first code submission contained a bug that would compute the z-value for the bottom left corner of the screen, but color the top left. That has since been fixed. I think that it's faster to use:

a:=x*2*d; b:=y*2*d+d;
z1:=Xmin+a*dx+i*(Ymax-b*dy);

instead of

a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
z1:=Xmin+a*dx+i*(Ymin+b1*dy);

since there are fewer floating point operations in the former vs. the latter.

2. In the case where k=r (i.e. when d=1), you can save a few more flops by changing

FOR x FROM 0 TO 160/d-1 DO
FOR y FROM 0 TO 120/d-1 DO
a:=x*2*d; b:=y*2*d;

to

FOR x FROM 0 TO 159 DO
FOR y FROM 0 TO 119 DO
a:=x*2; b:=y*2;

and subsequent references to d should be removed (so that fewer flops are used).

3. Rather than subtracting LN(c), create a constant lnc:=LN(c); and replace

k:=(m/(c*e^FLOOR(LN(m)-LN(c)))-1)*em1;

with

k:=(m/(c*e^FLOOR(LN(m)-lnc))-1)*em1;

since this means one fewer operation (computing LN(c) costs more than simply subtracting the pre-computed value)

4. (EDIT): move the definition of a in a:=x*2*d; to _outside_ the FOR y loop (since a doesn't needed to be recomputed every time we loop over y). This idea also suggests that we should find a different way to compute z1 as we loop over x and y to further reduce the number of flops.


These are minor changes, but since we're looping 76800 times, it may be that they add up to slight speedups.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-18-2015, 10:08 PM (This post was last modified: 02-19-2015 01:56 AM by Han.)
Post: #29
RE: Complex Plotting App
Was able to get it down to about 4:50 (290 seconds); temporarily fixed the color type issue in the settings screen.

EDIT: Made a few more modifications and dropped the time down to 279 seconds)

Code:
// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring

//Global variables
initComp:=0;
r;  //r is size of initial square which is 2^r by 2^r pixels
c;
coloring;
REGridOn;
IMGridOn;
em1:=1/(e-1);


SetHSV(h,s,v);
GetColor(v);
EvalF();
gComp_setdefault();
gComp_getsettings();

PlotSetup()
begin
  if initComp==0 then
    gComp_setdefault();
  end;
  gComp_getsettings();
end;

gComp_setdefault()
BEGIN
  Xmin:=-4; Xmax:=4;
  Ymin:=-3; Ymax:=3;
  r:=4;
  c:=.01;
  coloring:=1;
  initComp:=1;
  REGridOn:=1;
  IMGridOn:=1;
end;


view "Set Plot Options",gComp_getsettings()
begin
  local j;

  if initComp==0 then
    gComp_setdefault();
  end;

  local xmintemp:=Xmin,xmaxtemp:=Xmax;
  local ymintemp:=Ymin,ymaxtemp:=Ymax;
  local coloringtemp:=coloring;
  local rtemp:=r,ctemp:=c,REGridOntemp:=REGridOn,IMGridOntemp:=IMGridOn;

  if input(
    {
      {xmintemp,[0],{15,30,0}},
      {xmaxtemp,[0],{65,30,0}},
      {ymintemp,[0],{15,30,1}},
      {ymaxtemp,[0],{65,30,1}},
      {rtemp,[0],{15,20,2}},
      {ctemp,[0],{65,30,2}},
      {REGridOntemp,0,{90,10,4}},
      {IMGridOntemp,0,{90,10,5}},
      {coloringtemp,{"Red-Yellow Domain Coloring","HSV Domain Coloring", "Logarithmic"},{20,30,3}}
    },
    "Plot Setup",
    {
      "Xmin=", "Xmax=",
      "Ymin=", "Ymax=",
      "Box=", "Resolution=",
      "RE Contour Grid",
      "IM Contour Grid",
      "Coloring"
    },
    {
      "Enter minimum horizontal value",
      "Enter maximum horizontal value",
      "Enter minimum vertical value",
      "Enter maximum vertical value",
      "Initial pixel square width. Enter 0 for one pass",
      "Resolution for contour grid & magnitude mask",
      "Draw Real Contour Grids",
      "Draw Imaginary Contour Grids",
      "Select coloring scheme"
     })
  then

    textout_p("Applying plot options...",G0,1,1,1,0,320,#FFFFFFh);
    if xmintemp>=xmaxtemp then
      msgbox("Warning: Invalid Xmin/Xmax! Setting Xmax:=Xmin+1");
      xmaxtemp:=xmintemp+1;
    end;

    if ymintemp>=ymaxtemp then
      msgbox("Warning: Invalid Ymin/Ymax! Setting Ymax:=Ymin+1");
      ymaxtemp:=ymintemp+1;
    end;

    if rtemp<0 then
      msgbox("Warning: Box size must be >= 0; reset to 4");
      rtemp:=4;
    end;

    if (xmintemp<>Xmin) OR (xmaxtemp<>Xmax) OR
      (ymintemp<>Ymin) OR (ymaxtemp<>Ymax)
    then
      Xmax:=xmaxtemp; Xmin:=xmintemp;
      Ymax:=ymaxtemp; Ymin:=ymintemp;
    end;

    if rtemp<>r then
      r:=rtemp;
    end;

    if ctemp<>c then
      c:=ctemp;
    end;

    if coloringtemp<>coloring then
      coloring:=coloringtemp;
    end;

    if REGridOntemp<>REGridOn then
      REGridOn:=REGridOntemp;
    end;

    if IMGridOntemp<>IMGridOn then
      IMGridOn:=IMGridOntemp;
    end;

  end;

end;

EXPORT Plot()
BEGIN

  if initComp==0 then
    gComp_setdefault();
  end;

  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z0,z1;
  local a,b,d,k,x,y,dd;

  d:=2^r;
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymax-y*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;

  IF r>0 THEN
    FOR k FROM 1 TO r DO
      d:=2^(r-k); dd:=2*d;
      FOR x FROM 0 TO 160/d-1 DO
        a:=x*dd;
        z1:=Xmin+a*dx+i*(Ymax+d*dy);
        FOR y FROM 0 TO 120/d-1 DO
          b:=y*dd+d;
          z1:=z1-i*dd*dy;
          co:=EvalF(z1);
          RECT_P(G0,a,b,a+d-1,b+d-1,co);
          z0:=z1+d*dx;
          co:=EvalF(z0);
          RECT_P(G0,a+d,b,a+dd-1,b+d-1,co);
          z0:=z0+i*d*dy;
          co:=EvalF(z0);
          RECT_P(G0,a+d,b-d,a+dd-1,b-1,co);
        END;
      END;
    END;

  END;

  FREEZE;

END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := h*6;
        i := IP(z);
        f := FP(z);
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,k,sat,val;

    IF v≠0 THEN a:=ARG(v); END;
    a:=a MOD (2*π);
    a := a/(2*π);
    IF coloring==1 THEN a:=a/6; END;

// RE Contour
    IF REGridOn then
      m := ABS(RE(v));
      k:=m/c;
      IF k>1 then
        k:=(k/e^FLOOR(LN(k)) -1)*em1;
      END;
      sat:=2*k;
      IF k>=0.5 THEN sat:=2-sat; END;
      val := 1-0.4*sat^3;
      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      IF (val > 0.9999) OR (sat >0.9999) THEN
        IF coloring==3 THEN return RGB(200,200,200); END;
        return SetHSV(a,sat,val);
      END;
  END;

//IM Contour
    IF IMGridOn then
      m := ABS(IM(v));
      k:=m/c;
      IF k>1 then
        k:=(k/e^FLOOR(LN(k)) -1)*em1;
      END;
      sat:=2*k;
      IF k>=0.5 THEN sat:=2-sat; END;
      val := 1-0.4*sat^3;
      sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

      IF (val > 0.9999) OR (sat >0.9999) THEN 
        IF coloring==3 THEN return RGB(255,255,255); END;
        return SetHSV(a,sat,val);
      END;
  END;

//Domain Coloring
    IF coloring==3 THEN
      return RGB(MIN(255,LN(1+ABS(IM(v)))*128),MIN(255,LN(1+ABS(RE(v)))*128),MIN(255,MAX​(0,(LN(1+ABS(v))-2)*128)));
    END; 
    m := ABS(v); 
    k:=m/c;
    IF k>1 then
        k:=(k/e^FLOOR(LN(k)) -1)*em1;
    END;
    sat:=2*k;
    IF k>=0.5 THEN sat:=2-sat; END;
    val := 1-0.4*sat^3;
    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;
    return SetHSV(a,sat,val);
END;

I opted to leave out the PIXON code since there was not much improvement and yet much larger code.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-19-2015, 02:06 AM
Post: #30
RE: Complex Plotting App
I tried the new code on my HP prime, time comes out to be 4:45...similar enough so confirms Han's measurement. Of course, if we turn the contour grids off in the plot option the plot time comes down to 3:17 for the same graph, so if we find some way to optimize drawing the contour grid I think we can reduce the time further.

Also, I found an interesting complex graph implementation done in javascript here:

http://davidbau.com/conformal

The source shows a lot of optimizations for drawing complex graph that could be beneficial in optimizing our code here, as well as some other feature implementations such as doing conformal mapping based on image (world map), and interactive animation support (similar to HP Prime's Geometry app).
Find all posts by this user
Quote this message in a reply
02-19-2015, 02:14 AM
Post: #31
RE: Complex Plotting App
(02-19-2015 02:06 AM)dwgg Wrote:  I tried the new code on my HP prime, time comes out to be 4:45...similar enough so confirms Han's measurement. Of course, if we turn the contour grids off in the plot option the plot time comes down to 3:17 for the same graph, so if we find some way to optimize drawing the contour grid I think we can reduce the time further.

Also, I found an interesting complex graph implementation done in javascript here:

http://davidbau.com/conformal

The source shows a lot of optimizations for drawing complex graph that could be beneficial in optimizing our code here, as well as some other feature implementations such as doing conformal mapping based on image (world map), and interactive animation support (similar to HP Prime's Geometry app).

I'm testing out an idea which is based on the other link you provided.

http://www.mai.liu.se/~hanlu09/complex/d...icode.html


The idea is to store the result F evaluated at specified rows and columns and then use LINE_P at the end. The result is (hopefully) similar to what you see in section 0.1 (see link). It's an alternate method for generating the contours, but rather than generating the entire set of contours, it would simply show the map of the original z plane limited to Xmin/Xmax and Ymin/Ymax under the function f. That way, we also get a better idea of how the map affects the rectangular plane as a whole.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-02-2015, 02:58 AM (This post was last modified: 04-02-2015 03:27 AM by Eddie W. Shore.)
Post: #32
RE: Complex Plotting App
(02-12-2015 04:02 AM)rprosperi Wrote:  
(02-12-2015 03:26 AM)Eddie W. Shore Wrote:  All I got from this link: http://dmewes.com/~daniel/Complex%20Plot.hpapp is a blank app. Am I missing something? Thanks!

Copy the code in Post #12 above and paste into Emulator (and then download to device per normal, etc.).

I am still having trouble, for the the example X^3, I just get the curve as if I was just using the Function App. I am using emulator version 6975. I tried pasting several codes and can't get the app to work properly.

Please advise.


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2015, 12:10 PM
Post: #33
RE: Complex Plotting App
(04-02-2015 02:58 AM)Eddie W. Shore Wrote:  
(02-12-2015 04:02 AM)rprosperi Wrote:  Copy the code in Post #12 above and paste into Emulator (and then download to device per normal, etc.).

I am still having trouble, for the the example X^3, I just get the curve as if I was just using the Function App. I am using emulator version 6975. I tried pasting several codes and can't get the app to work properly.

Please advise.

In the virtual calc, copy the Function app and save it as Complex. Activate the Complex app. Paste the code for the app into the Complex (App) source file listed in the Program Catalog. If all went well, then you should be able to plot, now.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-02-2015, 02:48 PM
Post: #34
RE: Complex Plotting App
(04-02-2015 12:10 PM)Han Wrote:  In the virtual calc, copy the Function app and save it as Complex. Activate the Complex app. Paste the code for the app into the Complex (App) source file listed in the Program Catalog. If all went well, then you should be able to plot, now.

hi Han,
me too, perhaps I've missing something...
I created Complex app (from Function), then pasted your code in post 29.
With (X+2)^2*(X-1-2*i)*(X+i), if plot, I get F1(X): NaN

thank you for help

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2015, 05:17 PM
Post: #35
RE: Complex Plotting App
(02-14-2015 11:43 AM)dwgg Wrote:  I did some further major improvement on the complex plotting app today, as listed below:

1. Implemented Plot Setup Menu to select X min/max, Y min/max, pixel box size, contour/magmitude mask resolution, Coloring scheme, contour grid on/off. I referenced functions in Graph3D as templates for overriding the Plot Setup menu.

I copied Function, renamed the copy Complex, then copied the code into the "program" tab of the app with Connection Kit.
I don't get the option for complex in Plot Setup as they are shown in your image...

please, help

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2015, 05:40 PM
Post: #36
RE: Complex Plotting App
(04-02-2015 05:17 PM)salvomic Wrote:  
(02-14-2015 11:43 AM)dwgg Wrote:  I did some further major improvement on the complex plotting app today, as listed below:

1. Implemented Plot Setup Menu to select X min/max, Y min/max, pixel box size, contour/magmitude mask resolution, Coloring scheme, contour grid on/off. I referenced functions in Graph3D as templates for overriding the Plot Setup menu.

I copied Function, renamed the copy Complex, then copied the code into the "program" tab of the app with Connection Kit.
I don't get the option for complex in Plot Setup as they are shown in your image...

please, help

Salvo

There is no need for the connectivity kit. Just directly paste it into the virtual calculator. Copy the code from:

http://www.hpmuseum.org/forum/thread-275...l#pid28006

Open the program editor (inside the virtual calculator -- press: [Shift][1], select Complex (App) and press [Enter]), delete the contents with [Shift][Esc], then in the emulator's program menu at the top of the program window, select Edit > Paste)

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-02-2015, 05:50 PM (This post was last modified: 04-02-2015 07:18 PM by salvomic.)
Post: #37
RE: Complex Plotting App
(04-02-2015 05:40 PM)Han Wrote:  There is no need for the connectivity kit. Just directly paste it into the virtual calculator. Copy the code from:

http://www.hpmuseum.org/forum/thread-275...l#pid28006

Open the program editor (inside the virtual calculator -- press: [Shift][1], select Complex (App) and press [Enter]), delete the contents with [Shift][Esc], then in the emulator's program menu at the top of the program window, select Edit > Paste)

ok Han,
but also doing so, I cannot see the options in Plot Setup (X min/max, Y min/max, pixel box size, contour/magmitude mask resolution, Coloring scheme, contour grid on/off).
Then with Program editor I get "error in line 268" both in Emulator and Prime (I copied also there)...

EDIT: found the error:
pasting, the line
Code:
//Domain Coloring
    IF coloring==3 THEN
      return RGB(MIN(255,LN(1+ABS(IM(v)))*128),MIN(255,LN(1+ABS(RE(v)))*128),MIN(255,MAX​​(0,(LN(1+ABS(v))-2)*128)));
    END;
was copied with "MAX (0)" containing a space; deleting the space the options for Plot Setup are ok and no error indicated by Program...
I don't know why, but this happened both in Emulator and in Prime...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-04-2015, 03:03 PM
Post: #38
RE: Complex Plotting App
(04-02-2015 12:10 PM)Han Wrote:  
(04-02-2015 02:58 AM)Eddie W. Shore Wrote:  I am still having trouble, for the the example X^3, I just get the curve as if I was just using the Function App. I am using emulator version 6975. I tried pasting several codes and can't get the app to work properly.

Please advise.

In the virtual calc, copy the Function app and save it as Complex. Activate the Complex app. Paste the code for the app into the Complex (App) source file listed in the Program Catalog. If all went well, then you should be able to plot, now.

I finally got it to work. When I first posted the code, I clicked on (Debug) and led me to a syntax error, which was easily corrected: the space between MAX and (0 had to be deleted in...

"IF coloring==3 THEN return RGB(MIN( ... *128),MIN(255,MAX (0,(LN(1+ABS(v))-2)*128))..."

Once that was corrected, the app runs fine now. Smile I copied the latest version. Appreciate your help everyone!


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2017, 07:28 PM (This post was last modified: 03-18-2017 03:07 AM by Han.)
Post: #39
RE: Complex Plotting App
EDIT: Update again if you downloaded while the download count was 11 or lower. Fixed a minor bug in the evaluation of the complex function. Should now plot without issues. Use same link to update. Also added pragma statement.

Graph of \( \displaystyle \frac{(X-i)^3}{X+1.001} \)

[Image: attachment.php?aid=4593]

Updated into a full app distribution (this should take care of some Unicode issues mentioned in previous posts).

To install, run the connectivity kit and connect the calculator (or virtual calculator) to the connectivity kit. Then simply drag the hpappdir folder into the desired calculator.


.zip  complexplot.zip (Size: 8.21 KB / Downloads: 47)


Attached File(s) Thumbnail(s)
   

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
06-30-2017, 03:48 AM
Post: #40
RE: Complex Plotting App
The current version fails to render transcendental functions with the default CAS settings. In particular, if both the “Exact” and “Integers” (“Change apparent integers into exact integers”) flags are set, CAS evaluation of cplxF returns Function (TYPE(…) == 8) objects instead of numbers for (Gaussian) integer inputs in cases where it cannot return an exact numerical answer, leading to invalid tests like “k>1” for k = ABS(RE(SIN(-4+3*i)))/0.01.

While this can be easily fixed by inserting evalf or approx into the CAS call, I’m curious, as an essentially clueless Prime programmer*, why you’re building and calling a CAS function in the first place, given that, in my cursory testing at least, the original non-CAS function works fine and plots slightly (~20%) faster.

Oh, and I almost forgot to mention…thanks for the program! I had just finished whipping up some plots in Mathematica to explain the multivalued complex cube root to a coworker when I found it, and, while the graphical output of Mathematica on a 34" display is objectively hard to top in QVGA, this particular coworker is exactly the sort of person (like me!) who’ll nevertheless get a kick out of the fact that a $150 calculator can do this sort of thing without smoke, mirrors, or low-level programming.

* While I am a long-time HP calculator user and (non-calculator) programmer by trade, yours is the very first program I’ve read or edited on this new Prime I’ve spent all of eight hours or so fooling around with.
Find all posts by this user
Quote this message in a reply
Post Reply 




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