acer

32490 Reputation

29 Badges

20 years, 9 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Thomas Richard Did you intend something more like this?


restart:

with(InertForm):

A := (cos(sqrt(2)*t)-cos(omega*t))/(omega^2-2):

AA := `%*`(1/denom(A),numer(A)):

Display(AA, inert=false);

(cos(sqrt(2)*t)-cos(omega*t))/(omega^2-2)

Value(AA);

(cos(2^(1/2)*t)-cos(omega*t))/(omega^2-2)

 


Download inertnumerdenom.mw

As usual, vv is correct on all fronts. Thank you, sir.

Have you tried declaring n as a local and assigning it appropriately? Or passing it in, if the dimensions of the rtable will depend upon it? And (long shot) without the option autocompile?

How about the inmem=false option for Compile:-Compile, assuming that you have a MSVC++ that allowed Compiler:-Compile to work on your older Maple versions for your 64bit Windows.

It compiles and works for me on my 64bit Maple 2016.1 on 64bit Windows 7 Pro, using suitable local n assigned to the right value, or picking up a global n assigned the integer value used to build the rtables. It also works for me with or without the inmem=false option.

I could only get it to produce an error if n had no value for it to access. But it was a related error message. I haven't been able to reproduce the error message you show.

acer

@Carl Love For fun. Adjust to taste.

clexplore.mw

@vv The delay property of a Plot Component relates to playing a "traditional" animation within the component. But Explore plays (renders) the individual plots only as fast as it can generate them, and does not precompute a sequence of frames (traditional animation). So Explore is creating the plots and playing them on demand, so to speak. As far as I know the delay property of a Plot Component does not affect the rendering when the value property is simply set to a particular plot (which is what Explore does, repeatedly).

Above I was talking about inserting a call to Threads:-Sleep, inside the procedure P which is Explored.

If, on the other hand, you have a traditional animation (seq of plots, in say a _PLOTARRAY structure, the kind that can be played using say plots:-display and option insequence=true) you can alternatively play it programatically by setting it as the value property of an embedded Plot Component and then setting the component's play property to true. If you do that then you could also set the component's delay property programmatically. See here for an example of that.

Another way to play a traditional animation within an embedded Plot Component is to programatically embed the whole thing into a worksheet. See a relevent example in the ?examples,ProgrammaticContentGeneration help page of Maple 2016, where it defines (in a code-edit region) and then calls an appliable module named EmbedAnim. I suppose that command could be enhanced to also provide a dial for the embedded Plot Component's delay property.

As Carl mentions in this thread, a traditional animation (plots:-animate(...) or plots:-display(..,insequence=true)) has the virtue that it can be readily exported to animated .gif file. And, with all the frames being precomputed it can usually play them quite quickly. Another benefit is that, with the frames all computed in advance, the total view is known (but sometimes that's a drawback, that the view is fixed). With Explore the view option must be supplied, or else it can change.

In Maple 2016 the Explore command has new options to "record" plots it generates to a supplied global name, used as a table. So, once one obtains desirable values of various fixed parameters then a traditoinal animation can be computed by "playing" the exploration on the remaining animated parameters. The global name of the table used to record the explored plots can then be converted to a traditional animation.

@Markiyan Hirnyk To make it slower you could add a call to Threads:-Sleep, inside `P`. The duration to sleep could even be a parameter of `P` and itself a non-animated Explore parameter. It might be nicest if the mechanism was as fast and efficient as possible, to give any sleep-delay control even more power and choice. 

@Carl Love Yes, thanks, I've seen it. I like the name Starlings.

It reminds me of another acceleration trick that might be possible with that Explore above.

vv's code acts inplace on `x` and `v`. It should be possible to create a 2D `PLOT` structure with a (uneval'd?) reference to a named n-by-2 float[8] Matrix whose columns are the x and y Vectors. And the first two arguments to `step` could instead be that single n-by-2 Matrix.

Basically, I mean that my procedure P could return PLOT(M,...) or whatever. So the kernel wouldn't have to garbage collect each plot structure's data rtables. Just an idea. And nothing else changes in the PLOT structure, so there's little need to have to call the Library `plot` command each time. It's only the data that changes -- updated inplace by `step`.

I used that technique once in an old mapleprimes thread, which I can't find now. I don't think it was this, because I hazily recall Joe Riel commenting.

Also, if I recall the Statistics:-Sample command now offers inplace re-use of a Vector container. So F and E might be re-used as well.

Just ideas. I'm not sure how much speedup there might be.

 

@Markiyan Hirnyk I haven't made Carl's suggested adjustments.

Also, certain parameters like n and mu could be made other (non-animated) parameters of the call to Explore.

The key thing is that this doesn't have `num` a fixed number of distinct frames, as does a looping (cycling) traditional animation.

It could also be all put into a single appliable module. As an exploration is could be easily made into a so-called "MathApp".

restart;

FE:=proc() global F,E; #friend,enemy
  F,E:='LinearAlgebra:-RandomVector(n,generator=1..n,datatype=integer[4])' $2;
end proc:

step:=proc(x::Vector(datatype=float[8]),y::Vector(datatype=float[8]),
      E::Vector(datatype=integer[4]),F::Vector(datatype=integer[4]))
local i::integer[4],ex::float[8],ey::float[8],ed::float[8],
                    fx::float[8],fy::float[8],fd::float[8];
for i to n do
  ex:=x[E[i]]-x[i];ey:=y[E[i]]-y[i]; ed:=sqrt(ex^2+ey^2);
  fx:=x[F[i]]-x[i];fy:=y[F[i]]-y[i]; fd:=sqrt(fx^2+fy^2);
  x[i] := 0.995*x[i] - 0.01*ex/(ed+0.01) + 0.02*fx/(fd+0.01);
  y[i] := 0.995*y[i] - 0.01*ey/(ed+0.01) + 0.02*fy/(fd+0.01);
