PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 300 days

MaplePrimes Activity


These are replies submitted by PatrickT

Joe, if you've got time for this, I have some questions related to StringTools:-RegSubs. Hints would be more than enough.

I'm tweaking the postscript file to get a different font types for the axis labels and for the tick labels. Essentially, a workaround for plotoptions = "font=[Times,roman,10],labelfont=[Times,italic,10]", which should but does not work. It's not a big deal, but I think it can be done with StringTools:-RegSubs. I couldn't find much help in the help pages.

Here is a typical problem. Replace this string:

(4) dup 0 stringbbox 452 exch sub exch pop 2582 exch m show
(x) dup 0 stringbbox 908 exch sub exch pop 3800 exch m show


by this string:

(4) dup 0 stringbbox 452 exch sub exch pop 2582 exch m show
(x) TickLabelFont dup 0 stringbbox 908 exch sub exch pop 3800 exch m show
AxisLabelFont

If the numbers were fixed, I would do this:

str := ST:-RegSubs("exch m show\n(x) dup 0 stringbbox 908 exch sub exch pop 3800 exch m show\n" = "exch m show\n(x) TickLabelFont dup 0 stringbbox 908 exch sub exch pop 3800 exch m show\nAxisLabelFont", str);

But the numbers will vary, so I want to read numbers like 0, 908, 3800 on the left-hand side of RegSubs(lhs=rhs,str) and copy them onto the rhs. I got as far as this:

str := ST:-RegSubs("exch m show\n(([a-z])) dup ([0-9]+) stringbbox ([0-9]+) exch sub exch pop ([0-9]+) exch m show\n" = sprintf("exch m show\n(%d) TickLabelFont dup %d stringbbox %d exch sub exch pop %d exch m show defaultFont\n", ?? ), str);

I'm not sure about ([a-z]) as a replacement for x, that's a wild guess.

I don't quite understand how to copy the numbers on the lhs, so I used %d as a placeholder.

In the string above (x) stands for the axis label 'x'. Can the code be made to work for any label, e.g. for something with several words and spaces, e.g.: (the x coordinate).

Another problem I came across is how to replace ORIENTATION(45.,45.,0) by ORIENTATION(45.,45.), since classic accepts only 2 arguments for ORIENTATION, so again lhs=ORIENTATION(([0-9]+),([0-9]+),([0-9]+)), rhs=ORIENTATION(%d,%d) or something like that...

And how about dealing with square brackets? I can't see any of these in the help pages. If you've got a link to doc, that'd be plenty.

