acer

32400 Reputation

29 Badges

19 years, 344 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Please describe in as much detail as possible how you want color to be defined.

The code you're shown has procedure mandelbrot which currently returns a single value given input point (x,y). And plot3d is using that to select a hue (as in H=hue from the HSV color space).

With just a single returned value m (per x,y input) it's natural to either produce a grayscale shading value or a hue value. Or you could use m for the intensity (the V in HSV) as well as for the hue.

Another value that you *could* make use of is the final z, for each (x,y) input. Since z is complex its real absolute value abs(z) is another piece is information that can be combined with the final m value to produce a color. With two values (m and abs(z) say) you could produce some attractive color shadings by generating three numbers for the RGB color space. Or you could produce values in a 3-element color space by doing modular arithmetic on either a single or a double-valued return.

Note that I have made no special effort here for efficiency. In particular the 2-value-return version mandelbrot2 below is not evalhf'able and so is slow. It could be made faster.

I didn't understand why you'd want a style=point, so I changed it. See also the last example on the densityplot command's help page. Other related links: herehere, here, and (distantly, showing how images and plot GRID are interchangeable) here and here.

The plots below look much brighter and less grainy in Maple itself.

restart:

mandelbrot := proc(x, y)

     local c, z, m;

     c := evalf(x+y*I);

     z := c;

     for m from 0 to 30 while abs(z) < 2.0 do

        z := z^2+c

        od;

        m;

     end:

plot3d(0, -2 .. 0.7, -1.2 .. 1.2, orientation=[-90,0], grid=[200, 200],
       scaling=constrained, style=patchnogrid, lightmodel=none,
       color=[((x,y)->mandelbrot(x,y)/30.0),
              1,
              1,
              colortype=HSV]);

plot3d(0, -2 .. 0.7, -1.2 .. 1.2, orientation=[-90,0], grid=[200, 200],
       scaling=constrained, style=patchnogrid, lightmodel=none,
       color=[((x,y)->mandelbrot(x,y)/30.0),
              1,
              ((x,y)->30-mandelbrot(x,y)),
              colortype=HSV]);

p1,p2,p3 := 23,5,2:

plot3d(0, -2 .. 0.7, -1.2 .. 1.2, orientation=[-90,0], grid=[200, 200],
       scaling=constrained, style=patchnogrid, lightmodel=none,
       color=[((x,y)->irem(mandelbrot(x,y),p1)),
              ((x,y)->irem(mandelbrot(x,y),p2)),
              ((x,y)->irem(mandelbrot(x,y),p3)),
              colortype=RGB]);

mandelbrot2 := proc(x, y)
     option remember,system, hfloat;

     local c, z, m;

     c := x+y*I;

     z := c;

     for m from 0 to 30 while abs(z) < 2.0 do

        z := z^2+c

        od;

        m, abs(z); # no longer evalhfable, as is

     end:

plot3d(0, -2 .. 0.7, -1.2 .. 1.2, orientation=[-90,0], grid=[200, 200],
       scaling=constrained, style=patchnogrid, lightmodel=none,
       color=[((x,y)->mandelbrot2(x,y)[1]/30.0),
              1,
              ((x,y)->mandelbrot2(x,y)[2]),
              colortype=HSV]);

 


Download naive_mandelbrot.mw

acer

I am having trouble understanding what you want, sorry. Perhaps something like this?

(It's a bug in this server that gridlines are shown in the first plot below.)

restart;

R:=2:

plots:-display(
   plots:-polarplot(R,theta=0..2*Pi,color=red),
   plots:-polarplot(R+cos(theta),theta=0..2*Pi,color=blue),
   gridlines=false);

plots:-display(
   plot(R,theta=0..2*Pi,color=red,coords=polar),
   plot(R+cos(theta),theta=0..2*Pi,color=blue,coords=polar),
   gridlines=false,scaling=constrained);

 


Download costhetafun.mw

acer

You haven't yet said which of the "styles" offered by Matlab's `bar3` command you're trying to emulate. None of these below cover's bar3's `grouped` style, for example.

restart;

Y := Matrix( 20, 3, (i,j)->evalf(1+sin(i*j/Pi)), datatype=float[8] ):

plots:-matrixplot( Y, heights=histogram, gap=0.5,
                   color=((x,y)->1-y/3+0.2),
                   orientation=[-55,55,0], labels=["","",""] );

Statistics:-AreaChart( Y );

Statistics:-AreaChart( Y, format=stacked );

 


Download 3dbarstuff.mw

acer

Try it with a call to `combine` around that problematic expression, ie,

combine( simplify( 2/Pi^2*zabt(n) + 4/Pi^2*dwabt(n) ) );

I am seeing this,

expr := (exp(-n*(cos(phi)+sin(phi)))
         *(-16*n^8+4*sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)*n^6+116*n^6
           -13*sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)*n^4-236*n^4
           -13*sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)*n^2+116*n^2
           +4*sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)-16))
        /(sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)
          *(sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)*n^4-4*n^6
            -3*sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)*n^2
            +13*n^4+sqrt(4*n^2+6*n-4)*sqrt(4*n^2-6*n-4)
            +13*n^2-4)):

combine(expr);

                       -exp(-n cos(phi) - n sin(phi))

acer

See here for an old post on this topic.

