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

To make plots go to a separate window, use the command

plotsetup(window);

These plots will look normal even if run from the command-line interface (that which you're calling maple-terminal).

One potential problem with this is that every plot goes to a new window, and I know of no programmatic way to close the windows. So, if you make 1000 plots, you'll have a 1000 open windows.

SimpleStack is an object-oriented module-based implementation; stack is a much older table-based implementation. SimpleStack has all the functionality of stack and some additional functionality. SimpleStack uses a more-familiar programming paradigm. I use SimpleStack exclusively.

Recursive procedures are very easy in Maple:

catalan:= proc(n::nonnegint)
option remember;
local k;
     add(thisproc(k)*thisproc(n-1-k), k= 0..n-1)
end proc:

#Put initial value in remember table.
catalan(0):= 1:

catalan(9);

     4862

By preloading the initial value into the remember table, we avoid the need to check for initial values in the procedure itself. This is more efficient.

A proper Maple function doesn't "print" a value; it returns a value. It's left up to the user whether or not to print the value.

 

`&ll`:= (a,b)-> 1/(1/a+1/b):
3 &ll 7;

In Maple, a^(1/3) is not real for a < 0. The real cube root is accessed by surd(a,3). So, change the plot command to

plot3d(surd(1-x^3-y^3, 3), x= -10..10, y= -10..10);

One way is to use the sequencing operator $:

1/2^k $ k= 4..8;

Although this operator is less efficient than the more common seq, it has the benefit of being capable of abstraction, which seq lacks:

MySeq:= 1/2^k $ k= a..b;


eval(MySeq, [a= 4, b= 8]);

Unlike seq, the k in the above expression should be either unassigned or placed in unevaluation quotes:

1/2^'k' $ 'k'= a..b;

When the number of equations is different from the number of variables being solved for, it's usually a bad idea to use solve. Use eliminate instead. The syntax is the same; just change solve to eliminate.

eliminate(
     [a = -(-y+1)/(x-y+2),
      b = -(-x^2+2*x*y-y^2-3*x+3*y-2)/(x-2*y+3),
      c = -(x*y-y^2-2*x+4*y-4)/(x*y-y^2-x+2*y-1),
      d = -(-x*y+y^2+x-2*y+1)/(x-2*y+3)
      ],
[x,y]
);

The second set is expressions that equal 0. So you can think of it as providing solutions for b and c.

You removed your code from your Question. That isn't a good sign.

Anyway, here is a very fast way to generate a large number of your random walks using directions sampled from your probability distribution.

 

restart:


Dirs:= Statistics:-Distribution(PDF= (phi-> cos(phi/2)/4)):
n:= 2^9: #walk length
N:= 2^4: #number of walks
DirBuffer:= Matrix((N,n), datatype= float[8]):
Walks:= Array((1..N,1..n,1..2), datatype= float[8]):


FillBuffer:= proc(B::rtable)
     Statistics:-Sample(Dirs, B, method= [envelope, range= -Pi..Pi]);
     [][]
end proc:


DoWalks_hf:= proc(W::Array, B::Matrix, n::posint, N::posint)
local k,K,phi;
     for K to N do
          W[K,1,1]:= 0:  W[K,1,2]:= 0:
          for k from 2 to n do
               phi:= B[K,k];
               W[K,k,1]:= W[K,k-1,1] + cos(phi);
               W[K,k,2]:= W[K,k-1,2] + sin(phi)
          end do
     end do
end proc:

DoWalks:= proc(W::Array, B::Matrix)
local n, N;
     FillBuffer(B);
     (N,n):= op(1,B);
     evalhf(DoWalks_hf(W, B, n, N));
     [][]
end proc:
     

CodeTools:-Usage(DoWalks(Walks, DirBuffer));

memory used=1.98MiB, alloc change=8.02MiB, cpu time=109.00ms, real time=111.00ms

 

(r,c):= trunc(sqrt(N))$2:
plots:-display(
     Matrix((r,c), (i,j)-> plot(<Walks[(i-1)*c+j,..]>)),
     thickness= 0, gridlines= false
);

 

Download RandDirWalk.mw

Array plots won't display in MaplePrimes, but you'll see in the worksheet that every walk is plotted on its own set of axes.

Regarding your followup question where you want to form the conjugate i*j*i^(-1) for every pair of elements i, j in A: It can be done like this:

B:= {seq(seq(PermConjugate(i,j), i= A), j= A)};

This computation takes about a minute because there are 705600 pairs. The end result is simply the set again (no surprise).

 

You can essentially enter them as in the book, and then make some substitutions: y to y(x), dy to diff(y(x), x) and dx to 1. Also, I've never seen arctg or tg. I just changed these immediately to arctan and tan, respectively.


13.1

eq:= sqrt(1-y^2)*dx+y*sqrt(1-x^2)*dy = 0;

(1-y^2)^(1/2)*dx+y*(1-x^2)^(1/2)*dy = 0

(1)

dSubs:= [dy= diff(y(x),x), dx= 1, y= y(x)];

[dy = diff(y(x), x), dx = 1, y = y(x)]

(2)

eq1:= eval(eq, dSubs);

(1-y(x)^2)^(1/2)+y(x)*(1-x^2)^(1/2)*(diff(y(x), x)) = 0

(3)

dsolve(eq1);

arcsin(x)+(y(x)-1)*(y(x)+1)/(1-y(x)^2)^(1/2)+_C1 = 0

(4)

13.2

eq:= x*y*dx+(x+1)*dy = 0;

x*y*dx+(x+1)*dy = 0

(5)

eq1:= eval(eq, dSubs);

x*y(x)+(x+1)*(diff(y(x), x)) = 0

(6)

dsolve(eq1);

y(x) = _C1*(exp(-x)*x+exp(-x))

(7)

13.3

eq:= x*(y^2+1)*dx+cos(x)^2*dy=0;

x*(y^2+1)*dx+cos(x)^2*dy = 0

(8)

eq1:= eval(eq, dSubs);

x*(y(x)^2+1)+cos(x)^2*(diff(y(x), x)) = 0

(9)

dsolve(eq1);

y(x) = -tan(x*tan(x)+ln(cos(x))+_C1)

(10)

13.4

eq:= x*y*arctan(x)*dx+(y^2+1)*dy=0;

x*y*arctan(x)*dx+(y^2+1)*dy = 0

(11)

eq1:= eval(eq, dSubs);

x*y(x)*arctan(x)+(y(x)^2+1)*(diff(y(x), x)) = 0

(12)

dsolve(eq1);

y(x) = 1/(1/LambertW(_C1*exp(-arctan(x)*x^2+x-arctan(x))))^(1/2)

(13)

dsolve(eq1, implicit);

(1/2)*arctan(x)*x^2-(1/2)*x+(1/2)*arctan(x)+(1/2)*y(x)^2+ln(y(x))+_C1 = 0

(14)

13.5

eq:= exp(x-y)*dy-dx = 0;

exp(x-y)*dy-dx = 0

(15)

eq1:= eval(eq, dSubs);

exp(x-y(x))*(diff(y(x), x))-1 = 0

(16)

dsolve(eq1);

y(x) = -ln(1-_C1*exp(x))+x

(17)

13.6

eq:= dy/dx = tan(y/x)+y/x;

dy/dx = tan(y/x)+y/x

(18)

eq1:= eval(eq, dSubs);

diff(y(x), x) = tan(y(x)/x)+y(x)/x

(19)

dsolve(eq1);

y(x) = arcsin(x*_C1)*x

(20)

 


Download 6_ODEs.mw

The correct syntax for the select command is

A:= select(g-> PermOrder(g)=4, H);

Think of it as having this English translation: "Select g such that PermOrder(g)=4 from H."

It's never allowed for an indexed name such as H[i] to be a left-side operand of ->i.e., a parameter. That was the proximate cause of your error message.

I posted code for extracting the extrema from plots, so you're not "on your own" as Mac Dude says. The code can be found here:

http://www.mapleprimes.com/questions/206660-Maximum-Point-Of-Plot#answer221288

The commands that are (guaranteed to be) thread safe are listed in the help page ?index,threadsafe. Unfortunately, it's a very small list.

Detecting whether a large number is prime is much, much easier computationally than factoring a product of two medium-sized primes. This fact is the basis of most modern cryptography systems. (There is no known theoretical reason for this fact---it may just be the current state of the known algorithms.)

restart:
p:= nextprime(2^99):
q:= nextprime(p):
n:= q*p:
CodeTools:-Usage(ifactor(n));

memory used=313.25MiB, alloc change=164.03MiB, cpu time=9.28s, real time=9.36s
(633825300114114700748351602943) (633825300114114700748351603131)

p:= nextprime(2^999):
%-2^999;

1239

restart:
p:= 2^999+1239:

CodeTools:-Usage(isprime(p));

memory used=3.33MiB, alloc change=8.00MiB, cpu time=32.00ms, real time=39.00ms
true

Note that the second number has five times as many digits as the first!

So, if n is a product of several small, easy-to-find factors and one large prime, then ifactor knows to stop after finding the small factors because it can quickly detect that the remaining factor is prime.

(A side comment on your timing technique: It's more accurate to include the timing commands and the code being timed in a single execution group.)

Regarding Christopher's Answer: There's no need for you to be forced to accept seq's default limitation to integer values of m. Any number of a values of in the range 1..2 (or in any range) can be accomodated like this:

linspace:= (ab::range, n::posint)-> [seq(op(1,ab)-`-`(op(ab))/(n-1)*_k, _k= 0..n-1)]:plots:-display(seq(plot(sin(m*x), x= -Pi..Pi), m= linspace(1..2, 9)));

The above plot uses 9 values of m.

Regarding Kitonum's Answer: I wouldn't be so quick to reject the idea of a 3-d plot. If contructed properly and viewed from a certain angle, it'll look like the 2-d plot that you want. I think that the continuous color gradation used in 3-d plots improves this particular plot:

plot3d(
     sin(m*x), m= 1..2, x= -Pi..Pi,
     style= wireframe, thickness= 2,
     orientation= [0,90], axes= normal, labels= [``, x, y]
);

The aboves uses plot3d's default of 49 values of m. That can be controlled with the grid option.

First 240 241 242 243 244 245 246 Last Page 242 of 395