acer

32400 Reputation

29 Badges

19 years, 344 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@nMaple Maple will export such animations as animated .gif files. You can do that by right-clicking on the plot, or with some programmatic commands.

Here is leaner code. It executes faster, saves to a much smaller file, and is a bit less hard on the poor Java GUI. The idea is that each of the three pieces is a surface which is linear in z. So the plot3d calls only need to use a value of 3 for the grid, in that dimension.

restart;

fA := Z->plot3d([2*cos(phi), 2*sin(phi), z], z = 0 .. Z, phi = 0 .. 2*Pi,
                style=surface, orientation=[-180,70,30], grid=[3,41]):

# Now force the highest value that matters into fA and store that in
# fA's remember table. This makes `h` not have to compute fA when Z>5.

fA(5) := fA(5):

fB := Z->plot3d([8*cos(phi), 8*sin(phi), z], z = 10 .. Z, phi = 0 .. 2*Pi,
                style=surface, orientation=[-180,70,30], grid=[3,41]):

# Now force the highest value that matters into fB and store that in
# fB's remember table. This makes `h` not have to compute fC when Z>20.

fB(20) := fB(20):

fC := Z->plot3d([(2+6*((z-5)*(1/5)))*cos(phi),
                 (2+6*((z-5)*(1/5)))*sin(phi), z],
                 z = 5 .. Z, phi = 0 .. 2*Pi,
                 style=surface, orientation=[-180,70,30], grid=[3,41]):

# Now force the highest value that matters into fC and store that in
# fC's remember table. This makes `h` not have to compute fC when Z>10.

fC(10) := fC(10):

h := Z->plots:-display(`if`(Z>10,fB(min(Z,20)),NULL),
                       `if`(Z>5,fC(min(Z,10)),NULL),
                       `if`(Z>0,fA(min(Z,5)),plot3d([[0,0,0]])),
                       axes = normal, scaling = constrained):

# A first way: produce a sequence of plots and display with insequence option.

S := CodeTools:-Usage( seq( h(t), t=0..20, 0.5 ) ):

memory used=8.20MiB, alloc change=32.00MiB, cpu time=577.00ms, real time=707.00ms, gc time=31.20ms

# This forms an animation structure. We could display it right away,
# or we could assign it to a name (such as K) and display that later.

K := plots:-display( S, insequence ):
op([1,0],K);

ANIMATE

K;

# A second way: Let the plots:-animate command do both steps above.
# And, again, we could assign it to a name (such as A) and display that later.

A := CodeTools:-Usage( plots:-animate( h, [t], t=0..20, frames=41 ) ):
op([1,0], A);

memory used=10.62MiB, alloc change=0 bytes, cpu time=437.00ms, real time=891.00ms, gc time=0ns

ANIMATE

A;

 


Download athing2.mw

 

@nMaple Please let me know or not, whether this is the kind of thing you want to do.

(This file is 25MB, since it has the 40 frame animation saved from two methods.)


restart;

fA := Z->plot3d([2*cos(phi), 2*sin(phi), z], z = 0 .. Z, phi = 0 .. 2*Pi,
                style=surface, orientation=[-180,70,30]):

# Now force the highest value that matters into fA and store that in
# fA's remember table. This makes `h` not have to compute fA when Z>5.

fA(5) := fA(5):

fB := Z->plot3d([8*cos(phi), 8*sin(phi), z], z = 10 .. Z, phi = 0 .. 2*Pi,
                style=surface, orientation=[-180,70,30]):

# Now force the highest value that matters into fB and store that in
# fB's remember table. This makes `h` not have to compute fC when Z>20.

fB(20) := fB(20):

fC := Z->plot3d([(2+6*((z-5)*(1/5)))*cos(phi),
                 (2+6*((z-5)*(1/5)))*sin(phi), z],
                 z = 5 .. Z, phi = 0 .. 2*Pi,
                 style=surface, orientation=[-180,70,30]):

# Now force the highest value that matters into fC and store that in
# fC's remember table. This makes `h` not have to compute fC when Z>10.

fC(10) := fC(10):

h := Z->plots:-display(`if`(Z>10,fB(min(Z,20)),NULL),
                       `if`(Z>5,fC(min(Z,10)),NULL),
                       `if`(Z>0,fA(min(Z,5)),plot3d([[0,0,0]])),
                       axes = normal, scaling = constrained):

# A first way: produce a sequence of plots and display with insequence option.

S := CodeTools:-Usage( seq( h(t), t=0..20, 0.5 ) ):

memory used=10.28MiB, alloc change=32.00MiB, cpu time=952.00ms, real time=1.15s, gc time=31.20ms

# This forms an animation structure. We could display it right away,
# or we could assign it to a name (such as K) and display that later.

