acer

32333 Reputation

29 Badges

19 years, 319 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Try that last one as,

b[6..9,1]:=j[[6,5,4,3],1];

acer

I believe that the menu item that you've cited is available similarly to the rest of the Standard GUI's main menubar, and not from the Help window's menubar. The choices should be available by navigating the menubar Tools->Help Database->....  It is possible that the "Tools" item appearing in the main menubar (on Windows, Linux) is accessible in some different way on OSX. (Eg, on OSX Tools->Options is just Preferences, if I recall...)

I have had success using the command INTERFACE_HELP for managing my own personal .hdb Help database files programmatically. I prefer it, usually, over the makehelp command. For example, using the following code I can repeatedly replace and update a particular help item, in a personal .hdb file, after editing the original worksheet. It deletes the topic, and then adds it back.

restart:
worksheetlocation:=cat(kernelopts('homedir'),
                       "/Documents/hsvdisc2d.mw"):
wkstext:=Worksheet:-ReadFile(worksheetlocation):
wksstring:=Worksheet:-ToString(wkstext):
libname:=cat(kernelopts('homedir'),
             "/maple/toolbox/temp/lib"),libname:
try
streamcall(INTERFACE_HELP('delete',
               'topic'="hsvdisc3d",
               'library'=cat(kernelopts('homedir'),
                             "/maple/toolbox/temp/lib/maple.hdb")));
catch:
end try:
streamcall(INTERFACE_HELP('insert',
               'topic'="hsvdisc3d",
               'text'='TEXT'(wksstring),
               'library'=cat(kernelopts('homedir'),
                             "/maple/toolbox/temp/lib/maple.hdb")));

It's a matter of taste, but I prefer to use scripts like this for rebuilding my project's .mla and .hdb files. This is useful for when I forget the details, and can be less error prone than doing things manually. I keep the scripting Maple code either in plaintext .mpl or in .mw 1D notation Worksheets.

acer

You can create an HSV color disc in both 2D and 3D plots, but the Standard GUI seems to initially respond much better to single density plots as 3D plots.

Here's a 3D version, with axes supressed. And some simple animations that use it as a background. (Note, I inline here a jpg, which appears as nice as did the plot in the GUI. I had trouble exporting it as GIF -- see below.)

restart:
with(ImageTools):
N:=360:
p:=Array(1..N,1..N,1..3,(i,j,k)->
         `if`(k=1,(i-1),`if`(k=2,(j-1)/N,1)),
         datatype=float[8],order=C_order):
scaledp:=Preview(ImageTools:-HSVtoRGB(p),50): #faster, maybe
#scaledp:=Preview(ImageTools:-HSVtoRGB(p)): #no-scaling doesn't help gif export
with(plots):with(plottools):
T:=transform((x,y,z)->[y*cos(x*evalf(2*Pi/360)),
                       y*sin(x*evalf(2*Pi/360)),
                       z]):
hsvdisc:=T(scaledp):
display(hsvdisc,axes=none,view=0..1);

animate(pointplot3d,[[[360*t/(8*Pi)*cos(t),
                       360*t/(8*Pi)*sin(t),
                       1]],
                     color=black,symbolsize=15,symbol=solidcircle],
        background=hsvdisc, t=0..8*Pi, frames=100, axes=none,
        view=[-360..360,-360..360,0..2]);

animate(spacecurve,[[360*T/(8*Pi)*cos(T),
                     360*T/(8*Pi)*sin(T),
                     1],T=0..t,
                     color=black,thickness=3,numpoints=150],
        background=hsvdisc, t=0..8*Pi, frames=100, axes=none,
        view=[-360..360,-360..360,0..2]);

Exporting a 2D or 3D densityplot to GIF image file format seems to give a patterned blotchy result. The result with JPEG or BMP looks ok, much smother color gradation. I tried programmatic `plotsetup` export, as well as right-click export from the plot after manually resizing it much larger, in Maple 15 and 16. Maybe I missed something obvious (like grid size??). If you want exported animated GIF, then I guess this would have to be sorted out.

acer

If you want it fast then you could compute the random values up front, using Statistics:-Sample and then access them one at a time, as you need them, from that resulting Array/Vector.

It will take memory, however, to store all the precomputed values up front. It is also possible to take a middle road -- by precomputing in smaller batches. In recent Maple a float[8] Vector can be (memory efficiently) re-used repeatedly as the container into which one periodically computes batches of the random values.

