HP Forums

Full Version: Complex Plotting App
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(06-30-2017 03:48 AM)jtm Wrote: [ -> ]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.

I'm not sure what you mean by "CAS call" -- I believe that the entire program/app uses only non-CAS commands. (However, it has been a while and I have yet to refer to the code.)
My personal 3D color view skills have problems interpreting complex function characteristics from the domain coloring scheme. Therefore, I played around with one imaginary and one real color intensity mapped directly linear to a given value range. Additionally the RGB color scheme is changed from ABS related black/white to real/imaginary related blue/red combination for values above a threshold value 'amin':
  • ABS(f(X)) < amin:
    white..black #000000..#FFFFFF = ABS(f(X)) 0 ...amin
  • ABS(f(X)) > amin:
    red #0000xx..#FF00xx = IM(f(X)) ymin...ymax
    blue #xx0000..#xx00FF = RE(f(X)) xmin...xmax
    black #000000 = IM(f(X)) < ymin and RE(f(X)) < xmin
    magenta #FF00FF = IM(f(X)) > ymax and RE(f(X)) > xmax
Axis and value display by tap and movement is added to the output graph. Below the code tested with Virtual Calculator 2.1.14181 (2018 10 16) on win 8 and 2.1.14294 (2019 10 25) on Android 7.1. Maybe useful for some of you.


#pragma mode( separator(.,;) integer(h-32) )

//EXPORT fX:="X^3"; // X gets x+i*y
//EXPORT xmin:=-5, xmax:=5, ymin:= −5, ymax:=5;
//EXPORT rmin:=-100, rmax:=350, imin:=-100, imax:=100;

//EXPORT fX:="Zeta(X)";
//EXPORT xmin:=−2, xmax:=1, ymin:=−4, ymax:=24;
//EXPORT rmin:=-4, rmax:=6, imin:=-4, imax:=6;

EXPORT fX:="(X+2)^2*(X-1-2*)*(X+)";
EXPORT xmin:=−4, xmax:=4, ymin:=−3, ymax:=3;
EXPORT rmin:=-100, rmax:=100, imin:=-100, imax:=100;

EXPORT amin:=0.1;
LOCAL  fxiy:=replace(fX,"X","(xmin+xi*x + *(ymax-yi*y))");
LOCAL  dx, dy, dreal, dimag, dabs;


LOCAL mymouse,mykey,entr,x,y;

 entr:=Entry; Entry:=1; // avoid textbook entry interpretation of fX
 IF input(
    { {fX,  [2],{10,90,0}},
    "Complex Plot Setup",
      "Xmin=", "Xmax=",
      "Ymin=", "Ymax=",
      "REmin", "REmax",
      "IMmin", "IMmax", 
    { "Enter function (X as independant)",
      "Enter minimum horizontal value",
      "Enter maximum horizontal value",
      "Enter minimum vertical value",
      "Enter maximum vertical value",
      "Enter minimum real f(X) value",
      "Enter maximum real f(X) value",
      "Enter minimum imaginary f(X) value",
      "Enter maximum imaginary f(X) value",
      "Switch from BlackWhite ABS to RedBlue IM/RE"
     } )
  fxiy:=replace(fX,"X","(xmin+dx*x + *(ymax-dy*y))");
  dx   :=(xmax-xmin)/320;
  dy   :=(ymax-ymin)/240;
  dabs :=255/(amin);

  // PlotRes(8);

  LINE_P(G0, 320/(xmin-xmax)*xmin, 0, 320/(xmin-xmax)*xmin, 240, #0); // y axis 
  LINE_P(G0, 0, 240/(ymax-ymin)*ymax, 320, 240/(ymax-ymin)*ymax, #0); // x axis

  TEXTOUT_P(" ESC to cancel. Tap + directional pad to show values.                  ",G0,0,0,2, #0h,500,#FFFFFF);
  // black text shadow ...
  TEXTOUT_P(xmin+","+ymax, G0,                              0+1,     13+1, 1, #0);
  TEXTOUT_P(xmin+","+ymin, G0,                              0+1, 240-10+1, 1, #0);
  TEXTOUT_P(xmax+","+ymax, G0, 320-size(str(xmax+","+ymax))*4+1,     13+1, 1, #0);
  TEXTOUT_P(xmax+","+ymin, G0, 320-size(str(xmax+","+ymin))*4+1, 240-10+1, 1, #0);
  // ... and white text to sign (x,y) edge values
  TEXTOUT_P(xmin+","+ymax, G0,                              0  ,     13  , 1, #FFFFFF);
  TEXTOUT_P(xmin+","+ymin, G0,                              0  , 240-10  , 1, #FFFFFF);
  TEXTOUT_P(xmax+","+ymax, G0, 320-size(str(xmax+","+ymax))*4  ,     13  , 1, #FFFFFF);
  TEXTOUT_P(xmax+","+ymin, G0, 320-size(str(xmax+","+ymin))*4  , 240-10  , 1, #FFFFFF);

  x:=−3; y:=-3; // avoid 1st inversion by position out of screen
   mymouse:= mouse();
   IF size(mymouse(1)) OR mykey≠−1 then // mouse activ
    INVERT_P(G0, x-1,y-1,x+1,y+1); // revert previous mark
     IF mykey== 2 THEN y := y-2; END; // up
     IF mykey==12 THEN y := y+2; END; // down
     IF mykey== 7 THEN x := x-2; END; // left
     IF mykey== 8 THEN x := x+2; END; // right
     IF mykey== 4 THEN RETURN; END; // esc
     IF mykey==-1 THEN // no key thus we arrived here by a tap
      x := mymouse(1,1);
      y := mymouse(1,2); 
    TEXTOUT_P(" ESC to cancel.    f (  "+TRUNCATE(xmin+dx*x + *(ymax-dy*y),-3)+"   ) =   "+
                                         TRUNCATE( CAS(EVAL(fxiy)),-3 )+"          ",
              G0,0,0,2, #0h,500,#FFFFFFh  );
    INVERT_P(G0, x-1,y-1,x+1,y+1); // mark by color inversion
  END; // while
 END; // input

LOCAL PlotRes(r)
LOCAL x,y,color;

 FOR x FROM 0 TO 320-r STEP r DO
  FOR y FROM 0 TO 240-r STEP r DO
   TEXTOUT_P(" ESC to cancel. Plot col "+x+"/320, row "+y+"/240, resolution "+r+".                  ", G0,0,0,2, #0h,500,#FFFFFFh  );
    IF ( ABS( CAS(EVAL( fxiy )) ) < amin ) THEN
     color:=RGB( MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ),
                 MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ),
                 MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ) );
     color:=RGB( MIN( 255, MAX(0, (  IM( CAS(EVAL(fxiy)) )-imin  )*dimag) ),
                 MIN( 255, MAX(0, (  RE( CAS(EVAL(fxiy)) )-rmin  )*dreal) ) );

Pages: 1 2 3
Reference URL's