K := plots:-display( S, insequence ):
op([1,0],K);

ANIMATE

K;

# A second way: Let the plots:-animate command do both steps above.
# And, again, we could assign it to a name (such as A) and display that later.

A := CodeTools:-Usage( plots:-animate( h, [t], t=0..20, frames=41 ) ):
op([1,0], A);

memory used=12.70MiB, alloc change=2.64MiB, cpu time=1.09s, real time=1.32s, gc time=0ns

ANIMATE

A;

 


Download athing1.mw

@nMaple I'm pretty sure that you misunderstood my meaning, or at best misapplied the idea I was trying to convey.

That name is a bit unusual. It seems to be `Νu` rather than just Nu, so I assigned it to `var` to avoid cut&paste issues, etc.

@nMaple In Maple 17 you could try it as, say,

A := plot3d([2*cos(phi), 2*sin(phi), z], z = 0 .. 5, phi = 0 .. 2*Pi):

B := plot3d([8*cos(phi), 8*sin(phi), z], z = 10 .. 20, phi = 0 .. 2*Pi):

C := plot3d([(2+6*((z-5)*(1/5)))*cos(phi), (2+6*((z-5)*(1/5)))*sin(phi), z],
             z = 5 .. 10, phi = 0 .. 2*Pi):

plots[display](A, B, C, axes = normal, scaling = constrained,
               style=surface, glossiness=1.0, lightmodel=Light4);

@tomleslie It is not true what you wrote in the other thread, that the way with uses LA=LinearAlgebra; is incorrect. There are several valid ways of utilizing uses. The problem in the earlier thread was that neither valid way was being used for one call (to Transpose).

The problem(s) here are different. The while i<>j look like a problem(in at least understanding). Also the abs(x-p) should probably be LinearAlgebra:-Norm(x-p) or similar. I haven't considered further.