Another way to precompute a sample of floats from the uniform distribution on [0,1) is with the `rtable` constructor, or more conveniently by accessing that though the LinearAlgebra package's commands `RandomVector` and `RandomMatrix`.

V:=LinearAlgebra:-RandomVector[row](3,generator=0.0..1.0,
                                 outputoptions=[datatype=float[8]]);

       V := [0.223811939491137, 0.585267750979777, 0.340385726666133]

X:=Statistics:-RandomVariable('Uniform'(0,1)):

S:=Statistics:-Sample(X,3);

       S := [0.751267059305653, 0.255095115459269, 0.505957051665142]

Statistics:-Sample(X,S):  # re-using S
S;

          [0.699076722656686, 0.890903252535798, 0.959291425205444]

You can compare with calling GenerateFloat() or rand() repeatedly. Note that `randomize` usually only needs to be called once, upon restart. The following is on 64bit Maple 16.01 for Windows 7.

restart:
randomize():
st := time():
X:=Statistics:-RandomVariable('Uniform'(0,1)):
S:=Statistics:-Sample(X,5000000):
for i from 1 by 1 to 5000000 do
S[i];
end do:
time() - st;

                                    2.792

restart:
randomize():
with(RandomTools[MersenneTwister]):
st := time():
for i from 1 by 1 to 5000000 do
GenerateFloat();
end do:
time() - st;

                                   11.170

restart:
randomize():
st := time():
for i from 1 by 1 to 5000000 do
rand()/(1000000000000.);
end do:
time() - st;

                                   29.063

Statistics:-Sample and the rtable constructors also respect the `randomize()` command.

acer

I can't tell from your phrasing whether you want to rearrange the entries of each row or of each column. If I've misinterpreted what you want then sorry; it's a trivial change to the code below to get the other effect.

If M is the original Matrix, then you can rearrange all the rows in one call, using rtable (Matrix/Vector/Array) indexing.

Eg,

M:=Matrix(7,7,(i,j)->i*11);

                           [11  11  11  11  11  11  11]
                           [                          ]
                           [22  22  22  22  22  22  22]
                           [                          ]
                           [33  33  33  33  33  33  33]
                           [                          ]
                      M := [44  44  44  44  44  44  44]
                           [                          ]
                           [55  55  55  55  55  55  55]
                           [                          ]
                           [66  66  66  66  66  66  66]
                           [                          ]
                           [77  77  77  77  77  77  77]

M[[4,6,7,2,3,1,5],1..-1];

                        [44  44  44  44  44  44  44]
                        [                          ]
                        [66  66  66  66  66  66  66]
                        [                          ]
                        [77  77  77  77  77  77  77]
                        [                          ]
                        [22  22  22  22  22  22  22]
                        [                          ]
                        [33  33  33  33  33  33  33]
                        [                          ]
                        [11  11  11  11  11  11  11]
                        [                          ]
                        [55  55  55  55  55  55  55]

 

See the subsection "Selecting Elements: Extracting Subblocks" of the rtable_indexing help-page.

acer

