Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

In Maple 2016: Suppose that A is the 5x2 Matrix. Then do

[seq(convert(v[], list), v= Iterator:-CartesianProduct(convert(A, listlist)[]))];

To see the full solution for 2nd-4th degree polynomials with variable coefficients, use option explicit:

solve(myeq, y, explicit);

Use PDEtools:-dchange to convert to polar coordinates, where the boundary condition is simpler.

PDE:= diff(u(x,y), x$2) + diff(u(x,y), y$2) = 1:
PDEp:= PDEtools:-dchange({x= r*cos(theta), y= r*sin(theta)}, PDE, simplify);

     PDEp := ((diff(u(r, theta), r, r))*r^2+(diff(u(r, theta), r))*r+diff(u(r, theta), theta, theta))/r^2

pdsolve({PDEp, u(1, theta) = 0});

     u(r, theta) = (1/4)*r^2+_F1(I*ln(r)+theta)+_F2(-I*ln(r)+theta)

Change y^`*` to `y*`.

(Some of this will repeat what Joe said, but I have the improved code also.)

Your hunch that hash tables would be better is spot on. Although your algorithm is impressive, your Maple implementation of it suffers from the most common of newbie efficiency mistakes: building a set or list by iteratively appending to an existing set or list. (I even used to do it myself, many, many years ago.) This can be corrected by building a table instead and then using indices or entries to build the set or list.

It only required a trivial change to make this change for your big set, orbits. This simple change reduced the run time to under 15 seconds. By also correcting the same mistake for your small set orbit and converting your small list interl to one built with a single seq, I shaved off another three seconds. By converting some of the other for loops to seqs, I shaved off another second. Moving the computation of d2 outside the inner loop saved another three seconds (an idea that I got from Joe). Remembering the previously computed values of d3 saved another 6 seconds (an idea that I got from Joe). The final code's memory usage is 22.18 M, and its time is under 3 seconds. Here is the code:

HEX:= proc()
local orbit, orbits:= table(), idx2, idx3, d2, d3, pos,
    interl, r, entry, refl, q,
    Base3:= proc(n) option remember; convert(n, base, 3) end proc
;
    for idx2 from 2^6 to 2*2^6-1 do
        d2:= convert(idx2, base, 2);
        for idx3 from 3^6 to 2*3^6-1 do
            d3:= Base3(idx3);
            interl:= [seq([d2[pos], d3[pos]][], pos= 1..6)];
            orbit:= table();
            orbit[seq(interl[[seq(q, q= 1+r..12), seq(q, q= 1..r)]], r= 0..11, 2)]:= ();
            for refl from 0 to 11 by 4 do
                entry:= interl[[seq(q, q= 1+refl..12), seq(q, q= 1..refl)]];
                orbit[entry[[1, seq(12-q, q= 0..10)]], entry[[3, 2, 1, seq(12-q, q= 0..8)]]]:= ()
            od;
            orbits[{indices(orbit, nolist)}]:= ()
        od
    od;
    nops([indices(orbits, nolist)])
end proc:

This code isn't intended to be run as 2D input, which fails by prematurely evaluating ().

You already have the correct implicit solution. It's what you called implicitsoln1. There's no way to get an explicit solution, i.e., a solution without RootOf and with y isolated on one side of the equation, which is probably why your instructor asked you for the implicit solution.

In the expression D(u)(x,0), you need to specify the independent variable with respect to which the derivative is being taken. So, you can change it to D[1](u)(x,0) for the derivative with respect to x or D[2](u)(x,0) for the derivative with respect to t.

You can start by reading ?HelpTools and its subpages. You should create your help file as a worksheet rather than as a .txt file.

The Answers of John and Kitonum have given a minor symptomatic solution to your problem but have failed to mention that your code can be vastly simplified.

If f and h are both sets, then all you need is

f intersect h;

The following works if f or h are sets or lists or a mixture:

select(`in`, f, h);

The print command is very, very rarely a good way to get your results. Whenever you feel tempted to use print, you should try to think of another way, or ask a Question here.

You want 20 arrays each with 20 elements? Use a 20x20 Matrix. Fill it with a single call to Sample:

X:= Matrix((20$2), datatype= float[8]):
N:= Statistics:-RandomVariable(Normal(0,1)):
Statistics:-Sample(N, X):

Now the jth column of X can be accessed as X[..,j] and is equivalent to a 20-element Vector.

(I know that the above commands can be shortened. I wrote it the way I did for pedagogy.)

Since q[2] is 0, this is trivial in that the sum reduces to one term. But I'll assume that you want to do this in more general cases. Also, I'll assume that x = x[1] and y = x[2]; otherwise, the answer is, of course, 0.

q:= <1,0>:
add(add(diff(a*x[1]*(1-x[1])-b*x[1]*x[2], x[j], x[k])*q[j]*q[k], j= 1..2), k= 1..2);

What ODE system? These are PDEs, not ODEs. You need to use pdsolve

One procedure will handle both of your questions, of course. Here it is:

Normalize:= proc(L::list)
local f:= proc() option remember; 0 end proc, k:= 0, x;
     forget(f);
     for x in L do
          if f(x)=0 then
               k:= k+1;
               f(x):= k
          end if
     end do;
     f~(L)
end proc:

Normalize([1,3,1,3,2,2,4,4]);
      [1, 2, 1, 2, 3, 3, 4, 4]

A question for the experts: Why is the forget necessary in this procedure? It gave erroneous results without it. I used Maple 2016. Surely this must be a major bug!

If you use the "raw" animated GIF export from Maple, then the display time for each frame will be 0.1 seconds and, it'll play as a continuous loop. You can download a GIF animation editor called Easy GIF Animator. With this, you can set the display time for frames individually, and you can turn off the continuous looping.

plot([
     piecewise(s < 2, s, 2+2*sin((s-2)/2)),   #x-coord
     piecewise(s < 2, 0, 2*(1-cos((s-2)/2))), #y-coord
     s= 0..2+Pi
]);

First 220 221 222 223 224 225 226 Last Page 222 of 395