Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are replies submitted by Doug Meade

The rand command has been updated and upgraded with the introduction of the RandomTools package. You really should check it out.

Here's how I would approach your problem. The general idea is similar to Thomas Unger's. In my implementation, the arguments to the procedure are the number of distinct elements and the set from which they are to be chosen. This needs some checking to be sure the set has enough elements to choose n unique members, otherwise it would be an infinite loop.  You can do that for yourself (or ask again if you need more help). Anyway, here's my code and a couple of examples:

f := proc( n, S )
  uses RandomTools;
  local A;
  A := Generate( set(choose(S),n) );
  while nops(A)<n do
    A := A union Generate( set(choose(S minus A), 8-nops(A) ) )
  end do;
  return A;
end proc:
f(8,{$1..2^4});
                        {4, 6, 8, 10, 11, 13, 14, 15}
f( 3, {red,blue,green,brown,yellow,gold,bronze,silver,orange} );
                             {red, blue, green}

I hope this is helpful,

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I know of no way to have a Maple procedure return a "table" that looks like what appears at the end of your worksheet. This is a GUI table, not to be confused with a table data structure within Maple.

What you can do is the following.

  1. Create the table like you have already done.
  2. Now, replace the numerical values with a Text Area embedded component. (Right-click on the component and select Component Properties. Set the width to, say, 15 and the rows to 1. Note the Name - or change it to something meaningful to you. You will probably want to unclick Editable. You won't be able to set the background to blend in with the rest of the table.)
  3. Next, write a procedure that computes the values that need to be displayed in this table. Instead of returning these values, your procedure will update the components you created in the previous step. The generic way in which you will do this is:
use DocumentTools in
  Do( TextArea0 = computed_value0 );
  Do( TextArea1 = computed_value1 );
  ...
end use;

To call the procedure to update the table, I might suggest putting a Button component next to the table.Give the button the caption "Update Table" or something more informative - or select an image to display on the button. Set the Action When Clicked to be a call to your procedure. (You can delete everything else from that window; there should be no need for DocumentTools here.) A slight variation on this is to put all of the code for the procedure directly in the Action When Clicked area for the button. Then you will need the DocumentTools skeleton that is provided. I prefer to use the proc because it gives me an easier way to manage the code. (You can hide the proc in a Code Edit Region (under the Insert menu) or as Startup Code (click the icon to the left of the smallest magnifying glass).

I hope this is helpful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

I agree that the context menus are the easiest way to customize a plot, but I wish there was a way to get Maple to return the command needed to (re)produce the plot from the command line. This seems like it should not be too difficult to achieve. What are the chances it could appear in the near future?

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I agree that the context menus are the easiest way to customize a plot, but I wish there was a way to get Maple to return the command needed to (re)produce the plot from the command line. This seems like it should not be too difficult to achieve. What are the chances it could appear in the near future?

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I did not pay enough attention to catch this. You are correct, and I understand why Maple did this. Maybe the typeset option should be modified to prevent automatic simplification of its arguments.

For this example, I avoided this problem by putting cos in single quotes, 'cos'. While this prevented the automatic simplificaiton it did not affect the typesetting of the fractions. For that, you need Robert's solution.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I did not pay enough attention to catch this. You are correct, and I understand why Maple did this. Maybe the typeset option should be modified to prevent automatic simplification of its arguments.

For this example, I avoided this problem by putting cos in single quotes, 'cos'. While this prevented the automatic simplificaiton it did not affect the typesetting of the fractions. For that, you need Robert's solution.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

The following are all interpretted as the same range:

0..1
0...1
0....1

If you want the range with right endpoint 0.1 you could use

0.. 0.1
0.. .1
0... .1

Believe it or not, this is documented. See ?range where you will find, among other information:

Note that more than two dots in succession are also parsed as the range (`..`) operator.

Interesting!

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

The following are all interpretted as the same range:

0..1
0...1
0....1

If you want the range with right endpoint 0.1 you could use

0.. 0.1
0.. .1
0... .1

Believe it or not, this is documented. See ?range where you will find, among other information:

Note that more than two dots in succession are also parsed as the range (`..`) operator.

Interesting!

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

All Joe is telling you is that putting "with(plots):" inside a Maple procedure does not do what you want it to do.

The help for "with" tells us that

The with(package) calling sequence makes the short form names of the commands of a Maple package available at the interactive level.

and

The with command is effective only at the top level, and intended primarily for interactive use. Because with operates by using lexical scoping, it does not work inside the bodies of procedures, module definitions, or within statements. See the examples at the end of this help topic.

See, in particular, the underlined phrases.

Joe's suggestion is to use the "long-form" of the command name. This can be either plots:-display or plots[display] . Joe suggested the former; I tend to prefer using the latter. There is a technical difference between the two forms, but that's terribly important right now. (See the UsingPackages help page for a complete description.)

The other thing I'd like to add is that Maple procedures accept an optional uses clause that is a nice replacement for with and allows you to use the short form of the command name. Here's a quick example:

myPlot := proc()
  uses plots;
  display( ...)
end proc;

In other words, just replace the with(plots) with uses plots (at the very top of the procedure definition. Note that  you can put several packages in a single uses option. For a complete description of this feature, see the help page for "procedure" (?procedure).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

All Joe is telling you is that putting "with(plots):" inside a Maple procedure does not do what you want it to do.

The help for "with" tells us that

The with(package) calling sequence makes the short form names of the commands of a Maple package available at the interactive level.

and

The with command is effective only at the top level, and intended primarily for interactive use. Because with operates by using lexical scoping, it does not work inside the bodies of procedures, module definitions, or within statements. See the examples at the end of this help topic.

See, in particular, the underlined phrases.

Joe's suggestion is to use the "long-form" of the command name. This can be either plots:-display or plots[display] . Joe suggested the former; I tend to prefer using the latter. There is a technical difference between the two forms, but that's terribly important right now. (See the UsingPackages help page for a complete description.)

The other thing I'd like to add is that Maple procedures accept an optional uses clause that is a nice replacement for with and allows you to use the short form of the command name. Here's a quick example:

myPlot := proc()
  uses plots;
  display( ...)
end proc;

In other words, just replace the with(plots) with uses plots (at the very top of the procedure definition. Note that  you can put several packages in a single uses option. For a complete description of this feature, see the help page for "procedure" (?procedure).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Here's another way to achieve this result, using only the plot command and its options.

plot( sin(x), x=-15..15, xtickmarks=spacing(Pi/2) );
plot( sin(x), x=-15..15, tickmarks=[spacing(Pi/2),default] );
plot( sin(x), x=-15..15,
      tickmarks=[spacing(Pi/2),[-sqrt(3)/2,-sqrt(2)/2,-1/2,0,1/2,sqrt(2)/2,sqrt(3)/2]] );

The plot command received a number of new options that provide users with greatly improved tools for creating nice plots. In addition to tickmarks (and xtickmarks and ytickmarks), you should take a look at the axis and typesetting options. Each of these has its own help page:

?plot,tickmarks
?plot,axis
?plot,typesetting

I hope this gives you some new and useful tools.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Here's another way to achieve this result, using only the plot command and its options.

plot( sin(x), x=-15..15, xtickmarks=spacing(Pi/2) );
plot( sin(x), x=-15..15, tickmarks=[spacing(Pi/2),default] );
plot( sin(x), x=-15..15,
      tickmarks=[spacing(Pi/2),[-sqrt(3)/2,-sqrt(2)/2,-1/2,0,1/2,sqrt(2)/2,sqrt(3)/2]] );

The plot command received a number of new options that provide users with greatly improved tools for creating nice plots. In addition to tickmarks (and xtickmarks and ytickmarks), you should take a look at the axis and typesetting options. Each of these has its own help page:

?plot,tickmarks
?plot,axis
?plot,typesetting

I hope this gives you some new and useful tools.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

You're making nice progress. I think you might do better using Tally from the Statistics package. For example:

with( Statistics ):
compareCount := (a,b)->rhs(a)>rhs(b):
for k from 1 to 10 do
  rolls := ['rand(1..6)'()$5];
  keep := select( `=`, rolls, lhs(sort( Tally(rolls), compareCount )[1]) );
end do;
                               [3, 2, 4, 2, 1]
                                   [2, 2]
                               [5, 1, 4, 4, 5]
                                   [4, 4]
                               [3, 2, 1, 2, 4]
                                   [2, 2]
                               [5, 3, 4, 1, 1]
                                   [1, 1]
                               [1, 2, 2, 3, 4]
                                   [2, 2]
                               [5, 1, 6, 4, 1]
                                   [1, 1]
                               [2, 1, 5, 1, 1]
                                  [1, 1, 1]
                               [4, 3, 5, 4, 6]
                                   [4, 4]
                               [4, 4, 2, 2, 2]
                                  [2, 2, 2]
                               [3, 5, 5, 4, 3]
                                   [5, 5]

Doug

P.S. I "flagged" your extra posts so that the administrators can clean up this topic.

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

You're making nice progress. I think you might do better using Tally from the Statistics package. For example:

with( Statistics ):
compareCount := (a,b)->rhs(a)>rhs(b):
for k from 1 to 10 do
  rolls := ['rand(1..6)'()$5];
  keep := select( `=`, rolls, lhs(sort( Tally(rolls), compareCount )[1]) );
end do;
                               [3, 2, 4, 2, 1]
                                   [2, 2]
                               [5, 1, 4, 4, 5]
                                   [4, 4]
                               [3, 2, 1, 2, 4]
                                   [2, 2]
                               [5, 3, 4, 1, 1]
                                   [1, 1]
                               [1, 2, 2, 3, 4]
                                   [2, 2]
                               [5, 1, 6, 4, 1]
                                   [1, 1]
                               [2, 1, 5, 1, 1]
                                  [1, 1, 1]
                               [4, 3, 5, 4, 6]
                                   [4, 4]
                               [4, 4, 2, 2, 2]
                                  [2, 2, 2]
                               [3, 5, 5, 4, 3]
                                   [5, 5]

Doug

P.S. I "flagged" your extra posts so that the administrators can clean up this topic.

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

The linalg package has been replaced by the LinearAlgebra package. This will work nicely with VectorCalculus.

with( LinearAlgebra ):
with( VectorCalculus ):
M := RandomMatrix(3,3)/100.:
V := t -> <t^2, 3*t, t^3>;
v := unapply( M.V(t), t ):

a := D(v):
a(t);
a(5);

Note the improved syntax for matrix multiplication that is available with LinearAlgebra.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed
First 33 34 35 36 37 38 39 Last Page 35 of 76