RegSubs("\n medium setlinewidth\n [] 0 setdash" ... doesn't work because of the []

searching for something completely different, I chanced upon this, useful to know and have at hand.

the author:  Robert Israel,

http://www.math.ubc.ca/~israel/advisor/advisor6/leastroot.txt

searching for something completely different, I chanced upon this, useful to know and have at hand.

the author:  Robert Israel,

http://www.math.ubc.ca/~israel/advisor/advisor6/leastroot.txt

I don't seen an attachment, is it there? In any case, unless your code is several pages long it will be easier for everyone if you copy-paste the equations into the text window, in 1D maple input format, without the output. Also, state your Maple version, and which you use : Standard v. Classic GUI.

@Joe Riel 

I don't know why it didn't work ...

but, in any case, a much better approach is to use CleanPlot earlier in the process of plot creation ---- since the complete plot is made up of 50 CURVES and as many POINTS, this approach avoids carrying these huge plots in the worksheet memory. So I wrapped the call to plots:-odeplot with CleanPlot, with the result that the dirty plots were not saved --- typically 50 Arrays like Array(1...75,1..3,numeric entries) intead of Array(1...2000,1..3,non-numeric/numeric entries).

My problem has therefore been fixed, thanks to your procedure.

Interestingly (maybe), the procedure I had put together by adapting Robert's code doesn't work. I suspect it's because the order of the data is not preserved by one of my manipulations, with the result that the trajectories get a different color from that intended.

The plot cleaned with Joe's procedure, with the intended colours:

The plot cleaned with my lame effort, with the wrong colours:

Thanks so much Joe. You're a life saver!

If you're interested, I can post a minimal example of the code which generates these "dirty" plots. Just let me know.

 Edit: Just to clarify what I did (my comment above may be a little cryptic), something along the lines of:

50Trajectories :=
 seq( CleanPlot( plots:-odeplot
    ( Sol(p) # p is a parameter
    , [ x(t), y(t), z(t) ]
    , t = 0 .. 100
    , 'colour' = colormap(i) # some formula to select colors
    ) )
   , p = L[1 .. 50] # list of 50 different values for the parameter
 ) :

@Joe Riel 

I don't know why it didn't work ...

but, in any case, a much better approach is to use CleanPlot earlier in the process of plot creation ---- since the complete plot is made up of 50 CURVES and as many POINTS, this approach avoids carrying these huge plots in the worksheet memory. So I wrapped the call to plots:-odeplot with CleanPlot, with the result that the dirty plots were not saved --- typically 50 Arrays like Array(1...75,1..3,numeric entries) intead of Array(1...2000,1..3,non-numeric/numeric entries).

My problem has therefore been fixed, thanks to your procedure.

Interestingly (maybe), the procedure I had put together by adapting Robert's code doesn't work. I suspect it's because the order of the data is not preserved by one of my manipulations, with the result that the trajectories get a different color from that intended.

The plot cleaned with Joe's procedure, with the intended colours:

The plot cleaned with my lame effort, with the wrong colours:

Thanks so much Joe. You're a life saver!

If you're interested, I can post a minimal example of the code which generates these "dirty" plots. Just let me know.

 Edit: Just to clarify what I did (my comment above may be a little cryptic), something along the lines of:

50Trajectories :=
 seq( CleanPlot( plots:-odeplot
    ( Sol(p) # p is a parameter
    , [ x(t), y(t), z(t) ]
    , t = 0 .. 100
    , 'colour' = colormap(i) # some formula to select colors
    ) )
   , p = L[1 .. 50] # list of 50 different values for the parameter
 ) :

@Joe Riel 


Thanks Joe, once again, for your attentive ear.

And Merry Christmas!

I did a quick check that indeed your amended procedure works on my test plot. Nice.

In the meantime, I had adapted a procedure written by Robert Israel, for a related mapleprimes question I asked a few weeks ago. At the time I thought that just removing the undefined entry, I hadn't realized that it would break the plot because the information stored about the size of the Arrays/rtables would become incorrect. Thanks to your explanations at the beginning of this thread, I was able to adapt that piece of code to deal with the test plot.

All this is a wonderful learning experience for me.

SADLY, once again, I erred in testing with an oversimplified example. It turns out that the plot structure I'm dealing with is more involved, as it contains several trajectories like the one in the testplot, as well as some points too.

I will need to work a wee bit harder on this still. However, I'm confident that your code could be adapted. I think using seq() over the N CURVES should work... (but when's the last time my intuition was correct?)

Final thoughts: These ugly error-filled plots were created with dsolve and odeplot, doing nothing out of the ordinary except perhaps using the dsolve,events/halt feature. I venture to say that there is an inefficiency somewhere that would be worth fixing. Adding a few lines of code to clean the Arrays produced with dsolve would seem to be a worthwhile undertaking. I can upload the code which generates these hugely inefficient plot structures, if deemed worthwhile to the Maple development team.

I copy-paste below my effort followed by the monster plot stucture I need to clean (attached in a text file).

### adapted from an idea by Robert Israel
cleanrtablePlot := proc(p)
  local A,d,U;
  A := op([1,1],p);
  d := [rtable_dims(A)] ;
  U := remove(r -> hastype(A[op(subsop(1=r,d))],Non(numeric),'exclude_container'),[seq(i,i=d[1])]) ;
  return PLOT3D(CURVES( A[op(subsop(1=U,d))], args[2 ..-1] )) ;
end proc :

But neither your revised code nor my effort above work on the complicated plot structure I'm dealing with. For information, I copy the full plot structure below. I'd been reluctant to do that until now because it's so huge. But in the state of desparation I'm in now, I'd copy-paste my entire hard drive if I had to.


APPENDIX:
mapleprimes_tmp.txt

@Joe Riel 


Thanks Joe, once again, for your attentive ear.

And Merry Christmas!

I did a quick check that indeed your amended procedure works on my test plot. Nice.

In the meantime, I had adapted a procedure written by Robert Israel, for a related mapleprimes question I asked a few weeks ago. At the time I thought that just removing the undefined entry, I hadn't realized that it would break the plot because the information stored about the size of the Arrays/rtables would become incorrect. Thanks to your explanations at the beginning of this thread, I was able to adapt that piece of code to deal with the test plot.

All this is a wonderful learning experience for me.

SADLY, once again, I erred in testing with an oversimplified example. It turns out that the plot structure I'm dealing with is more involved, as it contains several trajectories like the one in the testplot, as well as some points too.

