29 Badges

15 years, 222 days

SubstituteAll...

How about StringTools:-SubstituteAll, replacing with the empty string?

s:=" \\left \\int x \\,dx \\left":

StringTools:-SubstituteAll(s,"\\left","");

"  \int x \,dx "

I don't know whether you care about residual white-space,

with(StringTools):
SubstituteAll(SubstituteAll(SubstituteAll(s," \\left ",""),
"\\left ",""),
" \\left","");

"\int x \,dx"

call the procedure...

After issuing stopat(proc1), you need to actually run an example that calls that proc1 procedure. Then the debugger will appear, when the computation invokes that procedure.

alternatives...

I don't think that you should compute the plot as you describe with a fixed z-step-size, eg. by passing the adaptive=false and say numpoints=floor((9-2)/0.5)+1 options to the plot command (modifying how Tom called it). The result would be very coarse.

Tom's suggestion utilizes the default adaptive plotting of the plot command, sampling Z over the range -5..5 according to where it ascertains that more points would help. (This is true whether the z-range is 2..9 or -5..5.)

The computing time for Tom's adaptive plot call can be roughly halved by memoization (eg. storing the fsolve results rather than calling it twice, once for each of x and y).

But if you're willing to experiment with (or compute) the x- and y-ranges then for the example Tom invented even smoother curves can be obtained, and much quicker, eg. through the implicitplot command.

There are also regions in which the plots from the two methods visibly differ (eg. where the curves become steep/multivalued). I leave it to you to judge.

 > restart;
 > plots:-setoptions(size=[400,400]):
 > eqns:=[2*x+3*cos(y)+z^2=0, sin(x)+y+2*z=1];

 > str:=time[real](): T:=eliminate(eqns, [z]); P:=plots:-implicitplot(T[2], x=-12..12, y=-12..12): xydat:=plottools:-getdata(P)[-1]: zdat:=<[seq(eval(eval(z,T[1]),[x=xydat[i,1],y=xydat[i,2]]),             i=1..op([1,1],xydat))]>: plot( [, ],       thickness=2, labels=[z, ""] ); (time[real]()-str)*'seconds';

 > func:=proc(Z) option remember;         if not Z::numeric then return 'procname'(args); end if;         fsolve(eval(eqns, z=Z));       end proc:
 > forget(func): str:=time[real](): plot( [ 'eval'(x,func(Z)), 'eval'(y,func(Z)) ], Z=-5...5,       thickness=2, labels=[z, ""] ); (time[real]()-str)*'seconds';

 > forget(func): str:=time[real](): plot( [ 'eval'(x,func(Z)), 'eval'(y,func(Z)) ], Z=2...9,       thickness=2, labels=[z, ""] ); (time[real]()-str)*'seconds';

 > str:=time[real](): a := minimize( solve(T[1][1],y), x=-40..40, z=2..9): b := maximize( solve(T[1][1],y), x=-40..40, z=2..9): T:=eliminate(eqns, [z]); P:=plots:-implicitplot(T[2], x=-40..40, y=a..b): xydat:=plottools:-getdata(P)[-1]: zdat:=<[seq(eval(eval(z,T[1]),[x=xydat[i,1],y=xydat[i,2]]),             i=1..op([1,1],xydat))]>: plot( [, ],       thickness=2, labels=[z, ""] ); (time[real]()-str)*'seconds';

 >

Download impl_fun.mw

Is there a special reason why you haven't provided us with your full example, so that we could test out ideas?

another way...

Editing your original.

In the Maple GUI the results from the loop are actually shown for all three of i=1..3 . It's a quirk of this forum that they don't each render when inlined here.

You don't have to use a loop, of course. But I prefer indexed L[i] to concatenated L||i .

Download Lagrange_interpolation_ac.mw

Perhaps more graceful would be a revision to procedure Lg, such that it accepted lxi as an argument, and deduced n=numelems(lxi).

(This seems a tiny bit tidier than your followup A_little_example_ac.mw )

fieldoptions...

