# 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.

Code:
``` #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; PlotRes(r); EXPORT Plot() BEGIN LOCAL mymouse,mykey,entr,x,y;  entr:=Entry; Entry:=1; // avoid textbook entry interpretation of fX  IF input(     { {fX,  [2],{10,90,0}},       {xmin,[0],{30,15,1}},       {xmax,[0],{80,15,1}},       {ymin,[0],{30,15,2}},       {ymax,[0],{80,15,2}},       {rmin,[0],{30,15,3}},       {rmax,[0],{80,15,3}},       {imin,[0],{30,15,4}},       {imax,[0],{80,15,4}},       {amin,[0],{30,15,5}}     },     "Complex Plot Setup",     {       "f(X)",       "Xmin=", "Xmax=",       "Ymin=", "Ymax=",       "REmin", "REmax",       "IMmin", "IMmax",        "min|f(X)|"     },     { "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"      } )  THEN     RECT();   fxiy:=replace(fX,"X","(xmin+dx*x + *(ymax-dy*y))");   dx   :=(xmax-xmin)/320;   dy   :=(ymax-ymin)/240;   dreal:=255/(rmax-rmin);   dimag:=255/(imax-imin);   dabs :=255/(amin);   PlotRes(16);   // PlotRes(8);   PlotRes(4);   //PlotRes(2);   //PlotRes(1);   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   WHILE 1 DO    mymouse:= mouse();    mykey:=getkey();     IF size(mymouse(1)) OR mykey≠−1 then // mouse activ     INVERT_P(G0, x-1,y-1,x+1,y+1); // revert previous mark     CASE       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);       END;     END;     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;   END; // while  END; // input  Entry:=entr; END; LOCAL PlotRes(r) BEGIN 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  );    CASE     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) ) );     END;     DEFAULT      color:=RGB( MIN( 255, MAX(0, (  IM( CAS(EVAL(fxiy)) )-imin  )*dimag) ),                  0,                  MIN( 255, MAX(0, (  RE( CAS(EVAL(fxiy)) )-rmin  )*dreal) ) );    END;    RECT_P(G0,x,y,x+r-1,y+r-1,color);    IF ISKEYDOWN(4) THEN RETURN; END;   END;  END; END;```

[attachment=7959]
Pages: 1 2 3
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :