Carl Love

Carl Love

28085 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

A boundary that is a vertical line becomes one of the limits of integration.

If there is any hidden code associated with worksheet, then it can be accessed from the menu Edit -> Startup Code. Many (maybe most) worksheets have their code in plain view right in the worksheet.

Here is how to classify binary matrices by their rank over GF(2).
 

restart:

n:= 4:

#fixed receptacle for Matrix in Modular package form
M:= Matrix((n,n), datatype= float[8], order= C_order):
Alias:= (i,j)-> op(procname)[(i-1)*n+j]: #reindexer from Gray code to square matrix
rank:= 'rank':  #dummy procedure which will be used for its remember table
for p in Iterator:-BinaryGrayCode(n^2) do
   A:= Matrix((n,n), Alias[p]);
   LinearAlgebra:-Modular:-Mod(2, A, M);
   rank(A):= LinearAlgebra:-Modular:-Rank(2,M)        
end do:

#This is a separate procedure only because I want to hide the magic number 4,
#which extracts the remember table of a procedure:
Table:= (P::evaln(procedure))-> op(4, eval(P)):

#Divide the matrices into sets based on rank.
ByRank:= ListTools:-Classify(rank, [indices(Table(rank), nolist)]):

 

The above code runs many times faster than the corresponding code over the complex numbers.

 

Now the set corresponding to each rank is stored in ByRank.

ByRank[0];

{Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0})}

nops(ByRank[4]);

20160

This count corresponds with the well-known formula for the size of GL(n, q):

nGL:= (n,q)-> mul(q^n-q^k, k= 0..n-1):

nGL(n,2);

20160

nops(ByRank[3]);

37800

``

Download rank_mod_2.mw

If someone knows how to make this more efficient by using ArrayTools:-Alias or by other inplace operations, I would appreciate seeing it.

How about

(T-> (p-> [T[..-2][], p])~(combinat:-permute(T[-1])[..max(2,nops(T[-1])!)/2])[])~(Tours);

But, there must be a better way to your overall goal. If you describe that goal better, maybe I can figure out a better way.

min({L[ ]} minus {0});

I think that you're having a problem that the other respondents aren't because you're saving the module to a library and they aren't. Global variables aren't part of the module and thus won't be saved unless they are explicitly mentioned. There is no need for global variables. Try this:

MonPackageFonctions:= module()
option package;
local GeometricData, r, l, ModuleLoad:= ()-> SetGeometricData(0.2, 1);
export 
   GammaNum:= xx->
      evalf(eval(Pi-arccos((-xx^2+l^2-r^2)/xx/r/2), GeometricData)),
   psiNum:= xx->
      evalf(
         eval(
            -arcsin(sqrt(-(xx^4-2*xx^2*l^2-2*xx^2*r^2+l^4-2*l^2*r^2+r^4)/xx^2/r^2)/2/xx/l),
            GeometricData
         )
      ),
   SetGeometricData:= proc(r::algebraic, l::algebraic)
      GeometricData:= [thismodule:-r= r, thismodule:-l= l];
      NULL
   end proc
;
   ModuleLoad()
end module:

This exports a procedure that lets you set the GeometricData externally but also uses r= 0.2 and l=1 as defaults.

If the file is named myfile.bat then do

system("myfile.bat");

There are many possibilities. The criteria are mostly aesthetic. How about this?
 

restart:

N:= 9:

Dist:= Matrix(
   N$2, shape= symmetric, scan= triangular,
   [0, op]~([[26,15,20,7 ,25,16,24,29],
                [15,23,26,33,40,38,54],
                   [24,13,20,27,35,43],
                      [26,42,34,15,39],
                         [18,14,31,32],
                            [25,49,45],
                               [32,20],
                                  [30]]
)):

d:=<0, 18, 26, 11, 30, 21, 16, 29, 37>:

Procedure "tour_length" calculates the length of a given tour.

tour_length:= proc(tour::list(posint))
   option remember;  
   add(Dist[tour[i],tour[i+1]], i= 1..nops(tour)-1) + Dist[tour[-1],tour[1]]
end proc:

P:= [$2..5]:

Tour2:= ([1,op]~)~(combinat:-setpartition(P));

[[[1, 5], [1, 2, 3, 4]], [[1, 2], [1, 5], [1, 3, 4]], [[1, 3], [1, 5], [1, 2, 4]], [[1, 4], [1, 5], [1, 2, 3]], [[1, 2], [1, 3], [1, 4], [1, 5]], [[1, 2, 3, 4, 5]], [[1, 2, 5], [1, 3, 4]], [[1, 2], [1, 3, 4, 5]], [[1, 2, 4], [1, 3, 5]], [[1, 3], [1, 2, 4, 5]], [[1, 2, 3], [1, 4, 5]], [[1, 4], [1, 2, 3, 5]], [[1, 3], [1, 4], [1, 2, 5]], [[1, 2], [1, 4], [1, 3, 5]], [[1, 2], [1, 3], [1, 4, 5]]]

Tours_Distances:= (tour_length~)~(Tour2);

