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

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/
This is not the type of problem Maple is designed to do, particularly the step-by-step illustration of the verification. Here is one way in which this identity can be "verified" with Maple.
infolevel[all]:=10:
sec(u + t) = (cos(u)*cos(t)+sin(u)*sin(t))/(cos(u)^2-sin(t)^2);
                              cos(u) cos(t) + sin(u) sin(t)
                 sec(u + t) = -----------------------------
                                          2         2      
                                    cos(u)  - sin(t)       

simplify( lhs(%) ) = combine(rhs(%));
combine: combining with respect to trig
combine: combining with respect to cmbtms
combine: combining with respect to trig
combine: combining with respect to trig
combine: combining with respect to cmbpwr
combine: combining with respect to power
combine: combining with respect to power
combine: combining with respect to power
combine: combining with respect to power
combine: combining with respect to radical
combine: combining with respect to cmbpwr
combine: combining with respect to power
                          1           2 cos(-u + t)   
                      ---------- = -------------------
                      cos(u + t)   cos(2 u) + cos(2 t)

%*denom(lhs(%));
                            2 cos(u + t) cos(-u + t)
                        1 = ------------------------
                              cos(2 u) + cos(2 t)   

lhs(%) = combine( rhs(%) );
combine: combining with respect to trig
combine: combining with respect to cmbtms
combine: combining with respect to cmbpwr
combine: combining with respect to power
                                    1 = 1
The infolevel command tells Maple to give us a little more information about what it is doing (or trying). In this case, we only get minimal information from combine. It would be nice to get a little more information. I'm sure others will have more suggestions. Hopefully, at least one of our suggestions will be useful - even if it motivates you to write the procedure with the specific functionality that you seek. 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/
Let me add some details about the front lines on which I am fighting -- I mean, teaching. First, I am an old-timer who is most comfortable with my fingers on the keys. I can type. It slows me down to use the mouse or to use multi-key command sequences. While I admit to being an old-timer, I do not admit to be an old Doug who can't learn any new tricks. Second, it's not about me. All calculus students at the University of South Carolina spend one hour each week in the computer lab. I oversee the lab coordinators, who give detailed guidance to the TAs who actually meet the students. Most TAs have very limited (if any) prior exposure to Maple (or any mathematical software). So, we have to give the TAs simple, easy-to-learn skills and techniques that they can feel comfortable teaching to students less than one week after they first see them. I readily admit that document mode and 2D math input are more attractive than worksheets and Maple notation. The problems with document mode and 2D math input can be summarized with two statements:
  • actions and options can be very sensitive to the state from which they are initiated
  • there is no clear trace of exactly what was done to obtain a specific action.
Students do not have the mathematical sophistication to understand how small changes in the selection can lead to such large differences in the context menus produced. Students cannot see the instructor's hands and keyboard to know exactly what was done to enter something that leaves no trace. And, their attention is diverted from the presentation whenever they try something on their own - as they are instructed to do. Miss the wrong step in an interface-based construction and there is no hope of catching up! To me, the interface issues are not solved by creating more tutors and templates. While there is a place for tutors and templates, in the end they boil down to the equivalent of a button on a calculator -- they teach nothing about the mathematics. I want students to learn to use Maple as a powerful tool for solving problems. I want students to get a better understanding of the structure of the mathematics. I want students to have to formulate a sequence of steps that allows them to move (logically) from the given information to a solution. For all the stump speeches I've given lately you might think I had some political aspirations. (:-)) 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/
Let me add some details about the front lines on which I am fighting -- I mean, teaching. First, I am an old-timer who is most comfortable with my fingers on the keys. I can type. It slows me down to use the mouse or to use multi-key command sequences. While I admit to being an old-timer, I do not admit to be an old Doug who can't learn any new tricks. Second, it's not about me. All calculus students at the University of South Carolina spend one hour each week in the computer lab. I oversee the lab coordinators, who give detailed guidance to the TAs who actually meet the students. Most TAs have very limited (if any) prior exposure to Maple (or any mathematical software). So, we have to give the TAs simple, easy-to-learn skills and techniques that they can feel comfortable teaching to students less than one week after they first see them. I readily admit that document mode and 2D math input are more attractive than worksheets and Maple notation. The problems with document mode and 2D math input can be summarized with two statements:
  • actions and options can be very sensitive to the state from which they are initiated
  • there is no clear trace of exactly what was done to obtain a specific action.