I will need to work a wee bit harder on this still. However, I'm confident that your code could be adapted. I think using seq() over the N CURVES should work... (but when's the last time my intuition was correct?)

Final thoughts: These ugly error-filled plots were created with dsolve and odeplot, doing nothing out of the ordinary except perhaps using the dsolve,events/halt feature. I venture to say that there is an inefficiency somewhere that would be worth fixing. Adding a few lines of code to clean the Arrays produced with dsolve would seem to be a worthwhile undertaking. I can upload the code which generates these hugely inefficient plot structures, if deemed worthwhile to the Maple development team.

I copy-paste below my effort followed by the monster plot stucture I need to clean (attached in a text file).

### adapted from an idea by Robert Israel
cleanrtablePlot := proc(p)
  local A,d,U;
  A := op([1,1],p);
  d := [rtable_dims(A)] ;
  U := remove(r -> hastype(A[op(subsop(1=r,d))],Non(numeric),'exclude_container'),[seq(i,i=d[1])]) ;
  return PLOT3D(CURVES( A[op(subsop(1=U,d))], args[2 ..-1] )) ;
end proc :

But neither your revised code nor my effort above work on the complicated plot structure I'm dealing with. For information, I copy the full plot structure below. I'd been reluctant to do that until now because it's so huge. But in the state of desparation I'm in now, I'd copy-paste my entire hard drive if I had to.


APPENDIX:
mapleprimes_tmp.txt

@Pseudomodo 

Thanks, that was instructive. I did get lost at some point half way.  ;-)

In Hungary, where it was invented, Rubik's cube was marketed as "the magic cube", according to wikipedia. What I meant by a magic Rubik cube is different, what I meant is exemplified in the image below (image from wikipedia commons).

I just made one an hour ago by sticking numbered stickers, keeping the original colours though (visual help). But how many such cubes can we create? and are there multiple solutions? (i.e. starting from the cube below, 6 magic faces each with the numbers 1 to 9 arranged to sum to 15, but with, if possible, different colours)...

Thanks Joe for extending a helping hand, I can't seem to get these plots cleaned up (Did you read the bit where I say that the size of these plots goes from 11,226,123 bytes to 1,356,683 after the HFloat(undefined) entries are removed?!). I did a quick check, but it seems that my plots do indeed use rtable structures, specifically PLOT3D(CURVES(Array, ...)).

The undefined entries doesn't bother Maple's plot:-display routine, but it does break cmaple's ability to create postscript plots.

I don't have time to try to fix this right now, but I plan to get back to it during the weekend. In the meantime, here's more information.

Here is an artificial example which recreates a "dirty" plot

### Create nice plot with CURVES structure
sys := diff(y(x), x) = z(x), diff(z(x), x) = y(x):
var := {y(x), z(x)}:
sol := dsolve({sys, y(0) = 0, z(0) = 1}, var, type = numeric, method = classical):
testodeplot3d := plots:-odeplot(sol, [x, y(x), z(x)], -4 .. 4, color = orange):
# plots:-display(testodeplot);

### Create fake bad plot with Curves structure
A := op([1,1],testodeplot3d):
B := Array(1..10, 1..3, fill = HFloat(undefined), datatype = float[8], order = C_order):
A[1..10] := B:
badodeplot3d := PLOT3D(CURVES(A)):

### Your Cleaning procedure
cleanPlot := proc(p)
  local L ;
  subsindets( p
    , 'list({numeric,undefined})'
    , L -> if hastype(L,'undefined') then NULL else L end if ) ;
end proc :

### Cleaning the bad plot doesn't work
cleanodeplot3d := cleanPlot(badodeplot3d):
#plots:-display(cleanodeplot3d);
op([1,1],cleanodeplot3d)[5..14]; # it's not been cleaned


Thanks Joe for extending a helping hand, I can't seem to get these plots cleaned up (Did you read the bit where I say that the size of these plots goes from 11,226,123 bytes to 1,356,683 after the HFloat(undefined) entries are removed?!). I did a quick check, but it seems that my plots do indeed use rtable structures, specifically PLOT3D(CURVES(Array, ...)).

The undefined entries doesn't bother Maple's plot:-display routine, but it does break cmaple's ability to create postscript plots.

I don't have time to try to fix this right now, but I plan to get back to it during the weekend. In the meantime, here's more information.

Here is an artificial example which recreates a "dirty" plot

