Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@AlexeyK You wrote:

  • Concerning passing n: it's really a minor issue, but I caught myself on the thought that once you have evaluated the number of variables in the main procedure, it could be worth just assigning it to a variable and then passing it everywhere it is needed (thus, you don't need to evaluate the length again - a kind of optimality in terms of a number of operations). What do you think?

I agree, partially. The part that I agree with is that it's good to avoid recomputation. The part that I disagree with is that passing extra arguments is a good way to achieve that.

Maple has several ways to do it without passing extra arguments. Off the top of my head, the ways that I can think of are remember tables, Records, and objects. I'll describe remember tables, the easiest to use of those three.

A remember table is a component added to a procedure such that when the procedure is called with arguments with which it has previously been called, it automatically returns what it returned the last time without executing the procedure at all. This all happens behind the scenes; all that you need to do is add option remember to the procedure. So, for the case that we're talking about here, you can do this:

Arity:= 
    proc(f::procedure) option remember; nops([op](1, eval(f))) end proc
:
UV:= (f::procedure)-> 
    local x, y, XY:= map2(index~, [x,y], [$1..Arity(f)]);
    map(unapply, (evalc@[Re,Im]@f@op@(Complex@op)~)(XY), op~(XY))
:

@nm The validity of variable::type:= ... (including return-value) assertions other than for procedure parameters is checked if and only if assertlevel=2, and that checking is the only purpose of assertlevel=2. This checking must be done at run time rather than at compile (or parse) time, so it's expensive. In the case at hand, the move::static:= ... statement was in the body rather than the declarations of module dog, so, like all module bodies, it was executed immediately (which is why that code needs to be put in a ModuleLoad if the module is stored in a library).

@nm Sorry, I was undergoing a dental procedure when I sent the "Remove 'static'" message. I now see that this part may not have been obvious: I only meant for you to remove the 2nd static, the one in dog. This will work under assertlevel=2, and move will still be static because it's declared static in animal. Note that move is not being declared in dog; rather, the move that was already declared in animal is being reassigned. Through some behind-the-scenes magic that I don't understand, the dog object nonetheless retains a local copy of move.

@nm Try removing static.

@janhardo plotcompare does side-by-side plots. And, despite its somewhat generic name, it's specifically for complex functions. And two things you should know about its help page:

  • It's one of most-well-written and most-extensive help pages in all of Maple.
  • You'll learn a lot of complex analysis just from reading the help page, including how to find branch cuts on plots.

@pengcheng Xue So, using the variables already defined in your previous worksheet, the matrix to pass to approxsoln is simply

A:= <<s3[]> | s2>:

@AlexeyK 

I think that the most potentially confusing concept that the help page ?@ fails to illustrate adequately is that f@g also works when returns a sequence rather than a single value, provided that f is prepared to accept the number of arguments that g returns. In the example at hand, op is an operator that returns a sequence. The op in the subexpression Complex@op returns a pair (x[k], y[k]) for some between 1 and n, and Complex[*1] will accept two arguments. The op in the subexpression f@op returns exactly n values of the form Complex(x[k], y[k]), and f is expecting exactly n arguments. (We say that f is n-ary or that its arity is n.)

Recall from my Answer that I explained that it's not necessary to pass n. With the list-based functional-programming style that I've used, it's not even necessary to assign n as a local, its value being implicit as the length of list XY.

Footnote:
[*1] Complex(x,y) is almost the same thing as x+I*y, the difference here being that it'll remain unevaluated when x and y are just names. But, of course, it's handled sensibly by ReIm, and evalc or else it'd be worthless here. This distinction is not needed in procedure UV; I could just as well have replaced Complex with ((x,y)-> x+I*y)

@janhardo So, when you change it to x= -1..1, does it "work"?

You wrote:

  • The idea was only to show two plots besides eachother for a complex plot with a real and imaginair part. 

You should use plotcompare for that.

@AlexeyK

First, note that XY = [[x[1],y[1]], [x[2],y[2]], ..., [x[n],y[n]]]. Then

(evalc@[Re,Im]@f@op@(Complex@op)~)(XY)

means the same thing as

fxy:= f(op(map(xy-> xy[1]+I*xy[2], XY)));
evalc([Re(fxy), Im(fxy)]);

Does that help?

@janhardo What is x= 1..1 supposed to mean? Did you mean x= -1..1?

@pengcheng Xue I can't do anything with that data file until you give some description. Tell me what precisely the jth number in the ith row represents. Why are there 70 columns? Is it because there are 70 different values of x? If so, are those x values one row of the file? Do those x-values include the two boundary points?

Are there any derivatives higher than 1st order in the ODEs?

@AlexeyK If the following two reasonable conditions are met, then there's no need to pass into MainFunc; the can be determined from F. The conditions are

  1. All of the variables in all of the members of are intended to be complex-valued parameters of the resulting procedures.
  2. You're willing to use some standard order, such as alphabetical order, for the parameter sequences.

In that case, can be constructed by 

Z:= sort([indets(F, And(name, Not(constant)))[]], 'key'= (x-> ""||x));

@AlexeyK I guess that you haven't read and "digested" my Answer yet. Everything that you mentioned in the above Reply (except the PS) is done by the little command at the end of my Answer:

map(UV@unapply, F, Z);

Regarding "How do you format window with Maple code?": Are you referring to here, on MaplePrimes, or within Maple itself? On MaplePrimes, use the tool on the toolbar "<>". It's to the right of the 2 A's. In Maple itself, go to the Insert menu and select Code Edit Region.

@mmcdara Do you have any reason to believe that the Question by @panke was deleted by anyone other than its own author?
 

@mmcdara @Christopher2222 I think that both of you are failing to recognize the distinction between Moderators and Administrators. 

Moderator is any user of sufficiently high reputation who has been given the ability to edit and/or delete any material, regardless of its author. There are currently 85 Moderators, although that includes many who haven't used MaplePrimes in years. And I would guess that the majority of those 85 have never used their Moderator powers, except perhaps to delete spam.

An Administrator is an employee of MapleSoft who is tasked with maintaining this website. Administrators can retreive deleted material (I'm not sure of the details of that). I am only aware of one Administrator, @Bryon (Bryon Thur).

Several prominent "serious information" websites, including Wikipedia and StackExchange, use ordinary users as moderators; indeed, I doubt that those two could function at all if they didn't---they'd just be filled with junk material.

@oggsait Your plot can be made smoother by increasing the number of points (option numpoints) or increasing the 2D grid (option grid). Which of these you can use and which will work best depend on the particular plotting command that you used. If you say which one, I can advise further.

First 105 106 107 108 109 110 111 Last Page 107 of 709