tomleslie

13876 Reputation

20 Badges

15 years, 164 days

MaplePrimes Activity


These are answers submitted by tomleslie

  1. If I click on Updates in the MapleCloud window, then the Physics Updates package appears
  2. If I install the latest version (1033), then restart Maple
  3. Issue the command Physics:-Version(), the output is (my highlighting)

 

`The "Physics Updates" version in the MapleCloud is unable to determine. The version installed in this computer is 1033 created 2021, August 17, 19:13 hours Pacific Time, found in the directory C:\\Users\\TomLeslie\\maple\\toolbox\\2021\\Physics Updates\\lib\\`

So something has got a bit broken!

Several years ago I had occasion to write a really, really efficient Eratosthenes Sieve (can't now remember why!) - and I spent ages on it. I came with the code in the following and in the attached erato.mw (which also contain Acer's code for comparison puposes)

I'm not trying to start a competition here (because I'd almost certainly lose!) - but to illustrate the level of improvement which is (sometimes) possible throiugh a combination of very careful coding (and outright experimentation!). Like Acer, I haven't used any kind of compilation/parallelization etc, The code sieve() is around 7-8X faster than the code Eratosthenes2()

  restart;
  Eratosthenes2 := proc(N::posint) 
                        local L, n, k; 
                        description "Calculate all primes less than or equal to N"; 
                        L := Array(2 .. N, i->true); 
                        for n from 2 to trunc(sqrt(N)) do 
                            if L[n] = true then 
                               for k from n while k*n <= N do 
                                   L[k*n] := false
                               od;
                            fi; 
                        od; 
                       seq(`if`(L[n]=true,n,NULL), n=2..N);
                   end proc:

  Eratosthenes2(32);
  CodeTools:-Usage(Eratosthenes2(2^20)):
  nops([%]);
  restart;
  sieve:= proc( N::integer ) :: list;
                local j, k, prArr;
                description "The sieve of Eratosthenes":
	      #
	      # Initialise the array with all even indices
	      # >=4 set to zero: other entries set to 1
	      #
                prArr:= Array( 2..N,
                   	       [1,1, seq( '0,1',
  			                   j = 2..N/2
		                        )
                               ]
                             ):
              #
	      # cycle through all odd multiples (other than 1)
	      # of all odd indices, setting the entry to 0 
              #
                prArr[ [ seq
	                 ( seq
			   ( k*j,
                             j = k..N/k, 2
			   ),
                           k = 3..trunc(sqrt(N)), 2
                         )
	               ]
		     ]:= 0:
	      #
	      # Return the indices which have non-zero entries
	      #
                return [ 2, seq
		            ( `if`
			      ( prArr[j]=0,
 			        NULL,
			        j
			      ),
			      j = 3..N, 2
			    )
		       ]:
          end proc:
  sieve(32);
  CodeTools:-Usage(sieve(2^20)):
  nops(%);

Output from using Eratosthenes2() in the above

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31
memory used=184.74MiB, alloc change=21.00MiB, cpu time=3.82s, real time=3.82s, gc time=1.42s
82025

Output from using sieve() in the above

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
memory used=79.61MiB, alloc change=61.75MiB, cpu time=577.00ms, real time=516.00ms, gc time=124.80ms
82025

So sieve() uses about the half the memory and runs about 7-8X faster

 

 

What is wrong with the code below (and attached getCoeffs.mw);

  restart:
  expr:= 3*P^4*a[2]^2 + 6*P^2*q^2*B[2]*a[2] + 3*q^4*B[2]^2 +P^4*C[3] +\
         P^3*Q*C[3] + 6*P^3*a[1]*a[2] + 6*P^2*Q*B[1]*a[2] + p*q^3*d[3];
  coeffs(expr, [p, P, q, Q]);

which produces

3*a[2]^2 + C[3], C[3], 6*a[1]*a[2], 6*B[1]*a[2], 6*B[2]*a[2], d[3], 3*B[2]^2

 

 

I suggest you read the comments in the attached trickplot.mw which produces the plot below. (it renders rather better in a Maple worksheet than it does on this site - honest!)

 

what algorithm you are trying to implement, but (after fixing a minor typo) it is pretty obvious that the approach will not lead to any meaningful answers. See the more detailed comments in the attached pert.mw

If I use the DirectSearch:-SolveEquations() command with the option AllSolutions=true, I can generate 10 solutions for your problem. Based on the reported residuals, they all look pretty plausible (see the attached DSagain.mw )- although (interestingly?) none of these seem to correspond to the solution given by the in-built fsolve() command. So maybe there(at least?) are eleven solutions?

A warning, the above woksheet takes a while to produce - maybe 2 minutes on my machine, although I wasn't timing accurately.!

The DirectSearch() package is a free add-on which can be downloaded from the Maple Application Centre at

https://www.maplesoft.com/applications/view.aspx?SID=101333

 