Students do not have the mathematical sophistication to understand how small changes in the selection can lead to such large differences in the context menus produced. Students cannot see the instructor's hands and keyboard to know exactly what was done to enter something that leaves no trace. And, their attention is diverted from the presentation whenever they try something on their own - as they are instructed to do. Miss the wrong step in an interface-based construction and there is no hope of catching up! To me, the interface issues are not solved by creating more tutors and templates. While there is a place for tutors and templates, in the end they boil down to the equivalent of a button on a calculator -- they teach nothing about the mathematics. I want students to learn to use Maple as a powerful tool for solving problems. I want students to get a better understanding of the structure of the mathematics. I want students to have to formulate a sequence of steps that allows them to move (logically) from the given information to a solution. For all the stump speeches I've given lately you might think I had some political aspirations. (:-)) 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 can second all of Jacques' comments (not that he needs this). I would, however, like to point out one recent improvement to the Maple programming language. Jacques wrote
3. It is a good idea to use long names in a procedure rather than assuming that 'with' has been done. 'with' is useful for interactive use, but should be avoided when writing code.
Instead of using the long name, I like to use the "use" or "uses" features. You can ensure a package is available throughout a procedure with something like the following:
P := proc( ... )
       uses PackageName;
       ...
     end proc;
To make a package available for a specific block of code:
P := proc( ... )
       ...
       use PackageName in
         ...
       end use;
       ...
     end proc;
For example,
use plots in
  display( plot(sin), plot(tan), view=[DEFAULT,-10..10] );
end use;
The use ... end use form accepts more than a package name. You can give an expression sequence of assertions that are valid within the use ... end use block. For example
use `+`=`*`, `*`=`^` in
  3+2;
  3*3;
end use;
                                      9
                                     27
See the online help for use (?use) for a full explanation and more examples. 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 can second all of Jacques' comments (not that he needs this). I would, however, like to point out one recent improvement to the Maple programming language. Jacques wrote
3. It is a good idea to use long names in a procedure rather than assuming that 'with' has been done. 'with' is useful for interactive use, but should be avoided when writing code.
Instead of using the long name, I like to use the "use" or "uses" features. You can ensure a package is available throughout a procedure with something like the following:
P := proc( ... )
       uses PackageName;
       ...
     end proc;
To make a package available for a specific block of code:
P := proc( ... )
       ...
       use PackageName in
         ...
       end use;
       ...
     end proc;
For example,
use plots in
  display( plot(sin), plot(tan), view=[DEFAULT,-10..10] );
end use;
The use ... end use form accepts more than a package name. You can give an expression sequence of assertions that are valid within the use ... end use block. For example
use `+`=`*`, `*`=`^` in
  3+2;
  3*3;
end use;
                                      9
                                     27
See the online help for use (?use) for a full explanation and more examples. 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/
Did you look at the Wikipedia references I gave in an earlier post? These will give you some background on the Dirac distributions (they are NOT "functions" - they are not defined at 0). In particular, you will learn that int( f(t)*delta(t-tau), t=I ) = f(tau) when tau is in I, otherwise this integral is 0. This is what you are reporting with the different values of the integral. 0 is in (0-,infinity) but not in (0+,infinity). As for your question about discontinuous functions (f) with continuous antiderivatives (F). Let F(x)=abs(x) and define f=F'. More generally, form F(x) = piecewise( x<a, F1(x), x>a, F2(x) ) where F1(a-)=F2(a+) (to force continuity). Then f(x) = F'(x) = piecewise( x<a, F1'(x), x>a, F2'(x) )will be discontinuous at x=a unless F1'(a-)=F2'(a+). 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/
Did you look at the Wikipedia references I gave in an earlier post? These will give you some background on the Dirac distributions (they are NOT "functions" - they are not defined at 0). In particular, you will learn that int( f(t)*delta(t-tau), t=I ) = f(tau) when tau is in I, otherwise this integral is 0. This is what you are reporting with the different values of the integral. 0 is in (0-,infinity) but not in (0+,infinity). As for your question about discontinuous functions (f) with continuous antiderivatives (F). Let F(x)=abs(x) and define f=F'. More generally, form F(x) = piecewise( x<a, F1(x), x>a, F2(x) ) where F1(a-)=F2(a+) (to force continuity). Then f(x) = F'(x) = piecewise( x<a, F1'(x), x>a, F2'(x) )will be discontinuous at x=a unless F1'(a-)=F2'(a+). 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 is one possible solution to your problem. Basically, you want to keep only the terms that do not contain any indeterminates (variables) in an expression.
e1 := 2*x^2+4*y-6:
e2 := 2*x^2+4*y:
remove(has,e1,indets(e1,name));
                                     -6
