Carl Love

Carl Love

28095 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Here are the commands to numerically solve the PDE. The notation D[2] in the initial conditions refers to differentiation with respect to the second variable, t. The 0 as the third argument to each piecewise is a default value to be used when the condition (the first argument) is not satisfied.

restart:
PDE:= diff(u(x,t),t,t)-2*diff(u(x,t),x,x)+diff(u(x,t),x,t) = 0;
ICs:=
    u(x,0) = piecewise(abs(x) < 1, 1-x, 0),
    D[2](u)(x,0) = piecewise(abs(x) < 1, cos(Pi*x), 0)
;
BCs:= u(-4,t) = 0, u(4,t) = 0:
Sol:= pdsolve({PDE}, {ICs,BCs}, numeric, time= t, timestep= 0.025, spacestep= 0.1);

And here are some of the numerous plots you can generate:

Sol:-plot(x=0, t= 0..1);
Sol:-plot(t=1, x= -4..4);
Sol:-animate(x= -4..4, t= 0..3, numpoints= 100);

See ?pdsolve,numeric for more.

I believe that the memory will be freed at the first garbage collection after the restart. You can either wait for the garbage collection to come around on its own schedule, or you can force the collection with the command

gc();

 

Unknown error? I think that the error message is fairly clear for this one. You are trying to add a 3-element row Vector to a scalar.

Tr(X) and Tr(X0) are row Vectors, and H[1] is a scalar. So Tr(X).H[1]-Tr(X0).H[1] is a row Vector. Dtau1CC[1], and Tr(Dtau2) are 3x1 Matrices, and is a 3-element column Vector, so 3*(Tr(X).Dtau1.CC[i].Tr(Dtau2).U) is a scalar.

L:=[seq([i,i^2], i=1..4)]:

plots:-animate(
     plot,
     [L[1..trunc(k)]],
     k= 1..nops(L), frames= nops(L),
     style= point, symbol= circle, symbolsize= 12,
     view=[0..4,0..16]
);

Your problem is excessive calls to randomize(). Just use it once, at the top of your code.

The Maple clock has much lower resolution than your CPU clock. The Maple clock hasn't advanced between your calls to randomize() in the loop. Thus, the randomize() is setting the random sequence back to the same position.

