Product Tips & Techniques

Tips and Tricks on how to get the most about Maple and MapleSim

For a bit of light relief, head on over to the online comic strip at phdcomics.com.  If you've ever been a PhD student, be careful, this strip might make the nightmares come back...

Hello,

I have problem with define external function with dll written in Visual Basic.

Declaration of function is

I was playing with a problem from the Maple NG, one can state it as
  
  Int( arccos(x) / ( 1+x^4) , x=0 .. 1)

Maple 11.02 gives a result, which numerical can not be valid.

Using real (!) partial fractions (Maple uses decomposition over the
complex, no?) I got a similar problem with denominator = parabola
(and continuity over the integration interval):

  Int( arccos(x) / (x^2 - x * 2^(1/2) + 1), x = 0 .. 1)

Some more and time-consuming consuming experiments reduces troubles
to the following example, where symbolics are disproven by numerics:

As many of you have experienced, the maplet MathMLEditor, has some problem when it comes to interpret correctly the typing functions, even some functions with the help of the palette.

I was trying to input this function : sin(4*x)+cos(2*x) but after moving form the unknown tag _XML_ error, I end up with misinterpretations of this function, to things like  4*sin(x)+cos(2*x).

So, the comments in this blog tells that the better solution is to use a TextField to get the input function, but now I face this problem

f := Get('txtFunction');
 

After fighting with the Maplet Table control, I decided to give it a try to the TextBox, using tabulator spaces, to have some degree of control over the column layout I need to present tablar results.

The problem I am facing now, is that the "\t" tabulator scape caractar on the textbox has a size to big, in some applications you can set the tab size, in number of caracters or something else, anyone know if this is possible in Maple or on  a Maplet?

  restart: interface(version); Digits:=14:

    Classic Worksheet Interface, Maple 11.02, Windows, Nov 10 2007 Build ID 330022

  Ei(1,1/2*Pi*(1+2*k)): 
  %=convert(%,Sum);
  subs(k=0,%);
  evalf(%);

                    Pi (1 + 2 k)
              Ei(1, ------------) = GAMMA(Pi k + 1/2 Pi)
                         2

                             Pi            Pi
                      Ei(1, ----) = GAMMA(----)
                             2            ...

Another interesting undocumented package in the Maple 11.02 Library.

