Joe Riel

9530 Reputation

23 Badges

20 years, 27 days

MaplePrimes Activity


These are answers submitted by Joe Riel

A few comments.  First, you should use Array rather than array, the latter is older structure.  I'd probably use a table rather than an Array, just because ...

To generate a point plot you create a listlist structure of the form [[x1,y1],[x2,y2],...].  In this case, however, because the x are merely indices, it is easier to use Statistics:-LineChart, which only asks for a list (or Vector) or points:

L := table():
x:=0.3:
for i to 30 do
    x := 4*x*(1-x);
    L[i] := x
end do:
L := convert(L,'list'):
Statistics:-LineChart(L);
A nice feature of LineChart is that it plots the points and connects them.  Using plots[pointplot] gives a bunch of scattered points and it is difficult to see how they are connected.
 
To get the initial x in the array, swap the two lines in the do loop (the last computed x is not used).

You mean, I presume, for a relative path.  Isn't that the case?  Or maybe that was what you were saying, somewhat obliquely (the "should" confused me).

I believe so. I'm surprised that fact is not mentioned in the help page, I'll submit that as a bug.

alias(seq(x=x(t), x in {a,v,p})):
deqs := eval({a = diff(v,t)
              , v = diff(p,t)
             }, a = cos(t)):
ics := eval({p = 3
             , v = 0
            }, t = 0
           ):
dsolve(deqs union ics);
                         {p = -cos(t) + 4, v = sin(t)}

Sometimes it is useful to apply a single operation to multiple operands of an expression.  The applyop procedure doesn't work here; it can apply an operation to multiple operands, but separately.  For example

applyop(f, {1,-1}, a+b+c+d);
                              f(a) + b + c + f(d)
 

I'm thinking of an applyops procedure that does

applyops(f, {1,-1}, a+b+c+d);
                               f(a+d) + b + c

Similarly, it would be useful to be able to apply an operation to just the numerator or denominator of an expression.

The integral in question appears to be

A := Int(Int(q*exp((1-b)^2*qz^2/lambda2)*exp((1-b)^2*q^2/lambda1)/Pi/(1+b^2*q^2+b^2*qz^2)
        , q=-infinity..infinity)
    , qz = 0..infinity);

The notation used, however, is not entirely clear.  That is, it uses expsome_val; I assume that should be exp(some_val). Evaluating that directly in Maple gives 0 because the integrand is odd in q.  Should the limits of the inner integrand be symmetric?

Note that Maple uses Pi, not pi, to stand for the symbolic constant 3.14159...