You should (probably?) be using the plottools:-cylinder() command to create the cylinder . Also use plots:-implicitplot3d() to create the ellipsoidal end cap. Then use the plottools:-reflect() and plottools:-translate() to locate two copies of the basic endcap in the at the appropriate points of the combined figure.

So the code below (also attached ellCyl.mw )

  restart;
  with(plots):
  with(plottools):
  cylRad:= 1:
  cylHeight:= 4:
  ecc:= 1/2:
#
# The cylinder
#
  p1:= cylinder
       ( [0,0,-cylHeight/2],
         cylRad,
         cylHeight,
         strips=128,
         capped=false,
         color=red,
         style=surface,
         scaling=constrained
       ):
#
# The basic endcap
#
  p2:= implicitplot3d
       ( x^2/cylRad^2+y^2/cylRad^2+z^2/ecc^2=1,
         x=-cylRad..cylRad,
         y=-cylRad..cylRad,
         z=0..ecc,
         color=red,
         style=surface,
         scaling=constrained
       ):
#
# Display the cylinder and two endcaps. Note
# that one endcap is a translation of the
# basic endcap above: the other is a reflection
# of the basic endcap above in the plane z=0 as
# well as a translation
#
  display( [ p1,
             translate( p2, 0, 0, cylHeight/2 ),
             translate
             ( reflect( p2, [0,0,0], [1,0,0], [0,1,0] ),
               0, 0, -cylHeight/2
             )
           ],
           axes=none
         );

produces the figure

Obviously there are many other plotting options whihc can be used, depending on how you want to play with the final appearance

is to use the TravellingSalesman() command from the GraphTheory() package.

The following code (attached here travSale.mw)

  restart;
  with(GraphTheory):
  local D:
  pts := [A=[0, 0], B=[1, 1], C=[2, 5], D=[4, 2], E=[5, 3]]:
  G:= Graph
      ( { seq
          ( seq
            ( [ {lhs(pts[i]), lhs(pts[j])},
                add( abs~(rhs(pts[i])-rhs(pts[j])))
              ],
              j=i+1..numelems(pts)
            ),
            i=1..numelems(pts)-1
          )
        }
      ):
  dist, tour:= TravelingSalesman(G);
  HighlightTrail(G, tour);
  DrawGraph(G, stylesheet="legacy");

produces both the total distance and the 'trail'. (Note that there may be more than one 'trail' with the same minimum distance)

dist, tour := 20, [A, B, C, E, D, A]

As well as the figure

to obtain the *same* result in different ways. The code below (and attached here intTut.mw) solves your specific problem in two (slightly) different ways

  restart;
  with(Student[Calculus1]):
  expr:=Int(t^2*exp(-11*t),t);
#
# First method - starts with a change of variable
#
  Rule[ [ change, u = -11*t, u ] ](expr);
  Rule[ [ constantmultiple ] ](%);
  Rule[ [ parts, u^2, exp(u) ] ](%);
  Rule[ [ constantmultiple ] ](%);
  Rule[ [ parts, u, exp(u) ] ](%);
  Rule[ [ exp ] ](%);  
  Rule[ [ revert]  ](%);
 
#
# Second method - starts with integration by parts
#
  Rule[ [ parts, t^2, -exp(-11*t)/11 ] ](expr);
  Rule[ [ constantmultiple ] ](%);
  Rule[ [ parts,t, -exp(-11*t)/11 ] ](%);
  Rule[ [ constantmultiple ] ](%);
  Rule[ [ change, u = -11*t, u ] ](%);
  Rule[ [ constantmultiple ] ](%);
  Rule[ [ exp ] ](%);
  Rule[ [ revert ] ](%);

 

of which the attached (drawLines.mw) is only one. It produces the plots below. These plots "render" rather better in a Maple worksheet than they do on this site - honest.

 

 

 

 

you can't use an inequality in an eval() statement - so it is not 100% clear what you are trying to achieve.

The execution group at the end of the attached will check whether a supplied 'guess' is a valid value for the quantity 'xC1', and if it is, will return corresponding values for 'Rsrc' and 'xC2'.

evalStuff.mw

the 'legend' option is only available for 2D plots - since surfdata() is a 3D plot, there is no (in-built) method for doing this, although a variety of workarounds have been shown on this site in the past. As an example see

https://www.mapleprimes.com/questions/210870-Legends-For-3d-Plots

for one way

problem - but with multiple possible solutions depending on what you are trying to achieve.

The matrix you wish to export has entries delimited by square brackets - ie []. Excel generally does not use '[]' characters for other than rather obscure circumstances (eg structured table references, and references from within a worksheet to data in 'external files').

So why do you want to include '[]' characters in your export to Excel? What do you hope they will mean?

I see two choices

Convert every matrix entry enclosed within '[]' characters to a string, and export the result, so for example the code attached (xl1.mw), and shown below will produce the excel file test0.xlsx

  restart;
