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's a solution for an arbitrary number of dancers, using evenly spaced points on the unit circle as the starting points. The ODEs are essentially the same as in my solution above. I decided to form the dependent variable names with indexing (x[1]x[2]y[1], etc.) rather than with cat and ||. I also changed the indexing from 0..n-1 to 1..n. The brevity of the code shows Maple's great power at forming and working with a repetitive set of ODEs.

restart:
SpiralDance:= proc(n::posint)
local
     k, K:= k= 1..n, x, y, V_k:= [x[k],y[k]], v,
     eqns:= seq(((D+(X->X))(v[k]) = v[1+irem(k,n)]) $ K, v= [x,y]),
     ics:= op~([(V_k =~ [cos,sin](-2*k*Pi/n)) $ K])[],
     t, Sol:= dsolve({eqns(t),ics(0)}, numeric)
;
     plots:-odeplot(Sol, [V_k(t) $ K], thickness= 3, axes= none, gridlines= false)
end proc:

SpiralDance(5);

 

The breakpoint command in Maple is stopat. See ?stopat.

Your transform is (x,y)-> [x-y]. This says "take a point (x,y) on the graph and replace it with the single number x-y." That makes no sense: You need to replace points with points---pairs of numbers---not with single numbers.

I also encourage you to replace PLOT with plots:-display

There's a decimal point that you included somewhere in your input. Remove it.

Here's a simple solution, off the top of my head, with the dancers starting at [1,1], [1,-1], [-1,-1], [-1,1]. I leave animating this solution to you. It's really easy. The position of dancer (0 to 3) at time is [x||k(t), y||k(t)].

 

restart:

 

eqns:=
     seq(diff(x||k(t), t) = cat(x,irem(k+1,4))(t) - x||k(t), k= 0..3),
     seq(diff(y||k(t), t) = cat(y,irem(k+1,4))(t) - y||k(t), k= 0..3)
;
ics:=
     x0(0) = 1, x1(0) = 1, x2(0) = -1, x3(0) = -1,
     y0(0) = 1, y1(0) = -1, y2(0) = -1, y3(0) = 1
:
Sol:= dsolve({eqns,ics}, numeric):

diff(x0(t), t) = x1(t)-x0(t), diff(x1(t), t) = x2(t)-x1(t), diff(x2(t), t) = x3(t)-x2(t), diff(x3(t), t) = x0(t)-x3(t), diff(y0(t), t) = y1(t)-y0(t), diff(y1(t), t) = y2(t)-y1(t), diff(y2(t), t) = y3(t)-y2(t), diff(y3(t), t) = y0(t)-y3(t)

plots:-odeplot(
     Sol, [seq([x||k(t), y||k(t)], k= 0..3)], t= 0..5,
     thickness= 3, axes= none, gridlines= false
);

dsolve({eqns,ics});

{x0(t) = exp(-t)*sin(t)+exp(-t)*cos(t), x1(t) = exp(-t)*cos(t)-exp(-t)*sin(t), x2(t) = -exp(-t)*sin(t)-exp(-t)*cos(t), x3(t) = -exp(-t)*cos(t)+exp(-t)*sin(t), y0(t) = exp(-t)*cos(t)-exp(-t)*sin(t), y1(t) = -exp(-t)*sin(t)-exp(-t)*cos(t), y2(t) = -exp(-t)*cos(t)+exp(-t)*sin(t), y3(t) = exp(-t)*sin(t)+exp(-t)*cos(t)}

 

 

Download Spriral_Dance.mw

Try the old profiling commands: exprofileexcallgraphprofile. I don't have much experience with profile. I've used exprofile and excallgraph a lot, and I've never come across code that they couldn't handle.

The mathematical constant Pi is spelled with a capital in Maple. If you spell it pi, it's just another variable, which, unfortunately, prettyprints exactly the same as the mathematical constant. However, the printed forms can be distinguished using the lprint command.

A (nonconstant) function of a random variable is itself a random variable. So your is already a random variable and there's no need to apply RandomVariable to it. Skip T1, and do what you want with Y, such as 

simplify(PDF(Y,t));

or, more directly,

simplify(PDF(1/X,t));

 

restart:

 

MaxAbsWithIndex:= proc(M::Matrix(numeric), col::posint)
# Returns the entry with maximal absolute value in column col
# and its row index.
local
     Max:= -infinity, i, MaxI, v, absv, Maxv,
     Rows:= proc(M) option inline; op([1,1],M) end proc
