Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Let M a matrix of zeros and ones for instance.

N := 10^5:  # This is the order of magnitude I have to consider (10^4 may be enough if L is "small")
L := 5:     # L is between 3 and 8 in practice (see context at the end of this post)
M := LinearAlgebra:-RandomMatrix(N, L, generator=0..1):

Let C a set of colums of M and |C| the number of elements of C.
Let P a list of length |C| of  zeros and ones.

I want to count al the rows in M such that 

`and`( seq( M[n, C[k]] = P[k], k = 1.. |C| ) )

For instance

pattern := n -> `if`(evalb(`and`(seq(S[n, C[k]]=P[k], k=1..3))), 1, 0):
t0 := time():
add(pattern(n), n=1..N);
time()-t0
                             12351
                             0.431  # seconds

This code appears to be quite slow when one consider that I have to run it for all the possible choices of C and P (the contect is detailed below).

Do you have any some ideas to improve the efficiency (in terms of computational time) of this counting operation?
Thanks in advance





The context:
Let A = {1, 2, .., L} and P(A) the power set of A.
I set Q(A) = P(A) \ ( { } union A}.
Let C and C'  two disjoint subsets of Q(A).
Example

# With L=3

Q(A) = { {1},  {2},  {3},  {1, 2},  {1, 3},  {2, 3} }

# if A chose C = 
C = {2}

# Then C' is member of 
C' in { {1}, {3}, {1, 3}

