acer

22182 Reputation

29 Badges

15 years, 230 days

Social Networks and Content at Maplesoft.com

"My friend George Mallory… once did an inexplicable climb on Snowdon. He had left his pipe on a ledge, half-way down one of the Liwedd precipices, and scrambled back by a short cut to retrieve it, then up again by the same route. No one saw what route he took, but when they came to examine it the next day for official record, they found an overhang nearly all the way. By a rule of the Climbers' Club, climbs are never named in honour of their inventors, but only describe natural features. An exception was made here. The climb was recorded as follows: 'Mallory's Pipe, a variation on route 2; see adjoining map. This climb is totally impossible. It has been performed once, in failing light, by Mr G. H. L. Mallory.'." -- "Goodbye to All That", Robert Graves

MaplePrimes Activity


These are answers submitted by acer

The very long time that it takes for your high resolution example to display is mostly the time it takes for the GUI to render the animation. The kernel (Maple engine) time to compute the plotting structures does not grow nearly as quickly, with respect to the grid resolution.

For example, if I change that resolution to grid=[91,91] then on my decently fast machine the construction of the animation's plotting structure takes 3 seconds but the GUI takes over 100 seconds to render it.

In answering a Question of yours from 5 days ago I explained that the GUI performance is impacted by high resolution of 2D density plots. And that thread had several citations to older posts that mentioned the same issue.

You will not be able to get the GUI to quickly render (using its traditional animation mechanism) a decent number of high resolution densityplots in current Maple, even if they are completely precomputed.

One can get somewhat better GUI performance in rendering a sequence of colored 3D surface plots, displayed with a top-down orientation (view from above) so as to mimic a 2D densityplot. But the performance isn't much better, and the feasible grid resolution not much greater.

Improving the GUI performance for this same example is precisely what this older thread's Answer is all about.

That older Answer uses the background option of the plot command as an alternate for densityplot, but unfortunately the GUI cannot utilize multiple background encodings in rendering a "traditional" plotting animation.

Here are some ways in which the Explore command can be used, instead, to play a sequence of either plots-with-backgrounds or images.

arg_not_densityplot_anim.mw

The following (2015) is similar to that stackexchange example you cited:

   https://mapleprimes.com/posts/200943-Hypotrochoids-And-Symmetric-Things#comment200739

That parent Mapleprimes Post was based on a sum of exp calls, as was that parent stackexchange question. The Mapleprimes Post also starts with some related links.

Here is a version of that in a worksheet, using the animate command.

The code is longer than necessary as it allows various options for the eventual Explore of it, such as toggling off radial lines or circles, or changing the nesting order, etc.

restart:

cycler := proc(k, p, m, n, T,

               {showcircles::truefalse:=false, showlines::truefalse:=false,

                showaxes::truefalse:=false, forceview::truefalse:=true,
                nesting::string:="B M G"}, $)

  local t, v, c, r, col, tab, terms, perm;

  uses plottools, plots;
  tab := table(["B"=1,"M"=2,"G"=3]);
  terms := [exp(I*t), -exp((k+1)*I*t), I*exp((1-p*k)*I*t)];

  r := [m*n, n, m];
  col := ["black", "magenta", "green"];
  perm := map2(`?[]`,tab,`[]`~(StringTools:-Split(nesting," ")));
  (r,col,terms) := r[perm], col[perm], terms[perm];
  c := eval([seq([Re,Im](add(terms[i]*r[i], i=1..j)), j=0..3)], t=T);
  v := add(abs(r[i]), i=1..3);
  plots:-display(

    `if`(showcircles,

         [seq(circle(c[i], r[i], ':-linestyle'=':-dot', ':-color'=col[i]), i=1..3),

          pointplot([seq(c[i], i=2..4)], ':-symbol'=':-solidcircle',

                    ':-symbolsize'=15, ':-color'=col)][], NULL),
    `if`(showlines,
         [seq(line(c[i],c[i+1], ':-color'=col[i]),i=1..3)][], NULL),

    complexplot(add(terms[i]*r[i], i=1..3), t=0..T),

    `if`(forceview, ':-view'=[-v..v,-v..v], NULL),

    ':-scaling'=':-constrained',

    ':-axes'=`if`(showaxes, ':-boxed', ':-none') );

