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

Does anyone have a "Ten More Maple Errors" list?

If so, I propose including confusion between sum and add. This topic has come up several times on MaplePrimes, most recently (today) in the forum titled sum(...) doesn't seem to like values from a Matrix, why?.

If I could search MaplePrimes without destroying this partial post, I would search for other instances of this on MaplePrimes.

Instead of Top Ten lists, would it be more appropriate to start a FAQ on the student side of MaplePrimes? I could create a book page, but how many new users would think to look at a "book page" for a FAQ? It deserves more prominent location. This, I believe, requires some administrative intervention.

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/~meade/

Thanks, John, for starting a separate forum on this topic.

I, too, have found the new editor to make it more difficult for me to post on MaplePrimes. There have been some instances where I simply did not make a post because I did not want to fight the editor to present the information I wanted to contribute.

As it is, I rarely include Maple output in my posts. I wish it was easy to paste material from a worksheet into a post as an image. This would help with matrices, plots, etc.

John, congratulations on your impending transition to a red leaf!

---------------------------------------------------------------------
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/~meade/

First, I want to say I like the new MaplePrimes. Maintaining this site must keep Will on his toes. (I bet it's also a lot of fun.)

The new editor is not fun - at least for me. I have not been able to get past the crazy behavior when I try to backspace. Maybe I need to use the buttons more but, as I have said in other forums, I like to keep my hands on the keyboard.

So, I tend to enter my posts in source mode.

Has anyone else been annoyed, or even noticed, that after you preview a post written in source mode that the editor changes the source? I think it is mainly trying to ensure that the source fits into a default style. For example, it adds paragraph tags and changes the ordered and unordered lists.

If the changes did not change the content or appearance of the post, then there is no real problem. But, the appearance does change (sometimes). And, the careful formatting of my input (indentations, ...) are lost.

Is there a way to prevent the editor from making changes to my source?

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/~meade/

Here's another example of what I consider to be wrong with 2D Math Input.

The Accessing solutions from procedures forum topic refers readers to a worksheet .

This worksheet was prepared with 2D Math Input.

The procedure uses the name "beta_star". But, if I type this sequence of characters, I see βstar. If I want to get "beta_star" in the code, I have to type "beta\_star" (the _ must be escaped).

I know this has been discussed before, but I want to point this out as another example of nice looking results from 2D Math Input that require non-intuitive knowledge on the part of the user.

Personally, I would rather have slightly less attractive code that does not require any tricks to enter.

Just more of my opinions, 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/~meade/

 

Here's another example of what I consider to be wrong with 2D Math Input.

The Accessing solutions from procedures forum topic refers readers to a worksheet .

This worksheet was prepared with 2D Math Input.

The procedure uses the name "beta_star". But, if I type this sequence of characters, I see βstar. If I want to get "beta_star" in the code, I have to type "beta\_star" (the _ must be escaped).

I know this has been discussed before, but I want to point this out as another example of nice looking results from 2D Math Input that require non-intuitive knowledge on the part of the user.

Personally, I would rather have slightly less attractive code that does not require any tricks to enter.

Just more of my opinions, 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/~meade/

 

I have five computers that I use at different times:

  • an old desktop that has a CD drive
  • a new(er) desktop with a DVD drive
  • a laptop with a DVD drive
  • a tablet with neither a CD nor a DVD drive (this can be a real pain!)
  • an older laptop with a DVD drive, but a bad wireless card

I am not bragging, but I did not know how to respond to the poll other than "Other

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/~meade/

The contours= option specifies the heights (z) to be drawn on the plot. I do not know why these four curves were selected, but this should not have any connection with the location of the critical points of f. If you wanted to ensure the critical points were highlighted on the contourplot, I would use

contourplot( f, x=-2..2, y=-2..1, color=red, contours=[ f(0,-1), f(3/4,-7/16) ] );

But, I see that you have not defined f as a function, so the function calls would need to be replaced by eval's. Here is how I would approach this problem:

with( plots ):
f:=x^3-3*x*y+2*y^2-3*x+4*y+3:
fx := diff( f, x );
                                  2          
                               3 x  - 3 y - 3
fy := diff( f, y );
                               -3 x + 4 y + 4
cp := solve( [fx=0,fy=0], [x,y] );
                     [                 [    3      -7]]
                     [[x = 0, y = -1], [x = -, y = --]]
                     [                 [    4      16]]


p1 := contourplot( f, x=-2..2, y=-2..1, contours=10 ):
p2 := contourplot( f, x=-2..2, y=-2..1, contours=[seq(eval(f,p),p=cp)], color=pink, grid=[51,51] ):
display( p1,p2 );

The first contoutplot shows the general shape of the function. The second highlights the two level curves that contain the critical points. The grid= option helps to smooth out these curves, but even with grid=[350,350] Maple did not find the single point at (3/4,-7/16). You should also know about the contourplot3d command. The syntax is the same but the output is a 3D plot - the contours are displayed at their height on the surface. This can be useful in some situations. See ?contourplot for information about both commands. 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/~meade/

The contours= option specifies the heights (z) to be drawn on the plot. I do not know why these four curves were selected, but this should not have any connection with the location of the critical points of f. If you wanted to ensure the critical points were highlighted on the contourplot, I would use

contourplot( f, x=-2..2, y=-2..1, color=red, contours=[ f(0,-1), f(3/4,-7/16) ] );

But, I see that you have not defined f as a function, so the function calls would need to be replaced by eval's. Here is how I would approach this problem:

with( plots ):
f:=x^3-3*x*y+2*y^2-3*x+4*y+3:
fx := diff( f, x );
                                  2          
                               3 x  - 3 y - 3
fy := diff( f, y );
                               -3 x + 4 y + 4
cp := solve( [fx=0,fy=0], [x,y] );
                     [                 [    3      -7]]
                     [[x = 0, y = -1], [x = -, y = --]]
                     [                 [    4      16]]


p1 := contourplot( f, x=-2..2, y=-2..1, contours=10 ):
p2 := contourplot( f, x=-2..2, y=-2..1, contours=[seq(eval(f,p),p=cp)], color=pink, grid=[51,51] ):
display( p1,p2 );

The first contoutplot shows the general shape of the function. The second highlights the two level curves that contain the critical points. The grid= option helps to smooth out these curves, but even with grid=[350,350] Maple did not find the single point at (3/4,-7/16). You should also know about the contourplot3d command. The syntax is the same but the output is a 3D plot - the contours are displayed at their height on the surface. This can be useful in some situations. See ?contourplot for information about both commands. 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/~meade/
Disclaimer: when I first ran the original code, my variations showed sequentially faster compute times. When I went back for clean runs before creating this post, the improvements dropped from 50% to only 5% (or less). The lower improvements are, now, reproducible. So, these ideas are not as good as I first thought they would be. Still, I hope they are of interest to someone. Original Code (cleaned up)
restart;
with(Statistics):
lpmr := proc (lambda, phi, alpha, N)
  local X, Y, i, r;
  X[0] := 1; Y[0] := 1;
  r := i->Sample(RandomVariable(Poisson(X[i])), 1)[1];
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := r(i)
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc:
t := time(); lpmr(1, .5, .25, 3000): time()-t;
                                   123.684
                                    6.265
First Iteration: move package load into proc, declare X and Y as arrays (pre-allocates this space)
restart;
lpmr2 := proc (lambda, phi, alpha, N)
  local X, Y, i, r;
  uses Statistics;
  X := Array( 0..N );
  Y := Array( 0..N );
  X[0] := 1; Y[0] := 1;
  r := i-> Sample(RandomVariable(Poisson(X[i])),1)[1];
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := r(i)
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc:
t := time(); lpmr2(1, .5, .25, 3000): time()-t;
                                   130.232
                                    6.203
Second Iteration: move code for inner proc (r) into inner loop
restart;
lpmr3 := proc (lambda, phi, alpha, N)
  local X, Y, i;
  uses Statistics;
  X := Array( 0..N );
  Y := Array( 0..N );
  X[0] := 1; Y[0] := 1;
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := Sample(RandomVariable(Poisson(X[i])),1)[1]
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc;
proc(lambda, phi, alpha, N)  ...  end;
t := time(); lpmr3(1, .5, .25, 3000): time()-t;
                                   136.607
                                    6.266
Fourth Iteration: eliminate X array, use an array only for storing final numbers
restart;
lpmr4 := proc (lambda, phi, alpha, N)
  local x, y, Y, i;
  uses Statistics;
  Y := Array( 0..N );
  x := 1; y := 1;
  for i to N do
    x := lambda+phi*x+alpha*(y-x);
    y := Sample(RandomVariable(Poisson(x)),1)[1];
    Y[i] := floor(y);
  end do;
  convert( Y, list );
end proc;
t := time(); lpmr4(1, .5, .25, 3000): time()-t;
                                   189.231
                                    6.141
If I had the time, I would look at the Generate command in the RandomTools package to see if that could be used in this case.
---------------------------------------------------------------------
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/~meade/
Disclaimer: when I first ran the original code, my variations showed sequentially faster compute times. When I went back for clean runs before creating this post, the improvements dropped from 50% to only 5% (or less). The lower improvements are, now, reproducible. So, these ideas are not as good as I first thought they would be. Still, I hope they are of interest to someone. Original Code (cleaned up)
restart;
with(Statistics):
lpmr := proc (lambda, phi, alpha, N)
  local X, Y, i, r;
  X[0] := 1; Y[0] := 1;
  r := i->Sample(RandomVariable(Poisson(X[i])), 1)[1];
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := r(i)
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc:
t := time(); lpmr(1, .5, .25, 3000): time()-t;
                                   123.684
                                    6.265
First Iteration: move package load into proc, declare X and Y as arrays (pre-allocates this space)
restart;
lpmr2 := proc (lambda, phi, alpha, N)
  local X, Y, i, r;
  uses Statistics;
  X := Array( 0..N );
  Y := Array( 0..N );
  X[0] := 1; Y[0] := 1;
  r := i-> Sample(RandomVariable(Poisson(X[i])),1)[1];
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := r(i)
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc:
t := time(); lpmr2(1, .5, .25, 3000): time()-t;
                                   130.232
                                    6.203
Second Iteration: move code for inner proc (r) into inner loop
restart;
lpmr3 := proc (lambda, phi, alpha, N)
  local X, Y, i;
  uses Statistics;
  X := Array( 0..N );
  Y := Array( 0..N );
  X[0] := 1; Y[0] := 1;
  for i to N do
    X[i] := lambda+phi*X[i-1]+alpha*(Y[i-1]-X[i-1]);
    Y[i] := Sample(RandomVariable(Poisson(X[i])),1)[1]
  end do;
  map(floor, [seq(Y[i], i = 1 .. N)])
end proc;
proc(lambda, phi, alpha, N)  ...  end;
t := time(); lpmr3(1, .5, .25, 3000): time()-t;
                                   136.607
                                    6.266
Fourth Iteration: eliminate X array, use an array only for storing final numbers
restart;
lpmr4 := proc (lambda, phi, alpha, N)
  local x, y, Y, i;
  uses Statistics;
  Y := Array( 0..N );
  x := 1; y := 1;
  for i to N do
    x := lambda+phi*x+alpha*(y-x);
    y := Sample(RandomVariable(Poisson(x)),1)[1];
    Y[i] := floor(y);
  end do;
  convert( Y, list );
end proc;
t := time(); lpmr4(1, .5, .25, 3000): time()-t;
                                   189.231
                                    6.141
If I had the time, I would look at the Generate command in the RandomTools package to see if that could be used in this case.
---------------------------------------------------------------------
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/~meade/
I have restarted this discussion under the topic equations: what they are, what they are not, and what you can do with them 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/~meade/
I have restarted this discussion under the topic equations: what they are, what they are not, and what you can do with them 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/~meade/
One of the fundamental mathematical objects in Maple is the equation. 0=0 and 1=0 are two examples of equations. There are lots of things that can be done with an equation. In this case, the most obvious operation is to ask if the equations are true or false:
evalb( 0=0 );
                         true
evalb( 1=0 );
                         false
If the equation involves one or more indeterminates (variables), then another set of operations makes sense: solve, diff, assign, .... Bottom line: an equation is a mathematical object and Maple has lots of operations that can be applied to equations (assuming the operands are of appropriate types). 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/~meade/
One of the fundamental mathematical objects in Maple is the equation. 0=0 and 1=0 are two examples of equations. There are lots of things that can be done with an equation. In this case, the most obvious operation is to ask if the equations are true or false:
evalb( 0=0 );
                         true
evalb( 1=0 );
                         false
If the equation involves one or more indeterminates (variables), then another set of operations makes sense: solve, diff, assign, .... Bottom line: an equation is a mathematical object and Maple has lots of operations that can be applied to equations (assuming the operands are of appropriate types). 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/~meade/
Welcome to the world of floating-point arithmetic. I cannot completely analyze your situation because I do not know the exact functions you are considering. By default, Maple's floating-point numbers have 10 significant digits. If s(xi+h) and si(x) agree to many significant digits, then their difference will not have many (if any) significant digits. Divide this low-precision number by 2*h (=2*10^(-8) in your case) and you get a large number that may have very little relevance to the derivative that you are trying to compute. It's very likely you would get a better estimate to the derivative with a smaller value of h (one for which the floating-point cancellation would not be as severe). You will probably do well to follow your suggestion and replace these approximations to the derivative with the exact (symbolic) derivative. But, if you really do need to do floating-point arithmetic, you can increase the number of significant digits in Maple's calculations by increasing the value of Digits (see ?Digits). Remember: Digits is the number of significant digits Maple keeps track of; it is not the number of digits that are correct in the computed answer. It is not uncommon to have to set Digits to a value larger than the number of digits you hope to have in your answer. Many years ago I had a problem where I had to use Digits=50 just to get 3 digits of precision in my computed results. You might also see some improvements to take advantage of hardware floating-point arithmetic (see ?evalhf). 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/~meade/
First 50 51 52 53 54 55 56 Last Page 52 of 76