Kitonum

21435 Reputation

26 Badges

17 years, 28 days

MaplePrimes Activity


These are replies submitted by Kitonum

@vv  For some reason, your program does not work on my comp (32 bit Маple  2016.1 on Windows 8.1 ):

Download Error.mw

@Carl Love  Thank you!  I am surprised that you have found something essentially new in my procedure. In fact, it is conceptually very close to  CartProdSeq  procedure and also uses  foldl  command. The only difference is that you first create the whole list (a Cartesian product), and then in for loop enumerates it. This may cause problems with memory, if the original list is long. In my version  the construction of the desired objects occurs dynamically in the process of enumeration in nested sequences.

Here is the example illustrating the above. Problem: find the number of elements from  Cartesian product  [$ 0..9]^8  (total  10^8 elements)  that sum of the first four numbers is equal to the sum of the remaining numbers  (for example, [1,3,9,2,5,0,5,5] satisfies the condition).

restart:

CartProdSeq:= proc(L::seq(list), $)

local S,j;

    eval(subs(S= seq, foldl(S, [_i||(1..nargs)], seq(_i||j= L[j], j= 1..nargs))))

end proc:

 

k:=0:

for M in CartProdSeq([$0..9] $ 8) do

if `+`(M[1..4][])=`+`(M[5..8][]) then k:=k+1 fi;

od:

k;   

 

Error, (in CartProdSeq) Maple was unable to allocate enough memory to complete this computation.  Please see ?alloc

 

restart;

NestedSeq:=proc(Expr::uneval, L::list)

local S;

eval(subs(S=seq, foldl(S, Expr, op(L))));

end proc:

 

M:=[i||(1..8)]:

NestedSeq(`if`(`+`(M[1..4][])=`+`(M[5..8][]), 1, NULL), M=~0..9):

`+`(%);

                                                                 4816030

Edited.

This example:

result := ODETools[convertsys]({(D(x))(t) = x(t), ((D@@2)(y))(t) = y(t)-x(t)}, {}, {x(t), y(t)}, t);

[[YP[1] = Y[1], YP[2] = Y[3], YP[3] = Y[2]-Y[1]], [Y[1] = x(t), Y[2] = y(t), Y[3] = diff(y(t), t)], undefined, []]

(1)

NULL

subs(YP[1] = toto, result[1, 1]);

YP[1] = Y[1]

(2)

subs(lhs(result[1, 1]) = toto, result[1, 1]);

toto = Y[1]

(3)

``

 

Download convertsys.mw

 


 

 

@Joe Riel  I agree that your option is best if whole list is considered. But if the same thing should be done only for elements for example with odd numbers:

[seq(A[i,1]/A[i,2], i=1..nops(A), 2)];

@Carl Love 

eq:= a*x+b*y=c*x+d*y:

eq1:=(lhs-rhs)(eq);

factor(select(has, eq1, x)=-select(has, eq1, y));

                                      

 

or

coeff(eq1,x)*x=``(-coeff(eq1,y))*y;

                                             

 

 Edited.

@mskalsi 

restart;

Expr:=V[2]+a[5]*V[5]+a[6]*V[6]+a[7]*V[7]+V[9]:

v:=[a[5], a[6], a[7]]:

map(t->[t,0], v):

L:=[seq(seq(seq([i,j,k], k=%[3]), j=%[2]), i=%[1])];

F:=n->eval(Expr,v=~L[n]);

 

Function  F  substitutes  a[5], a[6], a[7]  in  Expr  by  nth triplet from  L .

For example:

F(3);

@Markiyan Hirnyk  I do not see any difference in quality:

A := plot(10*sqrt(3)/sqrt(120*Pi^2+19*x), x = 0 .. 10, y = 0 .. 1, thickness = 0):

B := plots:-implicitplot(y-10*sqrt(3)/sqrt(120*Pi^2+19*x), x = 0 .. 10, y = 0 .. 1, view = [0 .. 10, 0 .. 1], thickness = 0, gridrefine = 5):