### Create nice plot with CURVES structure
sys := diff(y(x), x) = z(x), diff(z(x), x) = y(x):
var := {y(x), z(x)}:
sol := dsolve({sys, y(0) = 0, z(0) = 1}, var, type = numeric, method = classical):
testodeplot3d := plots:-odeplot(sol, [x, y(x), z(x)], -4 .. 4, color = orange):
# plots:-display(testodeplot);

### Create fake bad plot with Curves structure
A := op([1,1],testodeplot3d):
B := Array(1..10, 1..3, fill = HFloat(undefined), datatype = float[8], order = C_order):
A[1..10] := B:
badodeplot3d := PLOT3D(CURVES(A)):

### Your Cleaning procedure
cleanPlot := proc(p)
  local L ;
  subsindets( p
    , 'list({numeric,undefined})'
    , L -> if hastype(L,'undefined') then NULL else L end if ) ;
end proc :

### Cleaning the bad plot doesn't work
cleanodeplot3d := cleanPlot(badodeplot3d):
#plots:-display(cleanodeplot3d);
op([1,1],cleanodeplot3d)[5..14]; # it's not been cleaned


As I was shopping for Christmas present, I came across several new versions of the Rubik's cube. My favourite is the 2X2X2 because that's the only one I can solve. The most popular version is, of course, the 3X3X3. 

Here is a picture of one I received as a gift as a child:

And apparently they now manufacture and sell (in a famous store whose name sounds like the name of a dinosaur) 4X4X4 and 5X5X5. The web informs me there are even 7X7X7. But anyways, the new Rubik puzzle that caught my attention is a 3X3X3 version with non-square shapes. I immediately got one:

I'm wondering, isn't this mathematically equivalent to the standard cube? As a child I had memorized algorithms to solve the 3X3X3. I've forgotten them now, but I can still complete 3X3X2 quite fast (but doesn't everyone?). But this one seems harder, surely just an illusion? Apart from the center pieces (I can't remember if they can be rotated) isn't there a unique way to "complete" the cube? If so, then, why is this new cube so much harder to solve? the absence of colors?

And then I thought about magic squares: if instead of having colors on each side you had numbers such that once completed the cube would have magic squares on each of the six sides? And sure enough, the idea has been implemented.

And then I thought about the Sudoku, which is related to the magic square. The standard Sudoku is an array of 9 (3X3) magic squares arranged in a 3X3 pattern. So that's 9 "sides" of a standard Rubik's cube, which has (obviously) only 6 sides.

I remembered Paul's recent post on the peg board puzzle http://www.mapleprimes.com/maplesoftblog/119099-Using-Maple-15-To-Solve-A-Peg-Board-Puzzle-Game and wondered whether the Rubik's cube and Sudoku had been studied with Maple. After a quick search I came across Joe's excellent post (I had no problem downloading the pdf document, which amazingly is still available after 6 years). But not a lot on the Rubik's cube.

It would be fun to have a section of mapleprimes devoted to mathematical games.

Is there anything mathematically interesting about the magic Rubik cube? I'm guessing that some versions would be easier to solve than the standard 6-coloured version if they have multiple solutions (can they?)

Just random thoughts as Christmas approaches and I shop for puzzles.

great explanation acer, in my view there's a strong case for adding your example to the help page,

http://www.maplesoft.com/support/help/Maple/view.aspx?path=Statistics/Quantile

It will not be obvious to the casual user that, to quote,

"By default, all computations involving random variables are performed symbolically (see option numeric below)."


I would guess that most statistics software do numerical computations by default.

great explanation acer, in my view there's a strong case for adding your example to the help page,

http://www.maplesoft.com/support/help/Maple/view.aspx?path=Statistics/Quantile

It will not be obvious to the casual user that, to quote,

"By default, all computations involving random variables are performed symbolically (see option numeric below)."


I would guess that most statistics software do numerical computations by default.

@samanthasumo,

I recommend you input your equations into a maple format and copy-paste them into the text window of a comment below. I also recommend that you use the worksheet format rather than the document format and that you use the 1D maple input format rather than 2D format. It will be a lot easier for you to copy-paste into mapleprimes. You can still have the output in the prettier 2D format, if you wish. These are options you set in Tools --> Options. Preferably input everything as an editable format, not as an image (sometimes when you copy-paste Maple worksheets you get an image, may happen if you copy-paste 1-line output, not usually if you copy-paste several lines of Maple output.

First 21 22 23 24 25 26 27 Last Page 23 of 93