You cannot execute Maple worksheets (files with extension .mw, or the older .mws) in command-line maple.  You can, however, export the contents of a worksheet as Maple input (select the "maple input (.mpl)" option from the "File Type" in the "Export As" dialog box and then execute the resulting file using the command maple filename.mpl.  You might want to use the -F option to prevent maple from exiting when it gets to the end of the file.

There is no switch/case statement in Maple.  Use the if then construct.  For clarity I occasionally swap the left and right sides of the equation so that the case shows up first:

if   a1 = a then
elif a2 = a then
elif a3 = a then
...
end if

Here's a version that uses the deprecated networks package instead of GraphTheory.  It ran on Maple11; I don't have Maple10 lying around for a quick check.  I'm not sure whether Maple10 supports the 'nolist' option to indices, which is used in a couple of places.  You can do the same with a map(op, {indices(...)}) call.  I also modified the routine to return routes starting from any edge.

Addendum: Maple10 might not support the use of _rest.  If not, use args[3..-1] in place of it.

Addendum: Rather than calling {indices(...,'nolist')}, a nicer solution is to assign a local variable Vertices and use it in place of those calls.  Do  Vertices := {cat(``,"a".."d",1..4)}.

module route()

local sides,Side,i,s,G,Route,cnt;
export connect, ModuleApply;

    sides := {a,b,c,d};
    Side := table();

    # Generate table Side mapping vertices to sides
    for i to 4 do
        for s in sides do
            Side[cat(s,i)] := s;
        end do;
    end do;

    # Create Graph

    G := networks['new']();
    networks['addvertex']({indices(Side,'nolist')},G);
    networks['addedge']({NULL
                         , seq({a2,b||j}, j=1..4)
                         , seq({a2,c||m}, m=1..4)
                         , seq({a3,d||n}, n=1..4)
                         , seq({b3,c||m}, m=1..4)
                         , seq({b3,d||n}, n=1..4)
                         , seq({b4,a||i}, i=1..4)
                         , seq({c1,b||j}, j=1..4)
                         , seq({c4,a||i}, i=1..4)
                         , seq({c4,d||n}, n=1..4)
                         , seq({d1,a||i}, i=1..4)
                         , seq({d1,b||j}, j=1..4)
                         , seq({d2,c||m}, m=1..4)
                        }
                        , G );

    connect := proc(V, S::set)
    local s,n,v;
        if S = {} then
            cnt := cnt+1;
            Route[cnt] := [_rest];
        end if;
        if V :: 'set' then
            for v in V do
                procname(v,S minus {Side[v]}, _rest);
            end do;
        else
            for n in networks['departures'](V,G) do
                s := Side[n];
                if not s in S then
                    next;
                end if;
                procname(n, S minus {s}, _rest, n);
            end do;
        end if;
    end proc;

    ModuleApply := proc()
    local v,i;
        cnt := 0;
        Route := 'Route';
        connect({indices(Side,'nolist')}, sides);
        [seq(Route[i], i=1..cnt)];
    end proc;

end module:

route();
nops(%);

Alec's brute-force technique is compact, but wouldn't scale very well.  Here's a somewhat better approach.  While not necessary, I used GraphTheory to create a graph, however, the recursive routine that computes the routes only uses it for the Neighbors export.  This returns 1/4 the number that Alec's does because I restricted the solution to starting at edge a.  I assume that the edges are undirected.

module route()

local sides,Side,i,s,G,cnt,Route;
export connect, ModuleApply;

    sides := [a,b,c,d];
    Side := table();

    # Generate table Side mapping vertices to sides
    for i to 4 do
        for s in sides do
            Side[cat(s,i)] := s;
        end do;
    end do;

    # Create Graph

    G := GraphTheory:-Graph({NULL
                             , seq({a2,b||j}, j=1..4)
                             , seq({a2,c||m}, m=1..4)
                             , seq({a3,d||n}, n=1..4)
                             , seq({b3,c||m}, m=1..4)
                             , seq({b3,d||n}, n=1..4)
                             , seq({b4,a||i}, i=1..4)
                             , seq({c1,b||j}, j=1..4)
                             , seq({c4,a||i}, i=1..4)
                             , seq({c4,d||n}, n=1..4)
                             , seq({d1,a||i}, i=1..4)
                             , seq({d1,b||j}, j=1..4)
                             , seq({d2,c||m}, m=1..4)
                            });

    connect := proc(v, S::set)
    local s,n;
    uses GraphTheory;
        if S = {} then
            cnt := cnt+1;
            Route[cnt] := [_rest];
        end if;
        for n in Neighbors(G,v) do
            s := Side[n];
            if not s in S then
                next;
            end if;
            procname(n, S minus {s}, _rest, n);
        end do;
    end proc;

    ModuleApply := proc()
    local v;
        cnt := 0;
        Route := table();
        for v in [cat(a,1..4)] do
            connect(v, {b,c,d}, v);
        end do;
        (cnt, eval(Route));
    end proc;

end module:

(cnt,Routes) := route();
convert(Routes,'list');

Without questions this site would be much less useful, and less interesting.  A good question elicits good responses, and is just as valuable.

Is alpha really the polynomial you want as the output?  A better example would have made this much clearer, say,

  polyString := "3*x^2+x+1":

The usual method is to use parse:

  parse(polyString);

                  

You need additional structure, in particular, an inner product, on this functional space.  Do you have one?

Yes it can be done.  After saving the variables (you can use the save command, or higher level write commands), use the `stop` procedure (not the stop command).  It can be called from inside a procedure.  You'll probably  want Maple to restart automatically.  That, too, can be done with a shell script that looks at the exit code, which you can pass with `stop`.

If you happen to be using a version of Maple (say 10 or 11) on a machine that supports forking (*nix) there may be a relatively simple way to avoid the excessive memory allocation by using the fork procedure from the process package.  However, this procedure is not available in Maple 12.  The basic idea is that you run the code that allocates the large amount of memory in a separate process, returning the output to the main process via a pipe.  You will need to kill and restart that process if it allocates too much memory.  You might look at my Tine package, which uses this technique to measure memory allocation and also provides a few commands to simplify calling a procedure in a transient forked process to avoid excessive memory allocation in the main process.

The best approach, however, might be to redesign your code to avoid the excessive memory allocation.

First 92 93 94 95 96 97 98 Last Page 94 of 114