[[14, 85], [52, 14, 59], [30, 14, 69], [40, 14, 56], [52, 30, 40, 14], [98], [59, 59], [52, 72], [69, 35], [30, 82], [56, 53], [40, 61], [30, 40, 59], [52, 40, 35], [52, 30, 53]]

Vector(Tour2 =~ Tours_Distances);

Vector[column]([[[[1, 5], [1, 2, 3, 4]] = [14, 85]], [[[1, 2], [1, 5], [1, 3, 4]] = [52, 14, 59]], [[[1, 3], [1, 5], [1, 2, 4]] = [30, 14, 69]], [[[1, 4], [1, 5], [1, 2, 3]] = [40, 14, 56]], [[[1, 2], [1, 3], [1, 4], [1, 5]] = [52, 30, 40, 14]], [[[1, 2, 3, 4, 5]] = [98]], [[[1, 2, 5], [1, 3, 4]] = [59, 59]], [[[1, 2], [1, 3, 4, 5]] = [52, 72]], [[[1, 2, 4], [1, 3, 5]] = [69, 35]], [[[1, 3], [1, 2, 4, 5]] = [30, 82]], [[[1, 2, 3], [1, 4, 5]] = [56, 53]], [[[1, 4], [1, 2, 3, 5]] = [40, 61]], [[[1, 3], [1, 4], [1, 2, 5]] = [30, 40, 59]], [[[1, 2], [1, 4], [1, 3, 5]] = [52, 40, 35]], [[[1, 2], [1, 3], [1, 4, 5]] = [52, 30, 53]]])

LimitDist:= (L::positive)-> select(T-> max(tour_length~(T)) <= L, Tour2):

<LimitDist(56)[]>;

Matrix([[[[1, 4], [1, 5], [1, 2, 3]]], [[[1, 2], [1, 3], [1, 4], [1, 5]]], [[[1, 2, 3], [1, 4, 5]]], [[[1, 2], [1, 4], [1, 3, 5]]], [[[1, 2], [1, 3], [1, 4, 5]]]])

``


 

Download Tours.mw

In differential equations in Maple, the dependent variables must always be used in functional form, i.e., x(t) and y(t) rather than x and y. Therefore, your code should be changed to

with(inttrans);
eq5 := diff(x(t), t)+diff(y(t), t$2) = 5*exp(2*t);
eq5s := laplace(%, t, s);
eq6 := diff(x(t), t)-x(t)-(diff(y(t), t))+y(t) = 8*exp(2*t);
eq6s := laplace(%, t, s);
solve({eq5s, eq6s}, {laplace(x(t), t, s), laplace(y(t), t, s)});
subs({x(0) = 2, y(0) = 1, (D(y))(0) = 1}, %);
eq3 := invlaplace(%, s, t);

If you make this simple change, then the last line will give you the answer that you're looking for.

A more-sophisticated approach---which might be useful if you want to re-use this operation a lot---is to use the RandomTools package:

RandomTools:-AddFlavor(
   A = module()
   local r:= rand(-90..90);
   export Main:= ()-> (a-> [a, convert(a*degrees, radians)])(r());
   end module
):
randomize():
n:= 4:
RandomTools:-Generate(list(A, n));

 

P:= [$2..5]:
Tours:= combinat:-setpartition(P):
nops~(Tours);
([1,op]~)~(Tours);

 

Your equation is an ODE with a parameter, y; it is not really a PDE because there are no derivatives with respect to y. So, it can be solved with dsolve:

restart:
equa1:= diff(u(x), x, x) - y*(1+x):
dsolve({equa1, u(0)=0, D(u)(0)=0});

 

You can use continued fraction convergents, like this:

x:= rand(2^1000..2^1001)()/rand(2^1001..2^1002)():

evalf(x);

.392692920399853

cf:= NumberTheory:-ContinuedFraction(x):

seq(Convergent(cf, k), k= 1..19);

1/2, 1/3, 2/5, 9/23, 11/28, 75/191, 86/219, 1537/3914, 3160/8047, 4697/11961, 17251/43930, 56450/143751, 976901/2487697, 7871658/20045327, 8848559/22533024, 25568776/65111375, 111123663/282978524, 136692439/348089899, 247816102/631068423

evalf([%]);

[.500000000000000, .333333333333333, .400000000000000, .391304347826087, .392857142857143, .392670157068063, .392694063926941, .392692897291773, .392692929041879, .392692918652287, .392692920555429, .392692920397075, .392692920399872, .392692920399852, .392692920399854, .392692920399853, .392692920399853, .392692920399853, .392692920399853]

 

Download Continued_fraction_convergents.mw

If your version of Maple is too old to have the NumberTheory package, then exactly the same thing is available in the numtheory package as commands cfrac and nthconver.

 

You can apply simplify to nested piecewise to convert it to a one-level piecewise:

simplify(m);

eval([x,y,z], L);

Careful, that must be [x,y,z] rather than {x,y,z} lest it won't be an ordered triple.

First 196 197 198 199 200 201 202 Last Page 198 of 395