Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 356 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

Your Question has no attached files.

@nm Sorry, you're right about the evaluation order. My Answer is nonsense.

@janhardo I'm not sure what you're asking, but a procedure can return any number of values:

Simple:= proc() return 1, 2, 3 end proc;
a, b, c:= Simple():
a;
b;
c;

If this is what you mean by "split", then yes, when a procedure returns multiple values, they can be split. But the number of variables on the left side of := needs to be either 1 or exactly the same number of values as the procedure returns.

I always put multiple return values in parentheses for clarity:

Simple:= proc() (1,2,3) end proc: #"return" is optional.
(a, b, c):= Simple();

@jalal I realize that this is problematic because of the variation of scaling, but it does allow exportation as a GIF:

plots:-display(
    seq(PlotExample(LSKoch, a), a= 1..5),
    insequence, axes= boxed, tickmarks= [0,0]

);
);

It would be possible to fix the scaling, but it may be easier to reprogram it from scratch, akin to this Koch snowflake animation that I wrote a while ago:
 

restart:

N:= 6: #number of iterations

#Rotate point P by angle theta around point Q:
Rot:= theta-> (P,Q)->
    local s:= sin(theta), c:= cos(theta):
    (P-Q).<c, s; -s, c> + Q
:

Rot120:= Rot(2*Pi/3): #the only rotation angle that we need

#Select a point on line segment PQ:
BetweenPt:= (P,Q,r)-> P*(1-r) + Q*r:

#Replace line segment __ with _/\, i.e., put a notch in the middle:
Notch:= (P,Q)->
    local P1:= BetweenPt(P,Q,1/3);
    (P, P1, Rot120(P,P1), BetweenPt(P,Q,2/3))
:

Pts[1]:= <seq(<cos(2*Pi/3*k) | sin(2*Pi/3*k)>, k= 0..3)>:

for k to N do
    Pts[k+1]:=
        <seq(Notch(Pts[k][j], Pts[k][j+1]), j= 1..3*4^(k-1)), <1|0>>
od:

plots:-display(
   seq(plot(Pts[k])$9, k= 1..N+1), insequence,
   thickness= 0, scaling= constrained, axes= none
);

SegmentLength:= n-> 3^(3/2-n):

SegmentCount:= n-> 3*4^(n-1):

Perimeter:= n-> 3^(5/2-n)*4^(n-1):

Area:= n-> 3^(1/2)*(6-(4/9)^(n-2))/5;

 

``

Download vonKoch.mw

 

 

@janhardo When the returned value of a procedure appears immediately before (or on the line immediately before) the end proc, then it's not necessary to explicitly use the word return; it's optional, and a great many Maple programmers omit it. However, some believe in always using it for clarity.

@jalal I meant

Explore(PlotExample(LSKoch, a), a= 1..5, animate);

@nm Yes, certainly a mess can be made from this, and my procedure doesn't check for numerous invalid forms. The only benefit that I see from this is that it allows many problems to be entered in a form somewhat equivalent to how they appear in source materials, to wit:

F(x,y)dx + G(x,y)dy = 0

becomes

F(x,y(x))*D(x) + G(x,y(x))*D(y(x)).

It's a purely syntactic transformation---no algebra required.

And note that D(x), D(y(x)), etc., is already valid Maple syntax, even though it doesn't really mean anything to Maple. 

@nm Surely I could write a little procedure (I'm thinking 10 lines or less) that converted from the OP's form to Maple's standard form. The form 

F(x,y)dx + G(x,y)dy = 0 

is standard for some textbook problems, so it's quite reasonable for CAS to support it.

@acer Thanks for spotting that. I meant

T:= unapply(x - f(x)/D(f)(x), x)

@emendes I don't believe that, unless someone whose knowledge I trust can explain on here (MaplePrimes) exactly why it's not threadsafe. Otherwise, it just seems to me like someone parroting a stock answer to you. Here's the complete code of index:

index:= E-> E[args[2..]]:

So, replace that with your own version:

Index:= E-> E[args[2..]]:

That doesn't use any commands that are not listed at ?threadsafe.

Please try my idea with Grid:-Wait().

 

@emendes 

There are two Questions here:

  • You have a computation A that is not threadsafe that is being done with Grid. It is running out of memory. It may be possible to address this Question with some simple tweaks such as numcpus or tasksize.
  • You have another computation, B, that is threadsafe, is being done with Threads, and is running out of memory. However, that computation would be running out of memory even if it were being run sequentially. So this Question has nothing to do with parallel processing. This Question cannot be addressed without fine hand-tuning of the code, which'll likely involve rolling off chunks of the data to .m files.

The fact that these two computations are being done as part of one overall program is irrelevant.

@emendes You already know that it is not threadsafe. If a computation is not threadsafe or is not being done on a single computer, then Threads can't be used.

@mmcdara The OP edited the Question while I was writing my Answer. After reading the revised Question, I realized that my Answer no longer applied, so I deleted it.

Assuming that an operation is threadsafe and being done on a single computer, I can't think of any good reason to use Grid rather than Threads.

That's a boundary value problem (BVP). Runge-Kutta methods cannot be directly applied. Why do you want to solve it with a particular method?

There's a difference between rkf45 (Runge-Kutta-Fehlberg 4th-5th-order method) and rk4 (Runge-Kutta 4th-order method).

First 181 182 183 184 185 186 187 Last Page 183 of 709