end proc:

#cycler(5, 3, 2, 3, 2*Pi, showcircles);

cycler(5, 3, 2, 3, Pi/3, showcircles, showlines);

plots:-animate(cycler, [3,3,2,4,t,showcircles], t=0..2*Pi, frames=100);

 

cycleranimnested0.mw

Here's the same thing running under the Explore command:

cyclerappnested0.mw

I find it amusing to visualize that the vector-sum -- and thus the traced curve -- is the same regardless of the nesting order. In the exploration the nesting order can be changed using the menubox, on-the-fly while it plays.

I suppose that with a little work one could adjust the code to allow deeper nesting, though the calling sequence might be better refactored or simplified (ie. w.r.t. the free parameters).

The error message indicates that theta evaluates to 0, so looks like you've forgotten assigning to theta earlier.

Is this the kind of thing that you're after?

restart;

#
# You could use the ImportMatrix command to import
# your data file, and assign to M.
#
# I made up this data below, because the data was
# present only as an image in the Question.
#

M := Matrix([ [ 2, 53, 9.39 ],
              [ 2, 55, 4.56 ],
              [ 3,  4, 1.39 ],
              [ 3,  5, 3.97 ],
              [ 3,  6, 1.60 ],
              [ 3,  7, 7.92 ],
              [ 3,  8, 1.35 ],
              [ 3,  9, 1.46 ],
              [ 3, 10, 3.65 ] ]):

comb := [ [1,3], [1,4], [1,9], [3,4], [3,9] ];

[[1, 3], [1, 4], [1, 9], [3, 4], [3, 9]]

rows := [seq(`if`(member([M[i,1],M[i,2]], comb), i, NULL),
             i = 1..LinearAlgebra:-RowDimension(M))];

[3, 8]

M[rows, ..];

Matrix(2, 3, {(1, 1) = 3, (1, 2) = 4, (1, 3) = 1.39, (2, 1) = 3, (2, 2) = 9, (2, 3) = 1.46})

Download some_rows.mw

There above could also be done with shorter, slicker code (and even less readily understandable code, if you prefer).

Of course you could also pull out other parts of the rows. You could pull out single columns, or omit the first two columns, etc. Eg.

   M[ rows, 2 ];
   M[ rows, 3.. ];

Or, if M has at least seven columns,

   M[ rows, 3..7 ];

 

Is this the kind of effect you're after?

restart

M := Matrix(4, 4); for m from 0 to 4 do for n from 0 to 4 do M(m+1, n+1) := %factorial(2*m+3*n)/(%factorial(m+2*n+1)*%factorial(m)*%factorial(n)) end do end do; M

Matrix(%id = 36893628751015145588)

`~`[InertForm:-Display](M, inert = false)

Matrix(%id = 36893628751003770380)

NULL

Download How_to_display_factorial_unevaluated_ac.mw

Some of those denominators have squares, eg, (2!)^2.  Let us know if you'd prefer to have those displayed as 2! * 2! , which may just involve using inert `%*` instead.

Since that old post was made the plot3d command has been given an image option, which provides an easier syntax for putting an image on a surface.

You can use a reference to an external file, or an imported image file which becomes an Array. Rescaling makes it easier on GUI/Java resources.

You've omitted the details of how you want the images oriented and aligned. So naturally you can adjust that in the code below.

I cut off some white narrow border around your Questions inlined images.

restart;

with(ImageTools):

loc:=cat(kernelopts(homedir),"/mapleprimes/"):

im1:=Scale(Read(cat(loc,"dl1.png"))[5..-5,5..-5,..],1/4):
im2:=Scale(Read(cat(loc,"dl2.png"))[5..-5,5..-5,..],1/4):

plots:-display(
  plot3d(1,x=0..Pi,y=0..Pi,coords=spherical,style=surface,image=Flip(im2,vertical)),
  plot3d(1,x=Pi..2*Pi,y=0..Pi,coords=spherical,style=surface,image=im1),
  axes=none);

 

Download hemisphere_img.mw

