MaplePrimes Posts

MaplePrimes Posts are for sharing your experiences, techniques and opinions about Maple, MapleSim and related products, as well as general interests in math and computing.

Latest Post
  • Latest Posts Feed
  • Just a small digression.  It would be nice if the numbers on the x-axis could be rotated or angled so it does not look like they collide with each other.  When the numbers reach the 100's or 1000's there will be congestion. 

    This is perhaps a suggestion for a future Maple version as the current versions do not support number rotations on the axis.

     

    The Locator object is a nice piece of Mathematica's Manipulate command's functionality. Perhaps Maple's Explore command could do something as good.

    Here below is a roughly laid out example, as a Worksheet. Of course, this is not...

    Here is a short wrapper which automates repeated calls to the DirectSearch 2 curve-fitting routine. It offers both time and repetition (solver restart) limits.

    The global optimization package DirectSearch 2 (see Application Center link, and here) has some very nice features. One aspect which I really like is that it can do curve-fitting: to fit an expression using tabular data. By this, I mean that it can find optimal values of parameters present in an expression (formula) such that the residual error between that formula and the tabular data is minimized.

    Maple itself has commands from the CurveFitting and Statistics packages for data regression, such as NonlinearFit, etc. But those use local optimization solvers, and quite often for the nonlinear case one may need a global optimizer in order to produce a good fit. The nonlinear problem may have local extrema which are not even close to being globally optimal or provide a close fit.

    Maplesoft offers the (commercially available) GlobalOptimization package as an add-on to Maple, but its solvers are not hooked into those mentioned curve-fitting commands. One has to set up the proper residual-based objective function onself in order to use this for curve-fitting, and some of the bells and whistles may be harder to do.

    So this is why I really like the fact that the DirectSearch 2 package has its own exported commands to do curve-fitting, integrated with its global solvers.

    But as the DirectSearch package's author mentions, the fitting routine may sometimes exit too early. Repeat starts of the solver, for the very same parameter ranges, can produce varying results due to randomization steps performed by the solver. This post is branched off from another thread which involved such a problematic example.

    Global optimization is often a dark art. Sometimes one may wish to simply have the engine work for 24 hours, and produce whatever best result it can. That's the basic enhancement this wrapper offers.

    Here is the wrapper, and a few illustrative calls to it on the mentioned curve-fitting example that show informative  progress status messages, etc. I've tried to make the wrapper pretty generic. It could be reused for other similar purposes.

    Other improvements are possible, but might make it less generic. A target option is possible, where attainment of the target would cause an immediate stop. The wrapper could be made into an appliable module, and the running best result could be stored in a module local so that any error (and ensuing halt) would not wipe out the best result from potentially hours and hours worth of conputation.

    restart:
    randomize():
    
    repeater:=proc(  funccall::uneval
                   , {maxtime::numeric:=60}
                   , {maxiter::posint:=10}
                   , {access::appliable:=proc(a) SFloat(a[1]); end proc}
                   , {initial::anything:=[infinity]}
                  )
              local best, current, elapsed, i, starttime;
                starttime:=time[real]();
                elapsed:=time[real]()-starttime;
                i:=1; best:=[infinity];
                while elapsed<maxtime and i<=maxiter do
                  userinfo(2,repeater,`iteration `,i);
                  try
                    timelimit(maxtime-elapsed,assign('current',eval(funccall)));
                  catch "time expired":
                  end try;
                  if is(access(current)<access(best)) then
                    best:=current;
                    userinfo(1,repeater,`new best `,access(best));
                  end if;
                  i:=i+1;
                  elapsed:=time[real]()-starttime;
                  userinfo(2,repeater,`elapsed time `,elapsed);
                end do;
                if best<>initial then
                  return best;
                else
                  error "time limit exceeded during first attempt";
                end if;
              end proc:
    
    
    X := Vector([seq(.1*j, j = 0 .. 16), 1.65], datatype = float): 
    
    Y := Vector([2.61, 2.62, 2.62, 2.62, 2.63, 2.63, 2.74, 2.98, 3.66,
                 5.04, 7.52, 10.74, 12.62, 10.17, 5, 2.64, 11.5, 35.4],
                datatype = float):
    
    F := a*cosh(b*x^c*sin(d*x^e));
    
                                        /   c    /   e\\
                             F := a cosh\b x  sin\d x //
    
    infolevel[repeater]:=2: # or 1, or not at all (ie. 0)
    interface(warnlevel=0): # disabling warnings. disable if you want.
    
    repeater(DirectSearch:-DataFit(F
                          , [a=0..10, b=-10..10, c=0..100, d=0..7, e=0..4]
                          , X, Y, x
                          , strategy=globalsearch
                          , evaluationlimit=30000
                                  ));
    repeater: iteration  1
    repeater: new best  9.81701944539358706
    repeater: elapsed time  15.884
    repeater: iteration  2
    repeater: new best  2.30718902535293857
    repeater: elapsed time  22.354
    repeater: iteration  3
    repeater: new best  0.627585701120743822e-4
    repeater: elapsed time  30.777
    repeater: iteration  4
    repeater: elapsed time  47.959
    repeater: iteration  5
    repeater: new best  0.627585700905294148e-4
    repeater: elapsed time  55.221
    repeater: iteration  6
    repeater: elapsed time  60.009
     [0.0000627585700905294, [a = 2.61748237902808, b = 1.71949329097179, 
    
       c = 2.30924401405164, d = 1.50333106110324, e = 1.84597267458055], 4333]
    
    
    # without userinfo messages printed
    infolevel[repeater]:=0:
    repeater(DirectSearch:-DataFit(F
                          , [a=0..10, b=-10..10, c=0..100, d=0..7, e=0..4]
                          , X, Y, x
                          , strategy=globalsearch
                          , evaluationlimit=30000
                                  ));
    
     [0.0000627585701341043, [a = 2.61748226209478, b = 1.71949332125427, 
    
       c = 2.30924369227236, d = 1.50333090706676, e = 1.84597294290477], 6050]
    
    
    # illustrating early timeout
    infolevel[repeater]:=2:
    repeater(DirectSearch:-DataFit(F
                          , [a=0..10, b=-10..10, c=0..100, d=0..7, e=0..4]
                          , X, Y, x
                          , strategy=globalsearch
                          , evaluationlimit=30000
                                  ),
             maxtime=2);
    
    repeater: iteration  1
    repeater: elapsed time  2.002
    Error, (in repeater) time limit exceeded during first attempt
    
    # illustrating iteration limit cutoff
    infolevel[repeater]:=2:
    repeater(DirectSearch:-DataFit(F
                          , [a=0..10, b=-10..10, c=0..100, d=0..7, e=0..4]
                          , X, Y, x
                          , strategy=globalsearch
                          , evaluationlimit=30000
                                  ),
             maxiter=1);
    
    repeater: iteration  1
    repeater: new best  5.68594272127419575
    repeater: elapsed time  7.084
     [5.68594272127420, [a = 3.51723075672918, b = -1.48456068506828, 
    
       c = 1.60544055207338, d = 6.99999999983179, e = 3.72070034285212], 2793]
    
    
    # giving it a large total time limit, with reduced userinfo messages
    infolevel[repeater]:=1:
    Digits:=15:
    repeater(DirectSearch:-DataFit(F
                          , [a=0..10, b=-10..10, c=0..100, d=0..7, e=0..4]
                          , X, Y, x
                          , strategy=globalsearch
                          , evaluationlimit=30000
                                  ),
             maxtime=2000, maxiter=1000);
    
    repeater: new best  3.10971990123465947
    repeater: new best  0.627585701270853103e-4
    repeater: new best  0.627585700896181428e-4
    repeater: new best  0.627585700896051324e-4
    repeater: new best  0.627585700895833535e-4
    repeater: new best  0.627585700895607885e-4
     [0.0000627585700895608, [a = 2.61748239185387, b = -1.71949328487160, 
    
       c = 2.30924398692221, d = 1.50333104262348, e = 1.84597270535142], 6502]
    

    I came across a thing that does not make sense in Maple. If you click on:

    http://ichart.finance.yahoo.com/table.csv?s=CSV&a=10&b=15&c=1996&d=03&e=24&f=2012&g=d&ignore=.csv

    Then you will get a csv-file.

    Now if you download and save that file on your computer then you can open it with:

    I am surfing around looking for cloud database providers (a lot of them are free
    such as http://xeround.com) Then it struck me that maple has a cloud. Unfortunatly I
    dont think it can handle what I want it to do:

    Wouldnt it be cool if every maple user could have a personal or public data warehouse
    in the maple cloud instead of everyone having sql servers running localy with attached
    cron jobs and head aches.

    It...

     

    The MRB constant is evaluated by

    I did not come across with a sorting algorithm animation that allows me to enter my own data, so I decided to write one in Maple.

    In this worksheet, you can create an animation on sorting the integers that you have entered. If you let the worksheet to generate the data for you, you can specify the sortedness of the data. This feature allows you to visualize how some algorithms perform better or worse on data of a certain characteristic: The time complexity may not be...

     

    with(numtheory):

    f := proc (x) options operator, arrow; sum((-1)^n*(n^(1/n)-1), n = x .. infinity) end proc

    proc (x) options operator, arrow; sum((-1)^n*(n^(1/n)-1), n = x .. infinity) end proc

    (1)

    What are the quotients  ot the  continued fration of the sum of f(1)+f(2)+f(3)+f(4)+...

    Here are the  quotients  of some partial sums.

    ``

    cfrac(evalf(sum(f(x), x = 1 .. 2)), 'quotients')

    [0, 2, 1, 1, 1, 21, 10, 4, 1, 4, 8, `...`]

    (2)

    cfrac(evalf(sum(f(x), x = 1 .. 3)), 'quotients')

    [0, 6, 1, 2, 3, 1, 1, 2, 3, 3, 24, `...`]

    (3)

    cfrac(evalf(sum(f(x), x = 1 .. 4)), 'quotients')

    [0, 2, 1, 2, 1, 4, 2, 1, 3, 1, 1, `...`]

    (4)

    cfrac(evalf(sum(f(x), x = 1 .. 5)), 'quotients')

    [0, 5, 1, 99, 1, 1, 1, 6, 1, 3, 1, `...`]

    (5)

    cfrac(evalf(sum(f(x), x = 1 .. 6)), 'quotients')

    [0, 2, 1, 6, 1, 2, 1, 2, 2, 1, 1, `...`]

    (6)

    cfrac(evalf(sum(f(x), x = 1 .. 7)), 'quotients')

    [0, 5, 1, 1, 142, 1, 1, 1, 1, 19, 1, `...`]

    (7)

    cfrac(evalf(sum(f(x), x = 1 .. 8)), 'quotients')

    [0, 2, 1, 47, 1, 1, 1, 1, 27, 4, 1, `...`]

    (8)

    cfrac(evalf(sum(f(x), x = 1 .. 9)), 'quotients')

    [0, 5, 5, 3, 1, 7, 1, 1, 1, 2, 1, `...`]

    (9)

    cfrac(evalf(sum(f(x), x = 1 .. 100)), 'quotients')

    [0, 3, 1, 1, 1, 11, 2, 2, 1, 1, 4, `...`]

    (10)

    cfrac(evalf(sum(f(x), x = 1 .. 200)), 'quotients')

    [0, 3, 1, 2, 1, 1, 1, 11, 3, 4, 6, `...`]

    (11)

    cfrac(evalf(sum(f(x), x = 1 .. 400)), 'quotients')

    [0, 3, 1, 3, 3, 3, 1, 18, 1, 2, 1, `...`]

    (12)

    cfrac(evalf(sum(f(x), x = 1 .. 800)), 'quotients')

    [0, 3, 1, 3, 1, 4, 16, 14, 3, 23, 2, `...`]

    (13)

    cfrac(evalf(sum(f(x), x = 1 .. 1600)), 'quotients')

    [0, 3, 1, 4, 7, 4, 436, 1, 1, 1, 2, `...`]

    (14)

    ``

    Here are the quotients of the  continued fration  of the sum. 

    cfrac(evalf(sum(f(x), x = 1 .. infinity)), 'quotients')

    [0, 3, 1, 4, 1, 1, 1, 1, 1, 9, 1, `...`]

    (15)

    With the exception of the leading 0, that is close to the integer squence of pi.

    ``evalf((65241/65251)*Pi)

    3.141111191

    (16)

    The exponents of 2 that sum the numerator and denominator, in the following way, of that multiple of pi give rise to the integer sequences {0,1,2,3,8,16},numbers such that floor[a(n)^2 / 7] is a square, and {0,2,3,4,8,16},{0,3} union powers of 2.

    evalf((2^16-2^8-2^5-2^2-2-2^0)*Pi/(2^16-2^8-2^4-2^3-2^2-2^0))

    3.141111191

    (17)

    We can do the same thing for the first 20 quotients giving rise to the integer sequences {0,1,2,5,6,8,10,13,17,19,22,23,24,28,31} and {0,4,6,9,12, 14,15,16,18,22, 23,24,28,31}. What can be said of these sequences?

    cfrac(evalf(sum(f(x), x = 1 .. infinity), 20), 20, 'quotients')``

    [0, 3, 1, 4, 1, 1, 1, 1, 1, 9, 1, 3, 1, 2, 1, 1, 1, 5, 1, 3, 11, `...`]

    (18)

    evalf((1849023129/1849306543)*Pi, 20)

    3.1411111913121115131

    (19)

    ````

    evalf((2^31-2^28-2^24-2^23-2^22-2^19-2^17-2^13-2^10-2^8-2^6-2^5-2^2-2-2^0)*Pi/(2^31-2^28-2^24-2^23-2^22-2^18-2^16-2^15-2^14-2^12-2^9-2^6-2^4-2^0), 20)

    3.1411111913121115131

    (20)

    ``


     

    NewtonBlackArea.mw

    I have been working with Newton-Raphson fractals for some time.  Like others it was necessary to deal with the "black areas" many times, so I performed some additional analysis and present some of these results here.  This will allow others to stop coloring these areas black and allow visualization of the structure inside these areas.  It will also help demonstrate...

    Starting from Maple 15, the useful ?plottools/getdata command is added. It tansforms a Maple plot to a Matrix. Unfortunately, the getdata command deals only with Maple plots. The question arises: "How to get a data from bmp, jpg, tiff, pcx, gif, png and wmf formats?" This is used in medicine and engineering. Such question was asked here

    2012.zip

    Ukraine. External independent evaluation (ZNO) in 2012. Trial in Maple 16

    html 3-interactive in Ukrainian: zno.zip

    One of my coworkers brought in G.L. Legendre's book "Pasta By Design" (amazon.ca/dp/0500515808).  It is full of photographs and parametric equations for 92 shapes of pasta.  Of course, we had to set about plotting his equations in Maple.  Orginally I was going to post about this before Maple 16 came out, but I was struck with how much better plots looked in the Maple 16 pre-release and so I decided to wait.   As one example, here are the parametric equations for Giglio Ondulato noodles plotted using the default 3D plot settings in Maple 16 and Maple 15.

     

    Released today, with over 4500 additions and enhancements, Maple 16 reinforces our track record for consistent innovation and industry leadership in areas like ease of use and symbolic computing performance.

    The*MRB*constant = sum((-1)^n*(n^(1/n)-1), n = 1 .. infinity) and sum((-1)^n*(n^(1/n)-1), n = 1 .. infinity) = sum((-1)^n*(n^(1/n)-1), n = 2 .. infinity)

    But what can we say about

     (∏)(-1)^(n)*(n^(1/(n))-1)?

    ``

    ``

    Maple does not evaluate it:

    evalf(product((-1)^n*(n^(1/n)-1), n = 2 .. infinity))

    product: Cannot show that (-1)^n*(n^(1/n)-1) has no zeros on [2,infinity] product((-1)^n*(n^(1/n)-1), n = 2 .. infinity)

    (1)

    And perhaps it should not because of the alternating sign;

    evalf(product((-1)^n*(n^(1/n)-1), n = 2 .. 10^2))

    -0.3908773173e-101

    (2)

    evalf(product((-1)^n*(n^(1/n)-1), n = 2 .. 10^3))

    -0.7676360791e-1799

    (3)

    evalf(product((-1)^n*(n^(1/n)-1), n = 2 .. 10^3+1))

    0.5316437097e-1801

    (4)

    ``

     

    Download 3232012.mw

    A common example to emphasize that it is not OK to bring absolute values inside the integral compares

    abs( int( cos(n*x), x=0..Pi ) ) asuming n::integer

    and

    int( abs( cos(n*x) ), x=0..Pi ) assuming n::integer

    Maple correctly formulates the first to 0. But the second expression gives it more trouble, returning two messages:

    Warning, unable to determine if (1/2)*Pi*(1+2*_Z7)/n is between 0 and Pi; try to use assumptions or use the AllSolutions option
    Warning, unable to determine if (1/2)*Pi*(1+2*_Z8)/n is between 0 and Pi; try to use assumptions or use the AllSolutions option
    First 110 111 112 113 114 115 116 Last Page 112 of 307