;
     for i to Rows(M) do
          v:= M[i,col];
          absv:= abs(v);
          if absv > Max then
               Max:= absv;
               MaxI:= i;
               Maxv:= v
          end if
     end do;
     (Maxv, MaxI)
end proc:

 

Pivot:= proc(M::Matrix(numeric), row::posint, col::posint)
uses RO= LinearAlgebra:-RowOperation;
local Max,MaxI;
     (Max,MaxI):= MaxAbsWithIndex(M, col);
     RO(RO(M, [row,MaxI], _rest), row, 1/Max, _rest)
end proc:
          

A:= LinearAlgebra:-RandomMatrix(3,4);

A := Matrix(3, 4, {(1, 1) = -32, (1, 2) = 27, (1, 3) = 99, (1, 4) = 92, (2, 1) = -74, (2, 2) = 8, (2, 3) = 29, (2, 4) = -31, (3, 1) = -4, (3, 2) = 69, (3, 3) = 44, (3, 4) = 67})

A1:= Pivot(A, 1, 1);

A1 := Matrix(3, 4, {(1, 1) = 1, (1, 2) = -4/37, (1, 3) = -29/74, (1, 4) = 31/74, (2, 1) = -32, (2, 2) = 27, (2, 3) = 99, (2, 4) = 92, (3, 1) = -4, (3, 2) = 69, (3, 3) = 44, (3, 4) = 67})

A;

Matrix(3, 4, {(1, 1) = -32, (1, 2) = 27, (1, 3) = 99, (1, 4) = 92, (2, 1) = -74, (2, 2) = 8, (2, 3) = 29, (2, 4) = -31, (3, 1) = -4, (3, 2) = 69, (3, 3) = 44, (3, 4) = 67})

Pivot(A, 1, 1, inplace);

Matrix(3, 4, {(1, 1) = 1, (1, 2) = -4/37, (1, 3) = -29/74, (1, 4) = 31/74, (2, 1) = -32, (2, 2) = 27, (2, 3) = 99, (2, 4) = 92, (3, 1) = -4, (3, 2) = 69, (3, 3) = 44, (3, 4) = 67})

A;

Matrix(3, 4, {(1, 1) = 1, (1, 2) = -4/37, (1, 3) = -29/74, (1, 4) = 31/74, (2, 1) = -32, (2, 2) = 27, (2, 3) = 99, (2, 4) = 92, (3, 1) = -4, (3, 2) = 69, (3, 3) = 44, (3, 4) = 67})

 

 

Download Pivot.mw

I think that the only reason to use Join would be if you wanted to use its second argument, the separator. I did some quick tests, and cat is quicker and uses less memory. Join is externally compiled and cat is built-in, so they're both pretty efficient.

How about shifting the z-coordinates of the centers of the base circles?

p1:= plottools:-cylinder([1, 1, 1], 1, 1):
p2:= plottools:-cylinder([1, 1, 2], 2, 3):
p3:= plottools:-cylinder([1, 1, 5], 1, 4):

plots:-display([p1,p2,p3]);

Here's an example of your 1, 2, and 3. There are many ways for 2 and 3. Pay special attention to the way that prime-power fields are created in Maple because it's a little unusual.

restart:
#0. Create the matrix
p:= Randprime(3,x) mod 2;
alias(x= RootOf(p,x)):
M:= Matrix(5,7, ()-> randpoly(x, degree= 3));

#1. Get the rank.
Gausselim(M, 'rank') mod 2:
rank;
     5


#2. Row sum squared
V:= Vector(op([1,1], M), i-> expand(add(y, y= M[i,..])^2));

#3. Dividing by row sum squared
Matrix(op(1,M), (i,j)-> M[i,j]/V[i]);

 

See the commands ?sign, ?primpart, and ?content. Using those, here's a short procedure for it:

p:=x^2*y-2*y*z+3*x^2+2*y-z:

RepeatPositiveTerms:= (P::polynom(integer))->
     [seq(`if`(sign(t)=1, primpart(t) $ content(t), [][]), t= [op(expand(P))])]
:

RepeatPositiveTerms(p);

     [x^2*y, x^2, x^2, x^2, y, y]

 

Any function can be made to map over a list by appending to its name:

abs~(L);
signum~(L);

Or, getting a bit fancier, there's

(abs~, signum~)(L);

 

Your system is overspecified: You have three equations, but only two unknown functions. This can't be solved.

First 255 256 257 258 259 260 261 Last Page 257 of 395