My oldest son, Stuart, recently completed a Science Fair project on sudoku puzzles. While I am fairly good at solving sudoku puzzles, the mathematics is something that is completely outside my area of expertise. After seeing the paper by Hurzberg and Murty in the Notices of the AMS (June/July 2007) and additional papers by Felgenhauer and Jarvis (http://www.afjarvis.staff.shef.ac.uk/maths/felgenhauer_jarvis_spec1.pdf)  and Russell and Jarvis (http://www.afjarvis.staff.shef.ac.uk/maths/russell_jarvis_spec2.pdf) and Jarvis' sudoku webpage (http://www.afjarvis.staff.shef.ac.uk/sudoku/), I felt that I had a reasonable understanding of some of the basic ideas involved in counting unique sudoku puzzles. While I had nothing to add to the mathematical ideas, I did see the potential to create a tool to visualize these ideas. The result is the worksheet I just uploaded to MaplePrimes:

View 178_Sudoku3-20-03-08.mw on MapleNet or Download 178_Sudoku3-20-03-08.mw
View file details

The time for Easter eggs will soon be here.

And using LibraryTools to browse and poke about in Maple's .mla files can show a few undocumented items.

Here's one below, that's an interesting part of a package.

Can anybody tell me how to plot a family of indexed curves without having to type each one in the plot command?

View 4937_page 27.mw on MapleNet or Download 4937_page 27.mw
View file details

I'd like to see anything anybody would do differently.

As an example it is shown, how one convert a (simple) trigonometric equation into a polynomial problem and use Maple
to find a symbolic answer for the equation. The idea is to use the so called Joukowsky transform, which maps the circle
to the interval [-1, ... , +1].

I would have liked to simplify the result (as it is real in my case), but gave up. May be others have a good idea for that.

Using the procedure permsPosNeg as given in the blog entry Positive and negative permutations, including the improvement obtained in the blog entry Refactoring Maple code, consider the following procedure:

John Fredsted posted some interesting code dealing with permutations, and I suggested a small improvement.  Here, I want to continue the story of that improvement.  First, let us focus one particular line of code:

  posMaps,negMaps := seq(map((perm::list) ->
		(x::list) -> [seq(op(perm[i],x),i=1..nops(perm))]
	,perms),perms in [posPerms,negPerms]);

which uses a lexically scoped procedure to perform the permutations. The first thing to notice is that op(perm[i],x) is really equivalent to x[perm[i]]. Now that we have that perky op gone, we see that the resulting code expression will return unevaluated if x is unknown, unlike op which throws an error message (correctly so!). So now instead of using scoping, we can let Maple actually evaluate the inner perm[i] calls, and use unapply to recover a routine. Putting that together gives us my suggestion:

posMaps,negMaps := seq(map((perm::list) -> unapply([seq(x[perm[i]],i=1..nops(perm))],x),perms), 
perms in [posPerms,negPerms]);

In a recent blog entry, I proposed an easy way to plot the region between two curves. Later I read from an earlier blog entry that “filled=true” in implicitplot can produce amazing effects for plotting regions. Inspired by the blog entry, I’d like to introduce another easy way to plot the region between two curves.

To plot the region between y=f(x) and y=g(x) (x=a..b), we just need the following code:
with(plots):

f:=x->f(x): g:=x->g(x):

implicitplot(y=0, x=a..b, y=f(x)..g(x), filled=true, coloring=[green,green]);


The key to the success of this code is that Maple 8 allows
varying range for the second variable y (i.e. y=f(x)..g(x)). However I was sorry to find that this is not allowed in Maple 11 (This will be addressed later.) .

 

Example 1  The region between y=x and y=x^2.

with(plots):

f:=x->x:g:=x->x^2:

a:=0: b:=1:

region:=implicitplot(y=0,x=a..b,y=f(x)..g(x),filled=true,coloring=[yellow,yellow]):

F:=plot(f(x),x=a-0.2..b+0.2,thickness=3,color=red):

G:=plot(g(x),x=a-0.2..b+0.2,thickness=3,color=blue):

display(F,G,region,scaling=constrained);

 

 

Example 2 The region between y=sin(x) and y=cos(x).

with(plots):

f:=x->sin(x):g:=x->cos(x):

a:=0: b:=6:

region:=implicitplot(y=0,x=a..b,y=f(x)..g(x),filled=true,coloring=[grey,grey]):

F:=plot(f(x),x=a-0.2..b+0.2,thickness=3,color=red):

G:=plot(g(x),x=a-0.2..b+0.2,thickness=3,color=blue):

display(F,G,region,scaling=constrained);



 

Now if we reverse the order of the range options from “x=a..b, y=f(x)..g(x)” to “y=f(x)..g(x), x=a..b”, some strange but interesting thing will happen (See Example 3.

Example 3

with(plots):

f:=x->sin(x):g:=x->cos(x):

a:=-1: b:=6:

region:=implicitplot(y=0, y=f(x)..g(x),x=a..b, filled=true,coloring=[grey,grey]):

F:=plot(f(x),x=a-0.2..b+0.2,thickness=3,color=red):

G:=plot(g(x),x=a-0.2..b+0.2,thickness=3,color=blue):

display(F,G,region,scaling=constrained);
 


It can be seen that the region in Example 2 has been reflected with respect to the line y=x. But this is not bad because can use this phenomenon to plot regions between curves x=f(y) and x=g(y) (See Example 4).

 

Example 4  The region between x=y^2/2 and x=y^4/4-y^2/2.

with(plots):

f:=y->y^4/4-y^2/2: g:=y->y^2/2:

region:=implicitplot(y=0,x=f(y)..g(y),y=0..2,filled=true,coloring=[grey,grey]):

F:=plot([f(y),y,y=-1..2.3],thickness=3):

G:=plot([g(y),y,y=-1..2.3],thickness=3,color=blue):

display(region,F,G,scaling=constrained);

 

 

 


Finally some questions to be answered or discussed.

    1. Is “coloring” used in the examples an option in the package Plots? But I cannot find it in the Help (Typing ? coloring produces no results.) .
   2. Why the strange but interesting thing happens in Example 3 ?

   3. Why the above method cannot be realized in Maple 11?
   If we input the following code in Maple 11,
with(plots):

implicitplot(y=0,x=0..1,y=x..x^2,filled=true,coloring=[yellow,yellow]);with(plots);
An error warning will occur:
Error, (in plots/implicitplot) invalid input: invalid range for second variable

This means varying range for the second variable y (eg. y=x..x^2) is not allowed in Maple 11 , but which is allowed in Maple 8. If this is true, then I doubt if Maple 11 is really stronger than its earlier versions in all respects.

 

In a comment to a Mapleprimes thread, Jacques mentioned an old suggestion of Kahan's that numerical computations should return an estimate of conditioning alongside a result.

I mentioned in this comment an approach for numerical estimation of (all) roots of a univariate polynomial with real or complex numeric coeffficients that is based upon computing eigenvalues of a companion matrix. Here below is some rough code to inplement that idea, but which also returns condition number estimates associated with the eigenvalues.

I include an example of the badly conditioned Wilkinson's polynomial. It is possible that better results could be obtained by using a Lagrange basis representation of that polynomial, but I didn't try to figure out how that would work in an analogous way. The standard Maple utility, fsolve, has no problem with this example.

First 44 45 46 47 48 49 50 Last Page 46 of 65