Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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.

0.3*(1 - 0.4*0.5) = 24%

It is not clear to me that the OP is interested in distinguishing between trees whose underlying graphs are isomorphic. This is often the treatment of the subject in an undergraduate mathematics course titled "graph theory" or "discrete mathematics", where a tree is defined simply as a connected undirected graph with no cycles. Using that definition, a representative of each isomorphism class of trees of order 7 can be displayed in a single row using

plots:-display(
   GraphTheory:-DrawGraph~(
      <GraphTheory:-NonIsomorphicGraphs(
         7, 6, output= graphs, outputform= graph, restrictto= connected
      )>^+
   )
);

On the other hand, if the OP does mean "trees" in the computer-science sense of rooted oriented trees, then these can be generated by the command Iterator:-OrientedForests. There are 48 of these of order 7, and they can be displayed in a 6x8 array like this:

plots:-display(
   GraphTheory:-DrawGraph~(
      Matrix(
         (6,8), 
         [seq(
            GraphTheory:-Graph({seq({k,V[k]}, k= 1..numelems(V))}),
            V= Iterator:-OrientedForests(6) #6 = 7 nodes - 1
         )]
      ), style= tree, root= 0
   )
);

Unfortunuately, neither of these solutions will work in the OP's claimed version, Maple 12.


 

restart:

 

From the indentity

sech(x): % = convert(%,sec);

sech(x) = sec(I*x)

it follows that

J0:= Int(sech(x)^q, x):
J:= Int(''sec''(I*t)^q, t= 0..x):
J0 = J;

Int(sech(x)^q, x) = Int(sec(I*t)^q, t = 0 .. x)

modulo a constant of integration, provided continuity. Make a u-substitution z= I*t:

J1:= IntegrationTools:-Change(J, I*t= z);

-I*(Int((1/cos(z))^q, z = 0 .. I*x))

Get the antiderivative

Int((1/cos(z))^q, z):  A:= value(%) assuming q::posint:  %% = A;

Int((1/cos(z))^q, z) = (Sum((Product(1-1/(-q+2*j+1), j = 0 .. i))*cos(z)^(-q+2*i+1), i = 0 .. -ceil(-(1/2)*q)-1))*sin(z)/q+(Product(1+1/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*ln(sec(z)+tan(z))

and use it to evaluate the definite integral J1.

  -I*(Eval(A, z= I*x) - Eval(A, z= 0)) = eval(-I*(subs(z= I*x, A) - subs(z= 0, A)));

-I*(Eval((Sum((Product(1-1/(-q+2*j+1), j = 0 .. i))*cos(z)^(-q+2*i+1), i = 0 .. -ceil(-(1/2)*q)-1))*sin(z)/q+(Product(1+1/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*ln(sec(z)+tan(z)), z = I*x)-(Eval((Sum((Product(1-1/(-q+2*j+1), j = 0 .. i))*cos(z)^(-q+2*i+1), i = 0 .. -ceil(-(1/2)*q)-1))*sin(z)/q+(Product(1+1/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*ln(sec(z)+tan(z)), z = 0))) = -I*(I*(Sum((Product(1-1/(-q+2*j+1), j = 0 .. i))*cosh(x)^(-q+2*i+1), i = 0 .. -ceil(-(1/2)*q)-1))*sinh(x)/q+(Product(1+1/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*ln(sech(x)+I*tanh(x)))

So the desired formula is

R:= expand(rhs(%)):
J0 = R;

Int(sech(x)^q, x) = cosh(x)*(Sum((Product(-q/(-q+2*j+1)+2*j/(-q+2*j+1), j = 0 .. i))*(cosh(x)^i)^2, i = 0 .. -ceil(-(1/2)*q)-1))*sinh(x)/(cosh(x)^q*q)-I*(Product(-q/(-q+2*j-1)+2*j/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*ln(sech(x)+I*tanh(x))

If x is real, that can be simplified to

R1:= simplify(evalc(Re(R))) assuming q::posint;

((Product((-q+2*j)/(-q+2*j-1), j = 1 .. -ceil(-(1/2)*q)))*arctan(sinh(x))*q+cosh(x)^(-q+1)*(Sum((Product((-q+2*j)/(-q+2*j+1), j = 0 .. i))*cosh(x)^(2*i), i = 0 .. -ceil(-(1/2)*q)-1))*sinh(x))/q

 


 

Download Int_of_sech_power.mw

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