plots[display](<A | B>);

 

 

 

@felixp  I used the codes from Carl Love's  comment  I missed that

My outputs are

educed(<0,0,0,1; 1,3,0,4>);

reduced(<1,3,0,4; 0,0,0,0>);

reduced(<0,0,0,0; 1,3,0,4>);

reduced(<1,3,0,4; 0,0,0,1>);

reduced(<0,0,0,0; 0,0,0,1>);

reduced(<0,1,1,1; 1,1,1,1>);

reduced(<1,0,1,1; 1,1,1,1>);

  

We get the same error in all cases.

@Carl Love  in each of which your  reduced  proc is not working properly;

reduced(<0,0,0,1; 1,3,0,4>);

reduced(<1,3,0,4; 0,0,0,0>);

reduced(<0,0,0,0; 1,3,0,4>);

reduced(<1,3,0,4; 0,0,0,1>);

reduced(<0,0,0,0; 0,0,0,1>);

reduced(<0,1,1,1; 1,1,1,1>);

reduced(<1,0,1,1; 1,1,1,1>);

@Carl Love 

1) Permutations of a set and the corresponding list give the same result:

restart;

combinat:-permute([1,2,3]);

combinat:-permute({1,2,3});

                            [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

                            [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

 

2) Enumeration in a multiple cycle more efficient. Compare:

 

t:=time():

for i to 100 do

for j to 100 do

for k to 100 do

i+j+k;

od: od: od:

time()-t;

                                                                  0.203

and

t:=time():

P:=combinat:-permute(`$`~([$1..100], 3),3):

for k in P do

`+`(k[]);

od:

time()-t;

                                                                  21.563

 

Of course, this is not essential for OP's problems.

@lg674 

Curve := proc(Range, a, b, c)  # Range is the range for t

local R, Phi, Theta;

R:=r(t,a,b,c); Phi:=phi(t,a,b,c); Theta := theta(t,a,b,c); plots:-spacecurve([R*cos(Phi)*sin(Theta), R*sin(Phi)*sin(Theta), R*cos(Theta)], t = Range, color = red, thickness = 2, linestyle = solid, axes = normal, orientation = [10, 50]);

end proc:

 

r := (t, a, b, c)->a*cos(t)+b*sin(t)+c:

phi := (t, a, b, c)->a^2*cos(t)+(b-1)*sin(t)+c+1:

theta := (t, a, b, c)->a^3*cos(t)+(b^2-1)*sin(t)+c^2+1:

 

Cone := (R, Theta) -> plot3d(eval([r*cos(phi)*sin(theta), r*sin(phi)*sin(theta), r*cos(theta)], theta = Theta), r = 0 .. R, phi = 0 .. 2*Pi, scaling = constrained) :

 

plots[display](Cone(8, (1/6)*Pi), Curve(0..2*Pi,1,2,3));

@san  I replaced  matrix  command by  Matrix  command, because matrix command is deprecated, and removed the  space between the  matrix  command and the subsequent opening parenthesis:

 

Download ch512_new.mw

 

@Ronan  If you want to add  0 to C2  in 4th position you can do it as follows:

C2:=[a,2,1-3*a,a^2-5,7*a,a^2]:

[C2[1..3][], 0, C2[4..-1][]];

                            [a, 2, 1-3*a, 0, a^2-5, 7*a, a^2]

@Markiyan Hirnyk  3. We have

expand(eval({x=9*z^2+3*z+367, y=6*z^2+z+244}, z=n+1/3));  # My nontrivial answer

expand(subs(n=n-1, %));   # We got Mathematica nontrivial answer

 

 

 

@Markiyan Hirnyk  

I know. For full automation, we can write

restart;

minimize(sin(x+y), x=-1..1, y=-1..1);

solve({sin(x+y)=%, abs(x)<=1, abs(y)<=1});

                  

 

 

 

First 79 80 81 82 83 84 85 Last Page 81 of 132