Carl Love

Carl Love

28150 Reputation

25 Badges

13 years, 350 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@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 g 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 k 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 Re, Im, 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 Z into MainFunc; the Z can be determined from F. The conditions are

  1. All of the variables in all of the members of F 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, Z 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. 

A 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.

@mmcdara You wrote:

  • Here is the plot, you can take it and put it into your own answer

No, I can't do that. MaplePrimes will not allow me, specifically, to post most plots or worksheets. However, you could edit my Answer to include the plot, and I'd be grateful if you did that.

@mmcdara The following derivation of the sum formula that I used is probably obvious to you, but I needed to write it out to understand it. In the following, I am simply using Maple to display my by-hand computation; Maple is not doing anything other than displaying it. Superscripted symbols in parentheses on function symbols (in the Standard prettyprinted output (not shown here)) represent the number of iterations, not the order of differentiation. 

By the chain rule
D(f@@n)(x) = D(f)((f@@(n-1))(x))*D(f@@(n-1))(x);
   D(@@(f, n))(x) = D(f)(@@(f, n - 1)(x)) D(@@(f, n - 1))(x)

So by induction
D(f@@n)(x) = Product(D(f)((f@@k)(x)), k= 0..n-1);
                             n - 1                    
                           ,--------'                 
                              |  |                    
                              |  |                    
          D(@@(f, n))(x) =    |  |   D(f)(@@(f, k)(x))
                              |  |                    
                             k = 0                    

We define x[k]= (f@@k)(x[0]) to get
D(f@@n)(x[0]) = Product(D(f)(x[k]), k= 0..n-1);
                                  n - 1             
                                ,--------'          
                                   |  |             
                                   |  |             
            D(@@(f, n))(x[0]) =    |  |   D(f)(x[k])
                                   |  |             
                                  k = 0             

Applying ln@abs to both sides, we get
ln(abs(D(f@@n)(x[0]))) = Sum(ln(abs(D(f)(x[k]))), k= 0..n-1);

                                  n - 1                 
                                  -----                 
                                   \                    
                                    )                   
        ln(|D(@@(f, n))(x[0])|) =  /    ln(|D(f)(x[k])|)
                                  -----                 
                                  k = 0                 


The number of arithmetic operations for the sum form and the product form are the same, but the sum form seems much more numerically stable.

@mmcdara The operation count of a numeric Maple procedure P can be reduced by 

P1:= codegen[optimize](P, tryhard);

The output is a revised Maple procedure. Thus, the pass through Matlab is unnecessary. In my experience, the results produced with the tryhard option (which uses a completely different algorithm) are almost always (but not 100% always) better than without the option.

For the case at hand, we want to optimize f@@iter for some very simple procedure f and some possibly large integer iter. And I'll suppose that we know a priori the value of iter, which is conceivable (e.g., for Newton's method). I don't think that there's any automatic optimization process that'll give you better results than direct iteration in a loop. In my considerable experience, there's only been one time where by meticulous by-hand optimizing I was able to reduce the operation count from that of direct iteration. (In that case, f was a Halley's method iteration for evaluating LambertW on a particular interval, and iter was 3, which I could show was sufficient to give the desired accuracy on that interval (I think 7 digits). The goal was to produce a procedure to run in Excel.)

@mmcdara The lines that you wanted explained should be something like:

FA := a-> x-> a*x*(1-x);
F:= FA(3.5): #or any specific numeric a
f := parse(sprintf("%a", eval(F)));
f1:= D(f);

The following explanation is of no mathematical interest; it's strictly for the most-hardcore programmers:

I think it's only the 3rd line of that---parse(sprintf(...))---that requires explanation. It's not a key step; it's just a trick to get around evalhf's extremely strict requirements.

The a in the anonymous inner procedure of FA is called a lexical variable because it's a parameter of a procedure at a higher level than the anonymous procedure. Procedures with lexical variables are not allowed by evalhf. Now, clearly, from a purely mathematical perspective F:= FA(3.5) is a new procedure (an instantiation of the anonymous procedure) with no dependence on a. However, evalhf balks at it simply because it was derived from a procedure that had a lexical variable at some previous time. The remants of the lexical variable can be seen with dismantle(eval(F)) or ToInert(eval(F)) or op(7, eval(F)). The parse(sprintf(...)) trick acts like money laundering to remove that lexical "stink"; essentially, it acts as if the procedure were retyped by hand with 3.5 in place of a. The same thing can be done with unapply, as noted by VV below.

Please post the plot, if MaplePrimes allows you to.

First 107 108 109 110 111 112 113 Last Page 109 of 711