#
# OP will have to change the pathname to something
# relevant to his/her machine
#
  pathName:="C:/Users/TomLeslie/Desktop/":
  M1:= Matrix(5, 2, [ [ "Graph 1", 0],
                      [ [3,3], 3],
                      [ [2, 3], 4],
                      [ [2, 2], 3],
                      [ [1, 3], 2]
                    ]
             ):
  M2:= Matrix(6, 2, [ [ "Graph 2", 0],
                      [ [3,3], 2],
                      [ [2, 3], 5],
                      [ [2, 2], 8],
                      [ [1, 3], 3],
                      [ [1, 2], 1]
                    ]
             ):
#
# Concatenate the two matrices
#
  M3:= <M1, M2>;
#
# Covert all list entries in the above to strings
#
  f:= x-> `if`( type(x, list),
                convert(x, string),
                x
              ):
  M4:=f~(M3);
#
# Export the result
#
  ExcelTools:-Export(M4, cat(pathName, "test0.xlsx"), "Sheet1", "B2");

However the drawback with this approach is that all data in column B of the Excel spreadsheet will be of type string, so doing anything "mathematical" with this data in Excel will be a bit "painful"

#############################################################################################

The second possibility is to consider the "interpretation"  of the data in your original matrices. For example if the row

[2,2] 3

can be sensibly interpreted

[x_value, y,_value] f(x_value, y_value)

then it may be a better approach to export as a matrix with three columns - ie

x_value y_value f(x_value, y_value)

This attachment ( xl2.mw ) containing the code below will produce the Excel file test1.xlsx

  restart;
#
# OP will have to change the pathname to something
# relevant to his/her machine
#
  pathName:="C:/Users/TomLeslie/Desktop/":
  M1:= Matrix(5, 2, [ [ "Graph 1", 0],
                      [ [3,3], 3],
                      [ [2, 3], 4],
                      [ [2, 2], 3],
                      [ [1, 3], 2]
                    ]
             ):
  M2:= Matrix(6, 2, [ [ "Graph 2", 0],
                      [ [3,3], 2],
                      [ [2, 3], 5],
                      [ [2, 2], 8],
                      [ [1, 3], 3],
                      [ [1, 2], 1]
                    ]
             ):

  labs:=<"x" | "y" | "data">;
  f:= mat-> local j:
             < seq( < mat[j,1][1] | mat[j, 1][2] | mat[j,2]>, j=2..op([1,1], mat))>:
  M3:= < cat~(M1[1,1], ":", labs),
         f(M1),
         cat~(M2[1,1], ":", labs),
         f(M2)
       >;
#
# Export the result
#
  ExcelTools:-Export(M3, cat(pathName, "test1.xlsx"), "Sheet1", "B2");

Rather than *converting* the required matrices, it may be a better approach to generate them in the required format in the first place

 

For your simple example, the code in the attached ( planar.mw ) and shown below will  generate the correspondence between faces in the original graph  and vertices in the dual graph. Note that this is pretty rough - it only works when all faces in the original graph have 3 (or fewer?) edges.

  restart;
  with(GraphTheory):
  g:=Graph({{1,2},{2,4},{3,4},{2,3},{1,3},{1,4},{4,5},{2,5},{1,5}}):
  IsPlanar(g, faces);
  DrawPlanar(g);
#
# The easy way!
#
  dual_g:=PlaneDual(g);
  DrawPlanar(dual_g);
#
# Show the list of faces of the original graph
#
  faces;
#
# Generate a list of names where the n-th entry
# in the lst corresponds to the n-th face in the
# list of faces
#
  Vnames:= [ seq
             ( cat
               ( V, StringTools:-Char(j)
               ),
               j=65..65+numelems(faces)-1
             )
           ];
#
# When two entries in the list of faces share two
# entries this represents an edge in the dual graph.
# The following finds all teh edges for a 3-conected
# graph
#
  myEdges:= { seq
              ( seq
                ( `if`
                  ( numelems
                    ( `intersect`
                      ( convert(faces[i], set),
                        convert(faces[j], set)
                      )
                    )=2,
                    {Vnames[i], Vnames[j]},
                    NULL
                  ),
                  j=i+1..numelems(faces)
               ),
               i=1..numelems(faces)-1
             )
           };
 g2:=Graph( Vnames, myEdges);
 DrawPlanar(g2);

If you want a more general solution, the obvious thing to do is start with the code used by Maple, which can be examined by using

with(GraphTheory);
showstat(PlaneDual);

Maple version

Maple 18.02, Windows 7, October 20 2014 Build ID 991181                           working
Maple 2015.2, Windows 7, December 21 2015 Build ID 1097895                   working
Maple 2016.2, Windows 7, January 13 2017 Build ID 1194701                       working
Maple 2017.3, Windows 7, September 13 2017 Build ID 1262472                  working
Maple 2018.2, Windows 7, November 16 2018 Build ID 1362973                   working
Maple 2019.2, Windows 7, November 26 2019 Build ID 1435526                   not working
Maple 2020.2, Windows 7, November 11 2020 Build ID 1502365                   not working
Maple 2021.1, Windows 7, May 19 2021 Build ID 1539851                             working

First 43 44 45 46 47 48 49 Last Page 45 of 207