acer

32385 Reputation

29 Badges

19 years, 338 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

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

@Wtolrud I don't understand what keystrokes you think got made there.

In 2D Math entry mode two ways to get such a (typeset) pretty-printed Norm call as input include: using the palettes, or using command-completion templates.

Are you referring to command-completion?

If so then see the following help topics,

  worksheet,expression,completecommand

  Typesetting,RuleAssistant

I don't know of a nice entry-level command for getting all the known (system) 2D Math completion rules, in such a way that you could manipulate it programmatically. The RuleAssistant offers access to them via drop-menus.

acer

@Carl Love The stock Matrix command can flatten too, if the Matrix entries in lists of lists.

The angle-bracket constructors won't allow application of a new datatype. Sure, he could have put datatype=float on each of the entry Matrices made by `helper2`, say. (We don't know for sure whether was desired or allowed.)

IMO simplest solution is build the Matrix B using lists and seq instead of the initializer. Using the Flatten command on the Matrix of Matrices entails building the Matrix of Matrices (in the imperfect fashion) and then repairing it with the custom Flatten procedure. But the Matrix command can build the final result immediately if called differently, with specified datatype, without need for fix up.

@Carl Love I just wondered whether it made a difference, in the case that it was to be re-used. Perhaps not relevant here.

@Carl Love Can that `All` be a local of an appliable module, so as to be created in advance and re-used?

@Mac Dude You can mark an execution group with a bookmark, and then elsewhere in the sheet you can create one or more hyperlinks to it.

For example, in this attachment if you left-click on the text word link then it will expand and jump to the bookmarked section. bkmrk.mw

First 299 300 301 302 303 304 305 Last Page 301 of 592