od;
end proc:
cstep:=Compiler:-Compile(step):

P:=proc()
  to mu do cstep(x,y,E,F) od;
  if rand(1..10)()=1 then FE() fi;
  plot(x,y,style=point,background="#333333",axes=none,view=[-2..2,-2..2],
       symbolsize=2,color="DarkOrange");
end proc:

n:=1000: mu:=10:
x,y:='LinearAlgebra:-RandomVector(n,generator=-1.0 ..  1.0,datatype=float[8])' $2:
FE():

Explore(P(xx),parameters=[[xx=0..1,shown=false,animate]],autorun,loop);

@Carl Love Is not view a global plot option, and thus covered on the ?geometry,draw help page by the bullet point about globalopts in the Description section?

I find it poor that the Calling Sequences section on that help page don't show the general forms like

  draw([ obj_1( localopts_1 ), ..., obj_n( localopts_n )], globalopts)

as mentioned in the second bullet point of the Description section.

My first attempt too was to try and pass the double default view, and it seems a bug that doesn't work.

Are you separating them by a comma?

If you separate them by a space, in 2D Input, then that will get interpreteted as multiplication.

acer

@Carl Love The member has made little effort to figure out the Maple equivalents for what appears to be Matlab code.

For example add(x, x=spin) would add all the elements of Matrix spin, instead of his sum(sum(spin)). It's unclear to me whether exp(-DeltaE) is intended as a matrix-exponential or the elementwise operation (it's unclear that the member knows Matlab well either), especially since what seems like it ought to be an assignment to p doesn't use that result later. And if rand(N)<trans is supposed to be evaluated as boolean to 0 or 1 (false or true) then how to compare rand(N) to 0.1 numerically even it it were made proper syntax for a RNG call within a call to `if`? And what is the initial value of trans?

It's a bit of a shambles.

 

For longer commentary I use Shift-Enter to get a new line (but still within the same Execuction Group) and then Ctrl-t to toggle to text mode.

That allows me to put commentary (in black by default) either above or below the code. And it even allows me to put typeset non-executable 2D Math inlined into the text paragraphs.

acer

@Doug Meade In 2D Math mode, the keystrokes would be (ignoring my whitespace),

| | V | | <ctl><shift><_>2

By <ctl><shift><_> I mean simultaneously pressing Control-Shift-underscore.

The point is that the norm `p`=2 has to be in a subscript. And it cannot be an atomic double-underscore subscript.

That works for me in Maple 2016, and the result  for V=Vector(1,2,3]) is sqrt(14).

Is this parsing rule available for modification by the Typesetting:-RuleAssistant? I didn't see it there. (...and I think I may have a handle on how to list off all that Assistant's candidates, but as mentioned I am not yet seeing it there).

 

It's not clear whether you have some initial-value problem to solve numerically, or have been given the specific task of writing your own code for that (say, as coursework or homework).

If you do not need to write your own scheme then simply use the dsolve command with the numeric option (and do not force a classical method or a fixed stepsize, without justificsation, as the solver can do often do better than that automatically). Start by reading the help page for topic dsolve,numeric .

acer

@Kitonum If you change that k4 assignment to instead  use h rather than h/2, so as to be  k4:=f(t[n]+h,y[n]+h*k3)  then (if Digits=15 say) you'll get results which concur with the following stock command's results:

restart;

K:=dsolve({diff(y(t),t)=sin(t),y(0)=1},numeric,method=classical[rk4],
           stepsize=0.1,output=Array([seq(0..5,0.1)])):

convert(K[2,1],listlist);

 [[0., 1.], [0.1, 1.00499583489549], [0.2, 1.01993342285110], 
  [0.3, 1.04466351242567], [0.4, 1.07893900873887], [0.5, 1.12241744236150], 
  [0.6, 1.17466439115686], [0.7, 1.23515782088314], [0.8, 1.30329330118699], 
  [0.9, 1.37839004487179], [1.0, 1.45969771009834], [1.1, 1.54640389755243], 
  [1.2, 1.63764226767027], [1.3, 1.73250119681705], [1.4, 1.83003288592892], 
  [1.5, 1.92926283060797], [1.6, 2.02919955804802], [1.7, 2.12884453350318], 
  [1.8, 2.22720213731696], [1.9, 2.32328961282474], [2.0, 2.41614688573355], 
  [2.1, 2.50484615686701], [2.2, 2.58850117242805], [2.3, 2.66627607915385], 
  [2.4, 2.73739377588537], [2.5, 2.80114367810526], [2.6, 2.85688881786345], 
  [2.7, 2.90407220815036], [2.8, 2.94222240812701], [2.9, 2.97095823360601], 
  [3.0, 2.98999256571798], [3.1, 2.99913521970836], [3.2, 2.99829484520064], 
  [3.3, 2.98747983893912], [3.4, 2.96679826089140], [3.5, 2.93645675454889], 
  [3.6, 2.89675848221342], [3.7, 2.84810009589965], [3.8, 2.79096777411931], 
  [3.9, 2.72593236414619], [4.0, 2.65364367829889], [4.1, 2.57482400123093], 
  [4.2, 2.49026087310127], [4.3, 2.40079922073331], [4.4, 2.30733291538543], 
  [4.5, 2.21079584148481], [4.6, 2.11215256556296], [4.7, 2.01238869862574], 
  [4.8, 1.91250104825405], [4.9, 1.81348765883193], [5.0, 1.71633783941702]]
First 301 302 303 304 305 306 307 Last Page 303 of 595