I don't have the book you cited, so I don't know whether your surface-image approach is any easier than simply shading the surface by passing coloring functions to the plotting command.

It isn't clear to me from your wording whether or not you want to avoid use of the mouse (eg. through context-panel actions).

One possibility is to use Equation Labels instead of assignment of the equation to temp names for equations and expressions. You might find that provides for doing "quick" and convenient substitutions in your worksheet, since there is a keyboard acceleration (Ctl-L) for inserting such references.

Or perhaps you are looking for a fully programmatic approach, with code that would work even in a commandline interface. See also the ditto Help page. For example,

restart;

eq1 := a = 3*x+2*y;

       eq1 := a = 3 x + 2 y

eval(eq1, [x=20,y=5]);

            a = 70

eval(eq1, [x=5,y=1]);

            a = 17

expr1 := 4*a-2*b;

      expr1 := 4 a - 2 b

eval(eval(expr1, eq1), [x=5,y=1]);

            68 - 2 b

eval(expr1, eq1);

        12 x + 8 y - 2 b

eval(%, [x=5,y=1]);

            68 - 2 b

 

_Z is a placeholder for the solving-variable inside a RootOf implicit representation of a "root" of the system of equations.

You could try passing the explicit option to the solve command.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

eq3 := 2*lambda*(q[1]+p[1]*exp(t))*(q[2]+p[2])^2*p[1]*exp(t) = s[1]:

eq4 := 2*lambda*(q[1]+p[1])^2*(q[2]+p[2]*exp(u))*p[2]*exp(u) = s[2]:

solve({eq3, eq4}, {t, u});

{t = ln(RootOf(-s[1]+(2*lambda*p[2]*q[1]+2*lambda*q[1]*q[2])*_Z+2*lambda*_Z^2)/((q[2]+p[2])*p[1])), u = ln(RootOf(-s[2]+(2*lambda*p[1]*q[2]+2*lambda*q[1]*q[2])*_Z+2*lambda*_Z^2)/((q[1]+p[1])*p[2]))}

solve({eq3, eq4}, {t, u}, explicit);

{t = ln((1/2)*(-lambda*p[2]*q[1]-lambda*q[1]*q[2]+(lambda^2*p[2]^2*q[1]^2+2*lambda^2*p[2]*q[1]^2*q[2]+lambda^2*q[1]^2*q[2]^2+2*lambda*s[1])^(1/2))/(lambda*(q[2]+p[2])*p[1])), u = ln((1/2)*(-lambda*p[1]*q[2]-lambda*q[1]*q[2]+(lambda^2*p[1]^2*q[2]^2+2*lambda^2*p[1]*q[1]*q[2]^2+lambda^2*q[1]^2*q[2]^2+2*lambda*s[2])^(1/2))/(lambda*(q[1]+p[1])*p[2]))}, {t = ln((1/2)*(-lambda*p[2]*q[1]-lambda*q[1]*q[2]+(lambda^2*p[2]^2*q[1]^2+2*lambda^2*p[2]*q[1]^2*q[2]+lambda^2*q[1]^2*q[2]^2+2*lambda*s[1])^(1/2))/(lambda*(q[2]+p[2])*p[1])), u = ln(-(1/2)*(lambda*p[1]*q[2]+lambda*q[1]*q[2]+(lambda^2*p[1]^2*q[2]^2+2*lambda^2*p[1]*q[1]*q[2]^2+lambda^2*q[1]^2*q[2]^2+2*lambda*s[2])^(1/2))/(lambda*(q[1]+p[1])*p[2]))}, {t = ln(-(1/2)*(lambda*p[2]*q[1]+lambda*q[1]*q[2]+(lambda^2*p[2]^2*q[1]^2+2*lambda^2*p[2]*q[1]^2*q[2]+lambda^2*q[1]^2*q[2]^2+2*lambda*s[1])^(1/2))/(lambda*(q[2]+p[2])*p[1])), u = ln((1/2)*(-lambda*p[1]*q[2]-lambda*q[1]*q[2]+(lambda^2*p[1]^2*q[2]^2+2*lambda^2*p[1]*q[1]*q[2]^2+lambda^2*q[1]^2*q[2]^2+2*lambda*s[2])^(1/2))/(lambda*(q[1]+p[1])*p[2]))}, {t = ln(-(1/2)*(lambda*p[2]*q[1]+lambda*q[1]*q[2]+(lambda^2*p[2]^2*q[1]^2+2*lambda^2*p[2]*q[1]^2*q[2]+lambda^2*q[1]^2*q[2]^2+2*lambda*s[1])^(1/2))/(lambda*(q[2]+p[2])*p[1])), u = ln(-(1/2)*(lambda*p[1]*q[2]+lambda*q[1]*q[2]+(lambda^2*p[1]^2*q[2]^2+2*lambda^2*p[1]*q[1]*q[2]^2+lambda^2*q[1]^2*q[2]^2+2*lambda*s[2])^(1/2))/(lambda*(q[1]+p[1])*p[2]))}

 

