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:
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 |
|||
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. 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:
|
|||
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:
|
|||
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 |
|||
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.
|
|||
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 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 |
|||
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:
|
|||
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 |
|||
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 I opted to leave out the PIXON code since there was not much improvement and yet much larger code. Graph 3D | QPI | SolveSys |
|||
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). |
|||
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. 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 |
|||
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! 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. |
|||
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.). 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 |
|||
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 |
|||
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: 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 |
|||
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: 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 |
|||
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: 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 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 |
|||
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. 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. I copied the latest version. Appreciate your help everyone! |
|||
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} \) 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. complexplot.zip (Size: 8.21 KB / Downloads: 49) Graph 3D | QPI | SolveSys |
|||
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. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)