When you write that you want a rational polynomial approximation do you have in mind something like P(x)+S(x)/T(x) where P(x), S(x), and T(x) are each univariate polynomials in x with double precision floating-point coefficients (but possibly rewritten in Horner`s form)?

By 4 ulps do you mean in lp=`last place` hardware double precision (ie. in a scheme with 16 decimal digits)?

You can make do by considering only 0..Pi/4.

Is this close enough (when run compiled with Compiler:-Compile, or converted using CodeGeneration[C]), and do you need Maple code that generates it? I used numapprox:-minimax while computing it.

tanfun := proc(x::float) option inline;
  (0.9639674457083826e-34+(-0.1403264094762631e-30+(0.3402219607050792e-28
  +(.4427849600763185+(-0.9428452458811255e-1+(-0.2340000962851197e-2
  +(0.4982686721516939e-3+(-0.9260046118558648e-4+(0.1971789821665368e-4
  +(-0.4012888100718023e-5+(0.8544837764235923e-6+(-0.1784319759347114e-6
  +(0.3799383266698791e-7+(-0.7999539350949548e-8+(0.1703131269569653e-8
  +(-0.3594642906853935e-9+(0.7644190510188491e-10+(-0.1609484525183886e-10
  +(0.3390517969012429e-11+(-0.6966640403796986e-12+(0.1384318962492760e-12
  +(-0.2506934227750501e-13+(0.3905859966369083e-14+(-0.4494272751264981e-15
  +0.3027062135360529e-16*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)
  *x)*x)*x)*x)*x)*x)*x)*x)*x)*x)/(1.328354880228956+(-.2828535737643377
  +(-.5383619549801358+.1146362355221901*x)*x)*x)+x end proc:

acer

If I understand what you want, then here is one way,

 

restart:

f1 := (x, y) -> sin((1/2)*y+(1/2)*x):
f2 := f1+1:

P1 := plot3d(f1, 0..10, 0..20, style=patch, shading=zhue):
P2 := plot3d(f2, 0..10, 0..20, style=patch, shading=zhue):

Q1:=op([1,3],indets(P1,specfunc(anything,GRID))):
Q2:=op([1,3],indets(P2,specfunc(anything,GRID))):

zmin,zmax,nrowsQ,ncolsQ:=min(min(Q1),min(Q2)),max(max(Q1),max(Q2)),
                         op(map(rhs,[rtable_dims(Q1)])):        

HSVfun:=proc(value,x,y)

   value, 0.75, 0.75;

end proc:

colseq1:=seq(seq(HSVfun((zmax-Q1[i,j])/(zmax-zmin),(i-1)/nrowsQ,(j-1)/ncolsQ),

                                j=1..ncolsQ),i=1..nrowsQ):

P1new:=subsindets(P1,specfunc(anything,SHADING),t->COLOR(HSV,colseq1)):

colseq2:=seq(seq(HSVfun((zmax-Q2[i,j])/(zmax-zmin),(i-1)/nrowsQ,(j-1)/ncolsQ),

                                j=1..ncolsQ),i=1..nrowsQ):
P2new:=subsindets(P2,specfunc(anything,SHADING),t->COLOR(HSV,colseq2)):

plots:-display(P1new,P2new,axes=box,orientation=[35,75,10]);

 

Download colorfun1.mw

(If this is close, then perhaps see this old Post. It could also be done with float[8] C_order Arrays, I suppose.)

acer

You can export your plots programmatically, by using the plotsetup command prior to commands which would normally display or print the plot. This allows one to specify both the output fle as well as a the file format and the resolution of the ensuing image file. (See also the plot/device help-page and in particular the functionality to specify exported height and width using the `plotoptions` option.)

If you wish to use the right-click context-sensitive menu to Export the plot then you may have to first resize it (manually, using the mouse cursor) in the Worksheet in order to obtain a higher resolution image file. (See this old comment, the parent thread of which is the first result when currently searching for "high resolution" on this site.)

acer

In the denominator of your expression that represents V[c] the last term looks like 1/8*something. But there is a missing space or multiplication symbol between the M[b] and the bracketed terms that follows. So your subexpression is actually a function application M[b](...) instead of a product M[b]*(...) and when evaluated at a float value for M[b] that subexpression becomes just the value of M[b] alone.

I suggest that instead of relying on spaces to denote multiplication implicitly your try and always insert explicit multiplication symbols. This problem arises for quite a few people, because it is often difficult to visually recognize whether such a space is or is not present.

acer

Plot something, and then click once on (an empty part of) the plot with the mouse pointer, so that it is in focus. This should make a menu subbar appear just below the top menubar of the Maple Standard GUI.

The item "Plot" will be surrounded by a darker background, but the item "Drawing" should be dark black which means that it is enabled. Select "Drawing" with the mouse cursor, after which a new set of items will be available in that menu subbar. There are a few different arrows, premade and available in that drawing tool.

See the help-pages DrawingTools which has a subsection near its end entitled, "Drawing on Plots", and DrawingToolbar.

acer

It works fine in Maple 14.01 on Windows.

I suspect either a problem with the installation, or an initialization file is setting something, or assigned values from an errant .mla archive are being pickled up.

acer

I doubt that the interpreted, Library level code of  evalf(Int(...)) is thread-safe. So perhaps you got lucky at first, and that Library code might still go wrong running under Threads:-Seq.

Also, the last I checked the Maple Library level define_external call for NAG d01amc was not being done with an option that designates it as thread-safe (the end result being that those particular external calls are blocking -- only one can run at a time). Ie, in Maple 16, I see no THREAD_SAFE option passed here to define_external(),

showstat(`evalf/int/NAGInt`::d01ajc,16);

`evalf/int/NAGInt`:-d01ajc := proc(func, xx, Left, Right, Eps, MaxNumSubInt)
local epsabs, epsrel, f, ret, NAGd01ajcM, max_num_subint, abserr, fun_count, num_subint, HFDigits, intfunc;
       ...
  16     NAGd01ajcM := ExternalCalling:-DefineExternal('hw_d01ajc',ExternalCalling:-ExternalLibraryName("int",'HWFloat'))
       ...
end proc

On the other hand, can you pull the rangeexp(amp,depth/4,t0[128]) right out of your Int() call, as a multiplicative constant? If so, then would there just be one numeric integral to be computed, which doesn't depend upon `depth`? Or have I read it wrongly?

acer

What form of printing is wanted? As a string, or line-printing, or...?

What printing mechanisms are allowed, if not explicit calls to the `print` command?

Perhaps one of these is closer to what you're after.

p:=proc () convert(eval('procname'),string) end proc:
p();

p:=proc () printf("%s",convert(eval('procname'),string)) end proc:
p();

p:=proc () iolib(9,':-default',"%s",convert(eval('procname'),string)); iolib(23,':-default') end proc:
p();

Those can also be anonymous, in recent Maple versions where `thisproc` is available, as follows,

proc () convert(eval('thisproc'),string) end proc:
%();

and so on.

Is this for 2D Math, or is it for 1D Maple notation input?

acer

@GPekov I find it quite difficult to give anything but vague and general advice if you don't post code or describe the code in much more detail. Sorry.

You haven't said whether you used Maple 16, or an older version. In some cases the new garbage collector of Maple 16 can do much better than the older "mark and sweep" collector of previous versions.

If you see some speedup for your code when you increase gcfreq then it may mean that your code speeds up a bit by virtue of the collector running less often (as the expense of more allocation, probably). But it doesn't follow from that that the collector is wasting its time walking structures unnecessarily (and which you seem to want to avoid forcibly). It might instead be that the collector is actually usefully collecting things, and keeping memory allocation down (which in turn might be helping keep your code faster than it might otherwise be). Or not. Hard to tell, code unseen.

What is inside this large Array (of Arrays?). Do the inner Arrays have hardware datatype? If not, and if their contents are numeric, then why not? Are there very many Arrays inside the outer Array? Could you use just a large flat Array instead of all of them (with code revised, but that's just bookkeeping) and give it a hardware datatype. Are you using lists somewhere, of Arrays of integers that are not datatype=integer[4], instead of hardware datatype Arrays? Lots of possibilities, with code unseen, sorry.

You might have a look at Maple's profiling tools, here, here, or here.

It sounds like you are on the right track for efficiency, judging by your other thread and Axel's sound advice: hardware datatypes, inplace operation on Array arguments for both input and output of Compilable procedures, etc. If you can keep garbage production (by the code) down, with zero being the goal, then the collector will almost never run and likely you can avoid it as a bottleneck.

One small thing, if your are coming from a compiled C/Fortran/other environment: Maple procedure calls are relatively quite a bit more expensive, so it can sometimes help to refactor code which just happens to be written to perform many function calls.

I don't see the justification for your last step, where you make the outer Sum have its index be just "q" (as opposed to "q-s" say). (I guess I must be missing something?)

> F := Sum(f(h)*exp(i*h*x),h=-infinity..infinity):

> G := Sum(g(s)*exp(i*s*x),s=-infinity..infinity):

> simplify(combine(combine(F*G)));                

             infinity    /  infinity                              \
               -----     |    -----                               |
                \        |     \                                  |
                 )       |      )       f(h) g(s) exp(i x (h + s))|
                /        |     /                                  |
               -----     |    -----                               |
           h = -infinity \s = -infinity   
                        /

> student[changevar](h=q-s,%,q);

              infinity    /  infinity                            \
                -----     |    -----                             |
                 \        |     \                                |
                  )       |      )       f(q - s) g(s) exp(i x q)|
                 /        |     /                                |
                -----     |    -----                             |
            q = -infinity \s = -infinity                         /

acer

First 261 262 263 264 265 266 267 Last Page 263 of 336