For any couple (C, C')  I want to do this

  1. Let |C| (|C'|) cardinal of C (resp C').
     
  2. Let us consider that members of C (resp C') "point to" the corresponding columns of M.
    for instance C = {2, 3} refers to columns 2 and 3 of M.
    As C and C' are ordered iI will write them indistinctely as lists (for instance C = [2, 3] in example above) when necessary.
     
  3. To a given |C| (|C'|) one may associate 2|C| (resp 2|C'|) sequences of 0 and 1.
    For instance,  to C = {2, 3} are associated sequences [0, 0], [0, 1], [1, 0], [1, 1].
    Let s(C) (s(C')) the list, or set, of 0-1 sequences associated to C (resp C')..
     
  4. For any couple (C, C') and any of the 2|C|+|C'| combinations (p, p') where p belongs to s(C) and p' belongs to s(C') I want to count the number of occurrences defined by: 
    seq( M[n, C[k]] = p[k], k=1..|C|) and seq( M[n, C'[k]] = p'[k], k=1..|C'|) 

    For instance, if C={2} and C={1, 3} I want to count the number M rows M such that 

    p = [0], p'=[1, 0]
    M[n, 2]=0 and M[n, 1]=1 and M[n, 3]=0;
    
    p = [1], p'=[1, 1] 
    M[n, 2]=1 and M[n, 1]=1 and M[n, 3]=1
    
    ... and so on

The computational time may ne quite large because of the number of possible couples (C, C') when L is large ( there exists  Stirling2(L+1, 3) such couples: already 90 couples for L=5  ... and 28501 for L=10).

Hi,

I hope everyone is fine here. I want to write the following nested loop in my code

restart; TOL := 10^(-3); v[i] := 10^(-4); u[i] := 10^(-4);
if abs(v[i]-1)<=TOL then    if abs(u[i])<=TOL then break    else t[i+1]:=t[i]+alpha; else; fi; fi;

it is not working. If the first condition (v[i]-1)<=TOL is fulfilled, then we have to check the second condition, u[i]<=TOL. That’s why I don’t use “and” here. If both conditions are fulfilled, then stop the loop and if second the condition not fulfilled (but first fulfill) then t[j+1]=t[j]+alpha. 

I shall be waiting for your positive response.

How to solve a ODE system using Newton's finite difference method?
How to plot f', theta and phi functions for various alpha values.

Difference.mw

Dear All,

I want all calculations in Maple code to be done with double precision. Using Digits:=18 and evalf greatly affects the calculation speed. But using the evalhf performs calculations much faster. The problem is that the evalhf cannot work with expressions that contain symbolic terms. For example, the evalhf(1/3*x+1/5*exp(-x^2)) generates an error. How can I perform calculations on expression with double-precision floating point without significantly slowing down the calculation speed? Is there a method that can be used at the beginning of the code to use double precision (preferably hardware) in all computation steps without slowing down the computations, unlike software floating-point computations?
Best wishes
 

Digits:=18;
evalf(1/3.);
evalhf(1/3.);


str:=time[real]();
for i from 1 to 100000 do
evalf(sqrt(3)*i):
end do:
time[real]()-str;

 

str:=time[real]();
for i from 1 to 100000 do
evalhf(sqrt(3)*i):
end do:
time[real]()-str;

 

Dear All,

I have the following algebraic function. In vibrations, it is common to write the functions exp(alpha[i]*I*t) as separate terms of cos(alpha[i]*t) and sin(alpha[i]*t). While exp(-beta[i]*t) remains without converting to sinh and cosh. How can I find the solution given for T(t) as the sum of terms C1[i]*sin(alpha[i]*t)*exp(-beta[i]*t) and C2[i]*cos(alpha[i]*t)*exp(-beta[i]*t) with non-complex (real) coefficients C1[i] and C2[i].

Can anyone help me to achieve my goal in the following expression?

 

T(t):=(1.450761945*10^(-11) + (3.836655196*10^(-14))*I)*exp((-0.5000000000 + 222.6866468*I)*t) + (-3.770333746*10^(-9) + (2.179000257*10^(-6))*I)*exp((-0.5000000000 - 924.5904413*I)*t) + (-2.584086158*10^(-12) + (4.273321932*10^(-13))*I)*exp((-0.5000000000 + 326.7549627*I)*t) + (1.986287340*10^(-9) + (1.330623218*10^(-11))*I)*exp((-0.5000000000 - 74.63720909*I)*t) + (-5.980910367*10^(-12) + (5.816480027*10^(-11))*I)*exp((-0.5000000000 - 453.7574402*I)*t) + (1.450761945*10^(-11) - (3.836655196*10^(-14))*I)*exp((-0.5000000000 - 222.6866468*I)*t) + (8.923968224*10^(-10) - (8.844466162*10^(-9))*I)*exp((-0.5000000000 + 637.9999953*I)*t) - (1.217986141*10^(-10) + (4.431771836*10^(-13))*I)*exp((-0.5000000000 - 138.7904660*I)*t) + (-1.217986141*10^(-10) + (4.431771836*10^(-13))*I)*exp((-0.5000000000 + 138.7904660*I)*t) + (0.0002537882980 + 0.00002277791755*I)*exp((-0.5000000000 - 5.570928456*I)*t) - (3.770333746*10^(-9) + (2.179000257*10^(-6))*I)*exp((-0.5000000000 + 924.5904413*I)*t) + (-0.0001618723219 + 0.01288449595*I)*exp((-0.5000000000 - 1638.001654*I)*t) + (8.923968224*10^(-10) + (8.844466162*10^(-9))*I)*exp((-0.5000000000 - 637.9999953*I)*t) + (-1.153529195*10^(-7) + (1.908444485*10^(-9))*I)*exp((-0.5000000000 + 30.22171212*I)*t) - (1.153529195*10^(-7) + (1.908444485*10^(-9))*I)*exp((-0.5000000000 - 30.22171212*I)*t) - (0.0001618723219 + 0.01288449595*I)*exp((-0.5000000000 + 1638.001654*I)*t) + (1.986287340*10^(-9) - (1.330623218*10^(-11))*I)*exp((-0.5000000000 + 74.63720909*I)*t) + (0.0002537882980 - 0.00002277791755*I)*exp((-0.5000000000 + 5.570928456*I)*t) - (5.980910367*10^(-12) + (5.816480027*10^(-11))*I)*exp((-0.5000000000 + 453.7574402*I)*t) - (2.584086158*10^(-12) + (4.273321932*10^(-13))*I)*exp((-0.5000000000 - 326.7549627*I)*t);

Dear All,

I have the given expression f as follows. I want to extract terms with sin, sinh, and exp in this expression. For example, for sin, cos, sinh and exp, I want the outputs to be -4*sin(x), -5*cos(x^3)*sin(y^2), 5*sinh(x^2) and 2*exp(y^2), respectively. Also, if I want to get terms having sin(x) and sin(y^2), I like to receive -4*sin(x) and -5*cos(x^3)*sin(y^2), respectively. And also, for terms including sinh(x^3), I want to get Void output. The above goals cannot be achieved with the following commands. Can anyone help me?

f := -4*sin(x) + 2*exp(y^2) + 5 - 5*cos(x^3)*sin(y^2) + 5*sinh(x^2);

indets(f, trig);

selectfun(f, exp);

selectremove(has, f, trig);

Multiplaction "dot" in Maple 2022 is way too small - causes errors.

e.g. two variables multiplied s*m ends up being sm a new variable as I cannot really see that there is a missing multiplication operator between the variables. This causes huge unnecessary errors.

Maple 9.x e.g had nice clear and big operators and this kind of error was avoided.

How can I undo this unfortunate regression in Maple 2022 to increase the size of multiplication operator and other operators, so that they actually becom visible and not just a little dot almost a pixel in size.

If I was a falcon (20x20)^infinity then this would have been ok, but I am not, I am human.

So how do I change this unfortunate regression so that these errors can be avoided.?

It was found on the social networks of the WM group. Written in Python. Perhaps someone would like to adopt it.
 

Deal All,

I have a system of linear differential equations with unknown functions T[1](t) to T[n](t). In the attached example, I considered the value of n equal to 10, but depending on the problem, the value of n may be higher. Maple is not able to solve this problem analytically with the ‘dsolve’. 

Does anyone have an idea to analytically solve for such a set of linear differential equations?

Best wishes

Set_of_Linear_DEs.mw

See attached worksheet in Maple 2023.

This example is taken from the Maple help page. I want to 'zoom in' on a plot3d object. The only way I have found was from responses [1] on the maple primes forum. It uses InlinePlot and the scale option to perform the 'zoom in'. Since InlinePlot generates the plot in terms of XML there is no graphic out, only a text based output. In order to reconstitute the InlinePlot as a plot object I can view visually I need to use some additional commands from the DocumentTool package. This is all great but the output, which in our case is P3, is not a plot object and therefore cannot be exported as a png. Is there a way to convert the InlinePlot with the scaling applied back to a typical plot object so I can export it as a .png, using Export("output_plot.png",P3,base=worksheetdir)?

can_I_convert_InlinePlot(P3)_back_to_a_regular_plot_object_so_I_can_export_it_as_a_png.mw

When I try to contract the tensor with connection, maple encounters such promble:

Error, (in DifferentialGeometry:-Tensor:-ContractIndices) expected 2nd argument to be a tensor. Received: _DG([["connection", O, [["con_bas", "cov_bas", "cov_bas"], []]], [`...`]])

The expression is Cacd Hab

I try to solve triple integraton in Maple with this code.

r := a + (b - a)*z/h;
x1 := sqrt(r^2 - y^2);
V := int(int(int(1, x = -x1 .. x1), y = -r .. r), z = 0 .. h);

but it leaves the last integral dz in the answer and warns: unable to determine if a*h/(-b+a) is between 0 and h; try to use assumptions or use the AllSolutions option
What is the problem?
and i need to get V = Pi*h(a^2 + ab +b^2)/3

Regards

Why does Maple 2022 still have only a history of ten files in the Recents ?

It makes it very difficult to search for files you opened but only realised later you need, but then it is long out of the silly 10 history list.

Isnt there a way to make a perpetual list so that all files opened are saved chronologiacally against date, or... at least be able to increase the silly 10 recent files to something like 30

Thanks

This is a follow on from and earlier question on tabulation. Some procdures returs up tp eight values. So using a Table make it easier to see what is what. Sometimes the equations returned are very long. Is there a way to truncate what is display in the table using something along the lines of term elision? Say the 1st 300 chatacters for example?  

Edit: Corrected an error in the worksheet.

restart

QQFProj := proc(q12::algebraic, q23::algebraic,
                q34::algebraic, q14::algebraic,
                  prnt::boolean:=true) #{columns:=[QQFproj,Q13proj,Q24proj]}
  description "Projective quadruple quad formula and intermediate 13 and 24 quads. Useful for cyclic quadrilaterals";
  local qqf,q13,q24, sub1,sub2,sub3, R,values,DF,lens;
  uses   DocumentTools;
  sub1:= (q12 + q23 + q34 + q14)^2 - 2*(q12^2 + q23^2 + q34^2 + q14^2) ;
  sub2:=-4*(q12*q23*q34+q12*q23*q14+q12*q34*q14+q23*q34*q14)+8*q12*q23*q34*q14;
  sub3:=64*q12*q23*q34*q14*(1-q12)*(1-q23)*(1-q34)*(1-q14);
  qqf:=((sub1+sub2)^2=sub3);
  q13:=((q12-q23)^2-(q34-q14)^2)/(2*(q12+q23-q34-q14-2*q12*q23+2*q34*q14));#check this
  q24:=((q23-q34)^2-(q12-q14)^2)/(2*(q23+q34-q12-q14-2*q23*q34+2*q12*q14));#check this
  if prnt then
  
   values:=<qqf,q13,q24>;
   DF:=DataFrame(<values>, columns=[`"Values Equations"`],rows=[`#1  QQF`,`#2  Q13`,`#3  Q24`]);
   lens := [4 +8* max(op(length~(RowLabels(DF)))),4+ min(max( 10*(length~(values))),1000)];#op(length~(ColumnLabels(DF)0)
   Tabulate(DF,width=add(lens),widthmode = pixels,weights = lens);
  return qqf,q13,q24
  end if;
  return qqf,q13,q24
end proc:

 q12:=1/2:q23:=9/10:q34:=25/26:q41:=9/130:#Cyclic quadrilateral
q12:=sqrt(17+a)/2:q23:=expand(r^2+t^2)^2/10:q34:=expand((a+b+c)^4/26):q41:=sqrt(17+b)/130:

Q:=QQFProj(q12,q23,q34,q41,true):

#Q[1]

#(Q[2])

#Q[3]

length(Q[1])

2669

(1)

length(Q[2])

1024

(2)

length(Q[3])

1024

(3)
 

 

Download 2024-05-14_Q_Data_Table_Limit_Equation_lentgh.mw

In my code, why  does InitState(5,5) return only one element of the vector while Coherent(5) returns 5 elements of the vector?

restart;

with(LinearAlgebra):

 

Coherent := proc({zeta:=1,phi:=Pi/2},n_max) local alpha,i,ICs:
 #alpha := sqrt(zeta)*exp(I*phi):
 ICs := Vector(n_max,i->evalc(evalf(exp(-zeta/2)/sqrt((i-1)!))*(sqrt(zeta)*exp(I*phi))^(i-1)),datatype=complex[8]);
end proc:

Projectile := proc({L:=1,sigma:=0.01,beta:=0.02,k0:=-5*Pi},n_max) local x0,g,c,v,ICs,j:
  x0 := evalf(beta*L);
  g := unapply(exp(-(x-x0)^2/2/sigma^2),x);
  c := evalf(int(g(x)^2,x=-L/2..L/2,numeric=true));
 
  v:=Vector(n_max,datatype=complex[8]);

  for j from 1 to n_max do:
     if (is(j,odd)) then  v[j]:= evalc[8](evalf(Int(cos(Pi*j*x/L)*g(x)*cos(k0*x),x=-L/2..L/2,method=_d01akc))+ I*evalf(Int(cos(Pi*j*x/L)*g(x)*sin(k0*x),x=-L/2..L/2,method=_d01akc)));
      else v[j]:= evalc[8](evalf(Int(sin(Pi*j*x/L)*g(x)*cos(k0*x),x=-L/2..L/2,method=_d01akc))+ I*evalf(Int(sin(Pi*j*x/L)*g(x)*sin(k0*x),x=-L/2..L/2,method=_d01akc)));
     end if:
  end do:

 ICs :=evalf[8](sqrt(2/L*c))*v;
end proc:

InitState := proc({zeta:=1,phi:=Pi/2,L:=1,sigma:=0.01,beta:=0.02,k0:=-5*Pi},d1,d2) local Z0:
z1 := Coherent(zeta,phi,d1);
#Z0:= MatrixMatrixMultiply(Coherent(zeta,phi,d1),Transpose(Projectile(L,sigma,beta,k0,d2))):
end proc:

Warning, (in InitState) `z1` is implicitly declared local

 

InitState(5,5); Coherent(5);

Vector(1, {(1) = .6065306597+0.*I})

 

Vector[column](%id = 36893490076814315516)

(1)
 

 

Download test3.mw

First 105 106 107 108 109 110 111 Last Page 107 of 2216