You can get more arrows while still using the VectorField command from the Student:-VectorCalculus package (as you've done in your attachment).

You can do that by supplying the fieldoptions option to the VectorField command, using the grid suboption in the list in the right-hand-side.

Adjusting your example,

 >
 >
 >
 >
 >
 >
 >

 >

Download How_to_add_more_arrows_acc.mw

You can read about this in the Help page for the VectorField command. When you encounter a difficulty with some command then a good place to look is its Help page (also available within the Maple GUI itself).

:-changecoords...

The unwith command is not robust if called within a procedure. (Similarly for the with command.)

Try calling it instead like,

:-changecoords(....)

which is a reference to the global name due to the colon-minus prefix. That is in contrast to the unadorned name which may have been rebound to some package's export's name, by some prior call to with.

2D parsing issue...

It appears to be a problem with the 2D parser.

If I place the mouse cursor at on the a[0] in that 10th row's existing input, and then delete the space between it and the coefficient 2, then the expected menu appears in the context panel and the context-menu actions work.  Here is the attachment that I got from that.
Table_solve_issue_ac.mw
The same happens if instead I delete the space following any of the other instances of 2 in that 10th row input.

I could also insert a new, empty 10th Table row, between the old 10th and 9th rows, and successfully retype the whole expression in 2D Input mode, and have it work. I ran into issues with copy&paste.

I don't know whether this problem with 2D Input is actually dependent upon it being a 10th (or later) row.

A GUI Worksheet/Document Table is not the same as the table or rtable Maple (kernel/engine) data structures. So kernelopts(rtablesize) should be irrelevent here.

interpolation...

If you have only the data values (but no longer have the original function) then you can interpolate.

In the following code the colors for the pointplot are (only) interpolated from the hue values of the precomputed (image) data. The function f is not referenced directly for computing the colors in the pointplot; f was used only in pregenerating the image.

 > restart;
 > (m,n):=100,150; (a,b,c,d):=-1,1,-2,2; X:=Vector(m, (i)->a+(b-a)*(i-1)/(m-1),datatype=float[8]): Y:=Vector(n, (i)->c+(d-c)*(i-1)/(n-1),datatype=float[8]):

 > f:=z->sin(z); Z:=Matrix(m,n,(i,j)->argument(f(X[i]+I*Y[j])),datatype=float[8]):

 > H:=ImageTools:-FitIntensity(Z): SorV:=Matrix(m,n,1.0): img:=ImageTools:-Create(m,n,3): img[..,..,1]:=360*H: img[..,..,2]:=SorV: img[..,..,3]:=SorV:
 > plots:-display(   ImageTools:-Preview(ImageTools:-Scale(ImageTools:-Rotate(ImageTools:-HSVtoRGB(img),left),                                         1..ceil((d-c)/(b-a)*300),1..300)),   scaling=constrained, size=[ceil(1.7*300),ceil((d-c)/(b-a)*300*1.7)],   axes=none, lightmodel=none);

 > F:=Interpolation:-SplineInterpolation([X,Y],H):
 > numdata:=2000: data := Matrix(,                datatype=float[8]):
 >
 > plots:-pointplot(data[..,1..2], symbolsize = 10, symbol = solidbox,                  color = COLOR(HUE, F(data[..,1..2])), scaling=constrained,                  axes=box, labels=[,], size=[300,ceil((d-c)/(b-a)*300)] );

 > # another way, for original f, as visual check. plots:-densityplot(argument(f(x+I*y)),x=a..b,y=c..d, grid=[150,150],                    colorstyle=HUE,style=surface,                    scaling=constrained, axes=box,                    labels=[,], size=[300,ceil((d-c)/(b-a)*300)]);

 > FL:=Interpolation:-LinearInterpolation([X,Y],H): plots:-listplot( F(data[..,1..2]) - FL(data[..,1..2]), size=[500,100] );

 >

datainterp.mw

Note that the extracted submatrix data[..,1..2], and F(data[..,1..2]) both have datatype=float[8], for efficiency in constructing the COLOR plotting substructure.

If the source image resolution is known to be fine enough you might alternatively try linear (rather than spline) interpolation.

Naturally, if you extract H from an HSV image (in the ImageTools sense) then you could accomodate the scaling factor of 360, to get H in the 0..1 range for plotting.

[edit. I've since corrected some use of the dimensions, and re-attached...]

GUI performance...

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

something old...

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

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).

theta assigned...

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

something like this?...

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] ];

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

 > M[rows, ..];

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 ];

like this?...

Is this the kind of effect you're after?

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.

easier now...

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.

like this?...

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

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