remove(has,e2,indets(e2,name));
                                      0
Other solutions are possible with typematch. Maybe someone else can post some of these. 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 is one possible solution to your problem. Basically, you want to keep only the terms that do not contain any indeterminates (variables) in an expression.
e1 := 2*x^2+4*y-6:
e2 := 2*x^2+4*y:
remove(has,e1,indets(e1,name));
                                     -6
remove(has,e2,indets(e2,name));
                                      0
Other solutions are possible with typematch. Maybe someone else can post some of these. 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'll guess that the real question is that you don't like Maple's response when you give f a non-numeric argument:
f := proc(x)
  if x>0 then x else -x fi;
end proc:
f(-3);
                                      3
f(x);
Error, (in f) cannot determine if this expression is true or false: 0 < x
The problem here is that Maple can decide if x>0 only when x is numeric. In this type of situation you need to check if the argument is numeric before entering the body of the procedure. And, if you want, you can have Maple generate appropriate output. Here's one way to do this for your example:
f := proc(x)
  if x::numeric then
    if x>0 then x else -x end if;
  else
    nprintf("|%a|",x)
  fi;
end proc:
f(x);
                                     |x|
f(-3);
                                      3
f(2.44);
                                    2.44
Hoping this has been 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.edu/~meade/
I'll guess that the real question is that you don't like Maple's response when you give f a non-numeric argument:
f := proc(x)
  if x>0 then x else -x fi;
end proc:
f(-3);
                                      3
f(x);
Error, (in f) cannot determine if this expression is true or false: 0 < x
The problem here is that Maple can decide if x>0 only when x is numeric. In this type of situation you need to check if the argument is numeric before entering the body of the procedure. And, if you want, you can have Maple generate appropriate output. Here's one way to do this for your example:
f := proc(x)
  if x::numeric then
    if x>0 then x else -x end if;
  else
    nprintf("|%a|",x)
  fi;
end proc:
f(x);
                                     |x|
f(-3);
                                      3
f(2.44);
                                    2.44
Hoping this has been 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.edu/~meade/
Done! I just created a book page containing links to all of the Quick Reference documents I have prepared over the past 10 years. If you want to put a direct link to this book page, the url is http://www.mapleprimes.com/book/quick-reference-document The most current version of the Quick Reference Guide can always be found at http://www.math.sc.edu/~meade/maple/maple-ref.pdf
---------------------------------------------------------------------
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/
Done! I just created a book page containing links to all of the Quick Reference documents I have prepared over the past 10 years. If you want to put a direct link to this book page, the url is http://www.mapleprimes.com/book/quick-reference-document The most current version of the Quick Reference Guide can always be found at http://www.math.sc.edu/~meade/maple/maple-ref.pdf
---------------------------------------------------------------------
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/
It would be nice if map could do this, but the lesser known zip will work. The general use of zip is to combine elements from two different lists, sets, .... The visual output from zip is useless (a 2x2 matrix whose entries are all NULL) but the appropriate assignments are made.
restart;
A := Matrix([[x,y],[u,v]]);
B := Matrix([[1,2],[3,4]]);
zip( assign, A, B ):
x, y, u, v;
                                 1, 2, 3, 4
---------------------------------------------------------------------
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 51 52 53 54 55 56 57 Last Page 53 of 76