You (or the code that you're calling) is trying to store a symbolic value, L, into a Matrix which is restricted to numeric values only. You must give a numeric value.

If that's not enough information for you to correct your code, then you'll need to post your code.

You could pad the lines with blanks so that every line has the same number of characters. Then there would be an easy correspondence between lines and byte positions.

int(X^2+3*y+3*z+X^7, X= 1..10);

They're called Code Edit Regions. You can find them on the Insert menu.

The answer depends on how large k is. For small k, simply use

Expand~(M^~k) mod p;

This may not be efficient for large k.

Problems of this type can be done by finding the shortest path in a graph, although I don't know if this method has the best asymptotic efficiency. For this particular problem, the answer 11 (11 transitions) is returned instantaneously, alongs with the transitions themselves.

The vampires, maidens, and the lift are a system. We model the states of the system by who and what is in the lobby after the completion of each movement of the lift. (What's in the lobby necessarily determines what's in the bar.) Each state is represented by an ordered triple [V,M,L], where V is the number of vampires in the lobby, M is the number of maidens in the lobby, and L is the number of lifts in the lobby. We are going to model the system as a directed graph. Its vertices will be the valid states. Hence the name StatesVx. First, determine the valid states.

StatesVx:= table():
for V from 0 to 3 do
     for M from 0 to 3 do
          for L from 0 to 1 do
               if
                   #Can't have more V than M in lobby unless M=0:
                   (V > M implies M=0) and
                   #Can't have more V than M in bar unless all M are in lobby:
                   (M > V implies 3=M) and
                   #L can never be left where there are no people:
                   (V+M=0 implies L=0) and (V+M=6 implies L=1)
               then
                    #Maple won't allow lists as vertex labels, so I convert them to names:
                    StatesVx[V,M,L]:= nprintf("%a", [V,M,L])
               end if
          end do
     end do
end do;

States:= [indices(StatesVx)]:

The arcs of the graph will be the transitions of the states that can be achieved with a single movement of the lift. We examine each ordered pair of states and determine whether it's a possible transition.

Transitions:= table():
for pair in combinat:-permute(States,2) do
     Vx||(1..2):= pair[]; (V1,M1,L1):= Vx1[]; (V2,M2,L2):= Vx2[];
     if
          #The lift must move:
          L1 = 1-L2 and
          #If the lift comes down, the number of people in the lobby increases:
          (L1=0 implies V1+M1 < V2+M2) and
          #If the lift goes up, the number of people in the lobby decreases:
          (L1=1 implies V2+M2 < V1+M1) and
          #The next 4 conditions say that if V in the lobby increase,
          #then M can't decrease, and vice versa:

          (V1 > V2 implies M1 >= M2) and
          (V2 > V1 implies M2 >= M1) and
          (M1 > M2 implies V1 >= V2) and
          (M2 > M1 implies V2 >= V1) and
          #The total change of people in the lobby is at most 2:
          abs((V1+M1) - (V2+M2)) < 3
     then
          Transitions[StatesVx[Vx1[]],StatesVx[Vx2[]]]:= 1
     end if
end do:

Now compute a shortest path through the graph from the initial state (everything in the lobby) to the final state (nothing in the lobby).

GraphTheory:-ShortestPath(
     GraphTheory:-Graph({indices(Transitions)}),
     StatesVx[3,3,1], StatesVx[0,0,0]
);

     [`[3, 3, 1]`, `[1, 3, 0]`, `[2, 3, 1]`, `[0, 3, 0]`, `[1, 3, 1]`, `[1, 1, 0]`, `[2, 2, 1]`, `[2, 0, 0]`, `[3, 0, 1]`, `[1,        0, 0]`, `[1, 1, 1]`, `[0, 0, 0]`]

So the required number of transitions is one less than the number of vertices in that shortest path.

nops(%)-1;

     11

Download Vampires_&_Maidens.mw

Suggestions for improvement of the above algorithm are most welcome, especially improvement of the asymptotic efficiency as the number of vampires and maidens increase. Solutions that merely count the number of transitions without listing them are not welcome (as comments to this Answer).

You need to use a units environment. There are two pre-defined environments, Standard and Natural.

restart:
with(Units):
with(Natural):
UseSystem(SI);
phi:= 30*arcdeg;

sin(phi);

This is suprisingly simple in Maple:

diff(ln(x)/x, x$n);

diff(exp(x)*ln(x), x$n);

Yes it is easily done via

plot([<X|Y1>, <X|Y2>])

or, if you have a large numbers of Y's, you may want to map the adjoining of X, like this:

plot(map2(`<|>`, X, [Y||(1..2)]))

The following is a close match to the plot in your Question:

X:= <0,1,2,3>:
Y1:= <0.5, 2.5, 1.75, 2>:
Y2:= <0.3, 1.4, 1.6, 3.2>:

plot(
     map2(`<|>`, X, [Y||(1..2)]),
     color= ["Orange", "LightBlue"],
     thickness= 4, view= [-0.5..3.5, 0..3.5],
     axes= frame,
     axis[2]= [gridlines, tickmarks= [seq(.5*k, k= 0..7)]]
);

Maple's command for solving differential equations is dsolve, not solve. If Maple could solve your equation, the command to do so would be

dsolve(diff(y(x),x,x) = lambda*x*y(x)/sqrt(-1+x));

(Note that there're no square brackets and no capital letters in that. Note also how the second derivative is specified.) But Maple (Maple 16 at least) cannot solve this equation. The above command returns a DESol structure, which is just an abstract representation of an unknown function.

First 262 263 264 265 266 267 268 Last Page 264 of 395