acer

32490 Reputation

29 Badges

20 years, 9 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by 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

with(Logic):

T := ( (A &implies B ) &and ( B &implies C ) )
     &implies ( A &implies C ):

Tautology( T );

                              true

acer

The select command picks off operands of the expression which satisfy the predicate. And what one might imagine to be "some terms" may not be the same as the operands of the expression.

op(y+3*x(t));
                           y, 3 x(t)

select(has, y+3*x(t), x);
                             3 x(t)

op(3*x(t));
                            3, x(t)

select(has, 3*x(t), x);
                              x(t)

op(x(t));
                               t

select(has, x(t), x);
                              x()

You might have intended "some terms" to mean terms in a sum, but neither a product nor a function call is a sum of terms.

Sometimes people will write a procedure which handles expressions by case. Ie, whether it is of type `+`, or type `*`, or neither. Or just to handle type `+` or not, according to need. The predicate gets mapped across a sum, but is applied directly otherwise. For example, as a simple operator,

H:=(e,x)->`if`(type(e,`+`),select(has,e,x),`if`(has(e,x),e,NULL)):

H( y+3*x(t), x );
                             3 x(t)

H( 3*x(t), x );
                             3 x(t)

H( x(t), x );
                              x(t)

H( x(t), y ); # returns NULL

nb. You may or may not want to distinguish between `has` and `depends`.

acer

Maple will use less memory (often, for the kind of operations you describe) if the Matrices,Vectors, or Arrays have a "hardware" datatype. That means that the datatype=value option is float[8] or integer[4], etc.

There is more support for datatype=float[8], which matches the double precision type for floating-point data that would be used by Matlab or `double` in the C language, etc. That support is accessible using most commands from LinearAlgebra, arithmetic operations such as `+`, `.`, etc, as well as elementwise operations such as (several commands prefixed by) `~` or `zip`.

3000x1000 is not very large, if programmed as above. For datatype=float[8] that is only about 24 MB of memory.

restart:

m:=CodeTools:-Usage( LinearAlgebra:-RandomMatrix(3000,1000,
                               outputoptions=[datatype=float[8]]) );

memory used=22.96MiB, alloc change=23.00MiB, cpu time=93.00ms, real time=97.00ms
                             [ 3000 x 1000 Matrix   ]
                             [ Data Type: float[8]  ]
                        m := [ Storage: rectangular ]
                             [ Order: Fortran_order ]

CodeTools:-Usage( m + m ):
memory used=22.89MiB, alloc change=23.00MiB, cpu time=16.00ms, real time=15.00ms

From your brief description I would imagine that yout task would involve a lot of floating-point computations, and that the float[8] datatype would be adequate for most (if not all) of the Arrays.

acer

I'm not sure what precisely you might mean by, "...the parameters in a record do get updated..."?

> restart:
> r:=Record(p1=parm1,p2=parm2):
> parm2:=0:
> r:-p2;
                                       0

> eval(r:-p2,1);
                                     parm2

> n:=eval(r):
> eval(n:-p2,1);
                                     parm2

> s:=copy(r):
> eval(s:-p2,1);
                                     parm2

> s:=copy(eval(r)):
> eval(s:-p2,1);   
                                     parm2

> f:=proc(t) t:-p2, eval(t:-p2,2), eval(t:-p2,1), eval(t); end proc:
> f(r);                                                             
                  0, 0, parm2, Record(p1 = parm1, p2 = parm2)

The printing of a Record might not be showing the value of `parm2` that you do get upon programmatic access of the value of export `p2`, but that's just a detail of the printing mechanism. In contrast, the `print/rtable` routine is what makes the assigned value of `z` appear visibly in the displayed output below.

> restart:
> m:=Matrix([[a]]):
> a:=z:
> m;
                                      [z]

> eval(m[1,1],1);
                                       a

acer

The first link might allow you an easier way to vary the coloring, if you are trying to match or get close to that image, by use of a graphical application where coloring is controlled by sliders.

http://www.mapleprimes.com/posts/134419-Faster-Fractals

 

http://www.maplesoft.com/applications/view.aspx?SID=32594

 

http://www.maplesoft.com/applications/view.aspx?SID=6853

 

If you just need something simple, to get started, you could modify the last example (Julia set) of the help-page of the densityplot command. You would need to understand the difference in the formula, of course.

acer

Maple has pretty good coverage. One area where it stands out is Ordinarty Differential Equations (ODEs), at which it is strong in both the exact symbolic and also the numerical solving areas.

acer

First 263 264 265 266 267 268 269 Last Page 265 of 337