Download solve_ex1.mw

ps. Please don't post multiple Question threads for the same example and query.

You can programmatically construct a procedure from the closed-form formula for the general sum.

# general representation of the sum

general:=factor(sum((N+k)^2, k=0..N));

                1                     
     general := - N (N + 1) (14 N + 1)
                6                     

# making a procedure from that formula

P:=unapply(general,N);

    P := N -> (1/6)*N*(N+1)*(14*N+1) 

P(10);

                   2585
(In terms of run-time efficiency, this would be more suitable for the situation that you wanted to compute results for many concrete but differing integer values of N.)
a := {x = -12, y = -23}, {x = -34, y = 87},
     {x = 18, y = 98}, {x = 27, y = 93},
     {x = 45, y = 68}:

map2(op@eval,[x,y],[a]);

      [-12, -23, -34, 87, 18, 98, 27, 93, 45, 68]

The Do command from the DocumentTools module is merely an alternate access point for that module's GetProperty and SetProperty commands.

Those latter two commands are reasonable. Personally I find the syntax of the Do command to be poor. I always use GetProperty and SetProperty instead.

But all three of those commands relate to getting and setting the values of properties of Embedded Components that already exist in the current Worksheet/Document.

Does your sheet contain any Embedded Components (whether inserted manually from the Components palette, or in a Help page opened as working document, or programatically via InsertContent)?

There is currently no .mw file attached to your Question.

Get rid of the evalf calls, which produce floating-point results instead of the exact values.

I suspect you intended a seq call or similar (or perhaps your code snippet is inside some loop).

Eg,

   seq( exp(2*Pi*I*i/3), i = 0 .. 2 );

That is not a bug.

The usual evaluation rules for a procedure call is that the passed arguments are evaluated before the procedure body computes. That is documented.

And so in your second example -- which produces the wrong plot -- you are actually passing the following to the plot command:

f(n);

                      round(n)
              1   (-1)        
              - + ------------
              2      round(n) 
                  n 2         

You have incurred an evaluation of f(n) prematurely, in your second example. That is user error, not a bug. It is similar to this effect,

round(n) mod 2;

               round(n)

There are several ways to do it correctly. You could instead use irem instead of the mod command. You could utilize unevaluation quotes (as shown in your first example) to delay the evaluation of f(n). You could use the operator form calling sequence to the plot command. You could rewrite procedure f so that calling it with a nonnumeric argument would return that same function call unevaluated.

By the way, similar user difficulties arise frequently in Mathematica too, as can be seen in the many similar queries on https://mathematica.stackexchange.com in which ?NumericQ figures in answers.

Put quotation marks around the file reference (filename).

As you have it, it gets parsed as some invalid Maple statements. (In 2D Input the backslash gets parsed as minus, eg. for sets.)

Your attempt at using that command to set a new value is incorrect syntax. You could try it like so,

kernelopts(includepath="C:\\Homes\\testFolder"):

kernelopts(includepath);

             "C:\Homes\testFolder"

That is similar to how kernelopts works for many other of its options.

(Note also that the return value is the previous value of the setting. I terminated that first statement with a full colon, so that aspect could be less confusing.)

1 2 3 4 5 6 7 Last Page 2 of 247