Altenatively, you could try it like this (and adjust the size as you wish),

Typesetting:-mo("Hello", mathcolor = "#00CC00", mathsize = "28");

acer

You could use the -c option twice. One to push in your single statement, and once more to push in a quit statement.

On MS-Windows the joy of this is often about getting quotes escaped properly.

(There is at least one old thread on this site about scripting with the CLI more generally, but which includes some comments about passing arbitrary input as if from a file.)

acer

I may not be properly understanding your question, but why can't you use square bracket indexing to both retrieve and assign to the exports of the Record?

restart:

q:=Record(a=sin(x),b=cos(x),c=(x+3.0)^2);

                        /                                     2\
             q := Record\a = sin(x), b = cos(x), c = (x + 3.0) /

exports(q);

                                   a, b, c

for e in exports(q) do
  q[e]:=limit(q[e],x=Pi);
end do:

a,b,c;

                                   a, b, c

eval(q);

                   Record(a = 0, b = -1, c = 37.71916033)

It could also be done above with,

  assign( eval(q[e],1), limit(q[e],x=Pi) );

for each export e of the Record.

acer

This is not good.

I merge execution groups (using the F4 key, say) often when programming in 1D mode. And prior to Maple 2015 I've relied on the fact that lines which begin with a prompt and those which don't are not treated differently, as far as multiple line statements go. And now in Maple 2015 this is broken.

This is a serious regression bug. Its cause is new behaviour in the Standard GUI of Maple 2015, in which a 1D Maple Notation input line need not be terminated with either colon or semicolon. I suppose this was intended as a convenience, implemented without giving adequate consideration to the fact that it introduces ambiguity to the language and breaks previously valid syntax.

Here is a simple example. This example of 1D Maple Notation code works in Maple 18 and earlier, but fails with a syntax error in the Standard GUI of Maple 2015. Note that these lines all occur within the same Execution Group.

for i from 1

  to 3 do

  i end do;

Error, `;` unexpected

Download multilineregression.mw

1D Maple Notation programming in an Execution Group of a Worksheet was one of the few (if only) adequately stable, reliable, and usable modes of programming in the Standard GUI.

The OP's plotting example is a good illustration of the kinds of things that are typical usage. Suppose you have three plot calls in three seeparate execution groups. You can merge the execution groups using just F4, with no need for cut & paste. And then remove a few terminators, and wrap in a `print` call, and the plotting's all combined. Easy. No need to mark out long lines wih the mouse cursor. And by having the print call on a separate line it's even easy to undo it, or toggle the merging on and off just by adding a few # symbols. Easy and useful. But now, a previously valid and straightforwardly natural way to accomplish this has been broken.

It might be ok to remove the need for a colon/semicolon terminator at the end of the last line of an Execution Group. But it's very much wrong to have the parser try and execute every line (lacking a colon/semicolon terminator) before the last line of an Execution Group.

acer

convert(BesselJ(0,x),FormalPowerSeries);

                          infinity
                           -----       k  (-k)  (2 k)
                            \      (-1)  4     x
                             )     ------------------
                            /                2
                           -----         (k!)
                           k = 0

acer

If instead of working with expressions you are ok working with procedures  (or operators, as `unapply` can give you) which each accept multiple arguments then you might look at this old post of mine. It is not written with a particular number of procedure arguments (or variables, if you will) hard-coded.

Note that one can find example problems which appear to converge to a point which is neither a root nor even close to a root, when using an implementation of Newton's method with only the iteration number and the norm-of-change-in-variables as its stopping criteria. A good rootfinding implementation should also offer a check on forward error (plugging the candidate solution back into the equations), to test if an actual root has been detected.

acer

The articles here and here, from the Maple Reporter Tips and Techniques series, might be of some use to you.

acer

@itsme The Explore "command" is an appliable module, not a procedure. When you call `Explore(...)` what you're actually invoking is the module local Explore:-ModuleApply. And so you'd need to change that local, not `Explore` itself. If you just assign some edited proc to the unprotected name `Explore` then you're blowing away the rest of the module.

The fact that the display shows only a summary has nothing to do with accessing the entries of the Matrix in the usual ways (other than crude cut & paste). Even with the displayed summary you can still assign the Matrix to a name and then access its rows, columns, or individual entries by using the usual square-bracket indexing. Or you can do further computation using other commands, including those available via the right-click context-menus.

If you really wish to see all the entries displayed explicitly then you can change the values of the interface(rtablesize) setting. See the interface help page for a description. Eg,

interface(rtablesize=50):

acer

Did you intend to write ``(1600) instead of (1600) ? And similarly for the (1500).

If so then can you not just switch the order in which you do those two eval calls?

param:= {mu[2] = ``(1600), mu[4] = ``(1500)}:
R := unapply(1/(1+exp((1/50)*x)), x):
evalf(eval(eval(R(abs(mu[4]-mu[2])), param), ``=(x->x)));

                          0.1192029220

acer

add( x*ln(x), x = X );

This uses the kernel builtin add for efficiency (not producing a temporary list as collectible garbage).

Your example data seems to be just integers. If you are expecting a float result then you might want to wrap evalf around the expression argument. Ie, evalf(x*ln(x)).

acer

First 227 228 229 230 231 232 233 Last Page 229 of 336