@sunflower You need that to be LinearAlgebra:-Transpose or LA:-Transpose (since for the latter you are already doing uses LA=LinearAlgebra.

I don't really understand why you are doing those LinearSolve calls on hard-coded b, but perhaps you intend to do something more general with it later on. You certainly don't need to print(x) if you are just going to return x.

What do you expect to happen if any of the L[i,i] are zero?

acer

@Carl Love It's possible that this too would produce the kinds of Matrix he's after. Eigenvalues will return purely real values in this case. Statistics:-Sample is fast enough that this might do (even if tweaks are required).

GUE:= proc(N::posint)
uses LA= LinearAlgebra, ST= Statistics;
local R,G1,G2,C,H;
     R:= ST:-Distribution(Normal(0,1));
     G1:= ST:-Sample(R, [N,N]);
     G2:= ST:-Sample(R, [N,N]);
     H:= Matrix(LA:-MatrixAdd(G1,G2,1,I),shape=hermitian);
     convert(LA:-Eigenvalues(H)/sqrt(4.0*N), list)[];
end proc:

Similalry for the second curve,


restart:

ff:=-1+18*(sinh(9*x-9/2)-sinh(3*x-477/2))^2/(9*cosh(9*x-9/2)+cosh(3*x-477/2))^2;

-1+18*(sinh(9*x-9/2)-sinh(3*x-477/2))^2/(9*cosh(9*x-9/2)+cosh(3*x-477/2))^2

evalf[1000](convert(series(ff,x,6),polynom)): evalf[5](%);

17.000+0.51222e-98*x-0.15376e-97*x^2+0.30715e-97*x^3-0.46182e-97*x^4+0.55156e-97*x^5

[evalf[1000](eval(ff,x=-4)-17), evalf[1000](eval(ff,x=4)-17)]:
evalf[5](%);

[-0.22618e-88, -0.59152e-82]

yoffscal := 1e-90:
yticks := [ seq( yadj*yoffscal=sprintf("19%+.1e",yadj*yoffscal), yadj=-10..10 ) ]:
Digits := 300:

plot( ff-17, x=-4..4, ytickmarks=yticks, view=-yoffscal*10..0 ) ;

yoffscal := 1e-100:
yticks := [ seq( yadj*yoffscal=sprintf("19%+.1e",yadj*yoffscal), yadj=-10..10 ) ]:
Digits := 300:

plot( ff-17, x=-4..4, ytickmarks=yticks, view=-yoffscal*10..0 ) ;

plot( ff-17, x=-4..4, axis[2]=[mode=log] ) ;

plot( ff-17, x=-4..4, axis[2]=[mode=log], view=-1e-96..0 ) ;

 


Download flat2.mw

@Adri van der Meer In the Standard GUI one could also use the typeset symbol for arc-degrees.

sol:=dsolve({diff(y(x),x,x)+y(x)=0,y(0)=0,D(y)(0)=0.5},numeric):

plots:-odeplot(sol, x=0..10,
               tickmarks=[[seq(i*Pi/2=(i*180/2*`&deg;`),i=1..8)],default]);

@ecterrab The new version is nicer, thanks.

The code inlined in your earlier Comment, now revised and updated, no longer shows the earlier assignment to `print/+`. You might wish to consider adding that print extension as before, so that some behaviour related to automatic simplification appears prettyprinted as before.

restart:

__fixplus:=module() option package; export `+`; end module:

`print/+`:=eval(:-`+`):

with(__fixplus):

macro(__fixplus:-`+`=:-`+`):

'1/2*(x+y)';

                                  1     1  
                                  - x + - y
                                  2     2  

Note that automatic simplification did not occur above. It merely seemed to, due to the printing mechanism.

lprint(eval(%,1));
  (1/2)*(x+y)

The case of procedure bodies is improved over before, to be sure. It's not exactly the same now as in stock Maple, though. Calls to infix `+` in the proc body are now calls to prefix :-`+`. And here too without automatic simplification.

proc(a,b) 1/2*(a+b); end proc;

                     proc(a, b) 1/2*:-`+`(a, b) end proc;

This is an interesting way to disable a class of automatic simplifications.

@vv My earlier point was that rebinding `+` will break worksheets and top-level code containing such instances of the name `+` in calls to convert and type specfunc and frontend, and that it's not been shown that there are not other ways that top-level code with break either.

Suppose you load the package which redefines `+`. And then you create a procedure proc(a,b) a+b; end proc. And then you save that in a .mla archive and redististribute it to someone else. It will then fail to work for them, since the procedure they have in the .mla is actually proc(a, b) M:-`+`(a, b) end proc. In other for this to work the original would have to be written as proc(a,b) :-`+`(a,b); end proc. So not only would the example need to be fixed by editing, but it would be onerous to write all sums like that.

So it's not just that convert(...,`+`) would break, at the top level.

It was not difficult to think of these examples. It's the examples that I have not yet imagined that worry me more.

@vv You've conflated two ideas. One idea (from Christopher2222) was to always load the Physics package up front. That will cause `*` to be rebound, and break examples like convert([1,2,3], `*`) until edited to use :-`*` instead.

Edgardo's suggestion was to use a module that rebound only `+`, and that does not affect your convert example involving `*`. It works as before.

I do not see loading Physics as fixing the problem, anyway. Note that Physics does not export `+`. I suspect that the original and some other examples succeed after loading Physics merely by some quirk. It does not appear to provide a general workaround. Consider,

restart:
with(Physics):

expr2:=x1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+t16
       +t17+t18+t19+t20+t21+t22+y0-y0+t28;

     expr2 := t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14

           + t15 + t16 + t17 + t18 + t19 + t20 + t21 + t22 + t28 + x1

expr2:=x1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+t16
       +t17+t18+t19+t20+t21+t22+y0-y0+t28;

     expr2 := t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14

           + t15 + t16 + t17 + t18 + t19 + t20 + t21 + t22 + t28 + x1 + t28 + x1

kernelopts(version);

           Maple 2015.0, X86 64 LINUX, Feb 17 2015, Build ID 1022128

 

@ecterrab Loading the suggested package module, as given, will break some existing top-level user code. [NB. The suggestion module has been subsequently revised, in the Comment above. I use the original M below.]

M:=module() export `+`; global `print/+`; option package;
    `+`:=()->:-`+`(args); `print/+`:=()->:-`+`(args);
   end module:
with(M):

convert([1,2,3],`+`);
Error, unrecognized conversion

So the top-level code would have to be edited to be like, say,

convert([1,2,3],:-`+`);
                               6

So, having rebound `+` in that way, one then has to be concerned about other purposes that the name `+` serves, and top-level instances of all such in one's code.

Here's another example.

frontend(expand, [sin(a+b)+cos(a+b)],
         [{`+`,`*`,'specfunc(anything,sin)'},{}]);
Error, type `+` does not exist

frontend(expand, [sin(a+b)+cos(a+b)],             
         [{:-`+`,`*`,'specfunc(anything,sin)'},{}]);

                  sin(a) cos(b) + cos(a) sin(b) + cos(a + b)

Sure that could be handled (without needing to search through and edit old code and worksheets) by also adding a type in the fix. But what other problems will there be? How does one know that all have been identified and corrected?

I will wait for the kernel update, to fix my Maple 2015.

Could one layer of function call be avoided, in this module? I mean, something like,

__fixplus:=module() option package; export `+`; `+`:=eval(:-`+`); end module:
`print/+`:=eval(:-`+`):
with(__fixplus):
First 317 318 319 320 321 322 323 Last Page 319 of 592