tomleslie

13876 Reputation

20 Badges

15 years, 181 days

MaplePrimes Activity


These are replies submitted by tomleslie

Firstly I have no issue about the danger associated with indexing on manipulated sets - I consider this to be an evil activity which no-one should attempt!

However I am still interested in the performance penalties (if any) of using the MutableSet() container - because so far I haven't found one (see the attached). Whilst playing with some possibilities I accidentally discovered, that a map[inplace]() command on a non-mutable set *looks* as if it works (ie no warnings/Errors), but actually does nothing. I would have expected a rude message!

  restart;

  f:=i->`if`(i::odd, i^2,i):
  nelem:=1000000:
#
# Generate a set of integers.
#
  S := {seq(i,i=1..nelem)}:
#
# Square the odd ones.
#
  P:=CodeTools:-Usage(map(f, S)):
#
# Check it works!
#
  P[1..10];
#
# Now do it with an 'inplace' map. I expected
# to get a rude message from this attempt - but
# no warnings, no errors. It just doesn't work!
#
  CodeTools:-Usage(map[inplace](f, S)):
  S[1..10];
#
# Now do the same thing with a MutableSet()
#
  M:=MutableSet( seq(i,i=1..nelem) ):
  CodeTools:-Usage(map[inplace]( f, M)):
  seq(M[i], i=1..10); # Mutable sets don't support range indexing!

memory used=109.81MiB, alloc change=10.64MiB, cpu time=1.40s, real time=1.41s, gc time=514.80ms

 

{1, 2, 4, 6, 8, 9, 10, 12, 14, 16}

 

memory used=106.83MiB, alloc change=6.63MiB, cpu time=1.68s, real time=1.68s, gc time=842.41ms

 

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

 

memory used=83.90MiB, alloc change=0 bytes, cpu time=1.51s, real time=1.34s, gc time=436.80ms

 

1, 2, 4, 6, 8, 9, 10, 12, 14, 16

(1)

 

Download mutSets.mw

 

@Sabrina Kamal 


 

restart

xx := Array([1.666666667, 1.941333333, 2.344, 2.842666667, 3.405333333, 4, 4.6, 5.2, 5.8, 6.4, 7, 7.593333333, 8.146666667, 8.62, 8.973333333, 9.166666667, 9.172, 9.009333333, 8.710666667, 8.308, 7.833333333, 7.316, 6.774666667, 6.225333333, 5.684, 5.166666667])

yy := Array([2.333333333, 1.974666667, 1.704, 1.529333333, 1.458666667, 1.5, 1.654666667, 1.897333333, 2.196, 2.518666667, 2.833333333, 3.117333333, 3.385333333, 3.661333333, 3.969333333, 4.333333333, 4.769333333, 5.261333333, 5.785333333, 6.317333333, 6.833333333, 7.314666667, 7.764, 8.189333333, 8.598666667, 9])

L := 5; W := (1/2)*L; angle := (1/12)*Pi

for i to 26 do x := xx(i); y := yy(i); eq1 := (a-x)^2+(b-y)^2 = (L^2+W^2)*(1/4); eq2 := (c-x)^2+(d-y)^2 = (1/4)*L^2; eq3 := (c-a)^2+(d-b)^2 = (1/4)*W^2; angle2 := evalf(tan(angle+(1/4)*Pi)); eq4 := (b-y)/(a-x) = angle2; ans := solve({eq1, eq2, eq3, eq4}, {a, b, c, d}); P1[i] := eval(a, {ans}[4]); Q1[i] := eval(b, {ans}[4]); x1[i] := eval(c, {ans}[4]); y1[i] := eval(d, {ans}[4]); eq5 := (Q1[i]-y1[i])/(P1[i]-x1[i]) = (Q1[i]-f)/(P1[i]-e); eq6 := (e-P1[i])^2+(f-Q1[i])^2 = W^2; ans2 := solve({eq5, eq6}, {e, f}); P2[i] := eval(e, {ans2}[2]); Q2[i] := eval(f, {ans2}[2]); eq7 := (Q2[i]-h)/(P2[i]-g) = (y1[i]-y)/(x1[i]-x); eq8 := (P2[i]-g)^2+(Q2[i]-h)^2 = L^2; ans3 := solve({eq7, eq8}, {g, h}); P3[i] := eval(g, {ans3}[1]); Q3[i] := eval(h, {ans3}[1]); eq9 := (Q1[i]-k)/(P1[i]-j) = (y1[i]-y)/(x1[i]-x); eq10 := (P1[i]-j)^2+(Q1[i]-k)^2 = L^2; ans4 := solve({eq10, eq9}, {j, k}); P4[i] := eval(j, {ans4}[1]); Q4[i] := eval(k, {ans4}[1]); print(i, P1[i], Q1[i], P2[i], Q2[i], P3[i], Q3[i], P4[i], Q4[i]) end do

plots:-display([seq(plot(`<,>`(`<|>`(`<,>`(P1[i], P2[i], P3[i], P4[i], P1[i]), `<,>`(Q1[i], Q2[i], Q3[i], Q4[i], Q1[i]))), color = black), i = 1 .. 26)])

 


 

Download doPlot.mw

 

@Carl Love 

is that OP originally claimed to be using Maple 2017, not Maple 17! Quote from earlier in this thread

@tomleslie Thank you for the reply. I am using Maple 2017. Please find the attached files as requested.inteliTry1.mw, inquiry1.xls Thanks once again.


So I checked it in Maple 2017, where the default format for ExcelTools:-Import() is 'Matrix'. OP later stated that (s)he was using Maple 17!

At some point between Maple 17 and Maple2017 the default format for ExcelTools:-Import() changed from 'Array' to 'Matrix'. I can't actually check in Maple 17, because the earliest version I have is Maple 18. However this exhibits the same issue.

In Maple 18 the probem can be fixed by putting the Import() statements within a Matrix() command. So the attached works in Maple 18, (and hopefully in Maple 17!)


 

restart; kernelopts(version); with(ExcelTools); M1A := Matrix(Import("C:/Users/TomLeslie/Desktop/Inquiry1.xls", "Sheet1", "A3:E9")); M2A := Matrix(Import("C:/Users/TomLeslie/Desktop/Inquiry1.xls", "Sheet2", "A3:E8")); f := proc (x) options operator, arrow; sqrt(x)+1 end proc; M1B := `<|>`(M1A, `~`[f](M1A[() .. (), 5])); M2B := `<|>`(M2A, `~`[f](M2A[() .. (), 5])); g := proc (x, y) options operator, arrow; zip(proc (i, j) options operator, arrow; i^2+j end proc, x, y) end proc; M1C := `<|>`(M1A, g(M1A[() .. (), 2], M1A[() .. (), 4])); M2C := `<|>`(M2A, g(M2A[() .. (), 2], M2A[() .. (), 4]))

`Maple 18.02, X86 64 WINDOWS, Oct 20 2014, Build ID 991181`

 

M1A := Matrix(7, 5, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7})

 

M2A := Matrix(6, 5, {(1, 1) = "JAN", (1, 2) = 29.1, (1, 3) = 36.9, (1, 4) = 29.2, (1, 5) = 35.1, (2, 1) = "FEB", (2, 2) = 32.1, (2, 3) = 39.1, (2, 4) = 30.0, (2, 5) = 37.4, (3, 1) = "MAR", (3, 2) = 31.9, (3, 3) = 39.5, (3, 4) = 31.6, (3, 5) = 37.7, (4, 1) = "APRIL", (4, 2) = 32.0, (4, 3) = 39.5, (4, 4) = 31.5, (4, 5) = 37.7, (5, 1) = "MAY", (5, 2) = 30.6, (5, 3) = 372.0, (5, 4) = 30.1, (5, 5) = 35.3, (6, 1) = "JUNE", (6, 2) = 28.3, (6, 3) = 33.1, (6, 4) = 28.3, (6, 5) = 32.0})

 

M1B := Matrix(7, 6, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (1, 6) = 6.477225575, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (2, 6) = 6.522680509, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (3, 6) = 6.477225575, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (4, 6) = 6.630275304, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (5, 6) = 6.753259945, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (6, 6) = 6.865151319, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7, (7, 6) = 6.805170109})

 

M2B := Matrix(6, 6, {(1, 1) = "JAN", (1, 2) = 29.1, (1, 3) = 36.9, (1, 4) = 29.2, (1, 5) = 35.1, (1, 6) = 6.924525297, (2, 1) = "FEB", (2, 2) = 32.1, (2, 3) = 39.1, (2, 4) = 30.0, (2, 5) = 37.4, (2, 6) = 7.115553941, (3, 1) = "MAR", (3, 2) = 31.9, (3, 3) = 39.5, (3, 4) = 31.6, (3, 5) = 37.7, (3, 6) = 7.140032573, (4, 1) = "APRIL", (4, 2) = 32.0, (4, 3) = 39.5, (4, 4) = 31.5, (4, 5) = 37.7, (4, 6) = 7.140032573, (5, 1) = "MAY", (5, 2) = 30.6, (5, 3) = 372.0, (5, 4) = 30.1, (5, 5) = 35.3, (5, 6) = 6.941380311, (6, 1) = "JUNE", (6, 2) = 28.3, (6, 3) = 33.1, (6, 4) = 28.3, (6, 5) = 32.0, (6, 6) = 6.656854249})

 

M1C := Matrix(7, 6, {(1, 1) = "JUNE", (1, 2) = 28.9, (1, 3) = 32.8, (1, 4) = 27.7, (1, 5) = 30.0, (1, 6) = 862.91, (2, 1) = "JULY", (2, 2) = 27.3, (2, 3) = 31.9, (2, 4) = 26.7, (2, 5) = 30.5, (2, 6) = 771.99, (3, 1) = "AUG", (3, 2) = 27.1, (3, 3) = 31.5, (3, 4) = 26.6, (3, 5) = 30.0, (3, 6) = 761.01, (4, 1) = "SEPT.", (4, 2) = 27.8, (4, 3) = 33.3, (4, 4) = 27.2, (4, 5) = 31.7, (4, 6) = 800.04, (5, 1) = "OCT.", (5, 2) = 28.8, (5, 3) = 34.9, (5, 4) = 28.0, (5, 5) = 33.1, (5, 6) = 857.44, (6, 1) = "NOV.", (6, 2) = 29.8, (6, 3) = 35.6, (6, 4) = 29.1, (6, 5) = 34.4, (6, 6) = 917.14, (7, 1) = "DEC.", (7, 2) = 28.5, (7, 3) = 35.1, (7, 4) = 27.9, (7, 5) = 33.7, (7, 6) = 840.15})

 

M2C := Matrix(6, 6, {(1, 1) = "JAN", (1, 2) = 29.1, (1, 3) = 36.9, (1, 4) = 29.2, (1, 5) = 35.1, (1, 6) = 876.01, (2, 1) = "FEB", (2, 2) = 32.1, (2, 3) = 39.1, (2, 4) = 30.0, (2, 5) = 37.4, (2, 6) = 1060.41, (3, 1) = "MAR", (3, 2) = 31.9, (3, 3) = 39.5, (3, 4) = 31.6, (3, 5) = 37.7, (3, 6) = 1049.21, (4, 1) = "APRIL", (4, 2) = 32.0, (4, 3) = 39.5, (4, 4) = 31.5, (4, 5) = 37.7, (4, 6) = 1055.50, (5, 1) = "MAY", (5, 2) = 30.6, (5, 3) = 372.0, (5, 4) = 30.1, (5, 5) = 35.3, (5, 6) = 966.46, (6, 1) = "JUNE", (6, 2) = 28.3, (6, 3) = 33.1, (6, 4) = 28.3, (6, 5) = 32.0, (6, 6) = 829.19})

(1)

 


 

Download xxLfunc2.mw

using the big green uparrow in the Mapleprimes - cos I'm not going to retype/edit your code from a picture! Just give me something I can work with!

If the rectangles are not parallel/perpendicular to the x/y-axes, then you need five values. Four to define the rectangle and one to define the rotation angle. (Technically you might need six, if you need to define the point about which the rotation takes place). in the following I have given two choices - firstly that the rotation is about the origin, and secondly that the rotation is about he bottom-left corner of the rectangle

restart;
with(LinearAlgebra):
with(plots):
with(plottools):
M:=RandomMatrix(21, 5):
M[..,5]:= (2*Pi/100)*M[..,5]:
display( [ seq
           ( rotate
             ( rectangle
               ( [M[i,1], M[i,2]],
                 [M[i,3], M[i,4]],
                 style=line
               ),
               M[i,5],
               [0, 0]
             ),
             i=1..21
           )
         ],
         axes=none,
         scaling=constrained
       );
display( [ seq
           ( rotate
             ( rectangle
               ( [M[i,1], M[i,2]],
                 [M[i,3], M[i,4]],
                 style=line
               ),
               M[i,5],
               [M[i,1], M[i,2]]
             ),
             i=1..21
           )
         ],
         axes=none,
         scaling=constrained
       );

 

 

 

 

Download genRect2.mw

@das1404

Sounds like web-browser issue. Depending on which browser you are using (Chrome/FireFox/IE/whatever), when you 'click' on a download  link here, you browser ought to give you some kind of dialog which goes something like

what do you want to do with this file?
with choices something like  "Save as" or, "Open with"

Choosing "Save as", you ought to get some kind of file browser in which you can navigate to a suitable location and select the file name (including extension). Your desktop is always a good bet for a location and you should ensure that your browser does not add to/change the file extension

Choosing "Open with", your browser *ought* to give you a list of applications whose association with file extensions it knows: so extensions 'doc' or 'docx' would be associated with MS Word, 'xls' or 'xlsx' would be associated with MS Excel, 'pdf' with Acroread etc. If your browser doesn't "know" the application associated with the Maple extensions 'mw', 'mws', then it *ought* to offer a list of all (installed) applicatons,  and invite you to select one: Maple ought to be on this list.

Whichever you choose, your browser will probably then ask something like "always do this with files of this type?", so that next time you try to download a Maple worksheet, it *should* happen more-or-less automatically.

Such a simple concept, which I cannot find any reference to in Maple's help. The only relevant description I can find is in the Maple Programming Guide, which states

Traditional procedural programming languages such as Pascal or C usually pass arguments
to procedures by value. This means that the procedure receives a copy of the data passed to
it. Such languages also allow values to be passed by reference. Pascal does this by prefixing
the parameter declaration with the var keyword. C requires that the parameter be declared
as a pointer, using the * prefix, and that the caller explicitly pass the address of the argument
using the & prefix (except when passing pointers to arrays).


Passing arguments by value ensures that the procedure cannot modify the passed data as a
side-effect, but requires making a copy of the data. Passing by reference is more efficient
for large data objects, but allows the procedure to (possibly unintentionally) modify the
caller's copy of the data.


In Maple, data is always passed by reference, but the immutability of most data types ensures
that the procedure cannot modify the caller's copy of the data. The exceptions are Maple's
mutable data structures: tables, Arrays, Matrices, Vectors, records, and objects. Modifying
these within a procedure will modify the caller's copy. Fortunately, these larger data structures
are the ones that you would most often want to pass by reference, since copying such data
consumes time and space.


A third argument passing convention seen in some programming languages is passing by
name. In this case, instead of passing the value of a variable, the variable itself is passed.
The called procedure can then assign a new value to the variable, which will remain in effect
when the procedure returns to the caller. Maple allows passing by name via the evaln
parameter declaration modifier, or by explicitly quoting the name when calling the procedure.
6.7 Using Data Structures with Procedures • 247


This does not contradict the earlier statement that Maple always passes by reference, because
it is now the variable name that is being passed by reference.

You probably need to read this very carefully - and even then a few experiments may be necessary to convince yourelf what is going on.. The paragraph which is worth serious consideration is

Passing arguments by value ensures that the procedure cannot modify the passed data as a
side-effect, but requires making a copy of the data. Passing by reference is more efficient
for large data objects, but allows the procedure to (possibly unintentionally) modify the
caller's copy of the data.

@Kitonum 

Construction of the for loop means that it will "bale out" when the 'while" condition fails, ie at i=15, and hence subsequent values (between i=16 and i=25?) will not be checked/printed

The following will check all values - ie all 60 rows in the OP's matrix

  with(LinearAlgebra):
  for i from 2 by 1 to op([1,1],M) do
        if      not Equal( M[i,1], M[1,1])
        then print(i, M[i, 1]);
        fi;
  od;

If OP really wants to check/print only the first 25 rows in the matrix M, then the final loop value, ie op([1,1],M), in the above should be replaced with 25

 

@vv 

OP has Maple 7.........

The attached shows your code running in Maple 2017.

The only changes I had to make were related to the location of the EXCEL file. I downloaded/stored this on my Desktop, so the filepath on the Import() command is changed to reflect this location.

I added a kernelopts(version) command so that you can check which Maple version I am running

See the attached.

Can only suggest that you execute your own code on your own machine, and save the resulting worksheet with all output. Maybe then I will be able to figure out why you have an issue

Download xlIssue.mw

And someone has broken the @Insert Contents'  on the MaplePrimes file upload, so that the file contents no longer appear here - which makes my statements above more tedious to verify

*seems* to work.

Output corresponds to that shown on your mathStackExchange link.

What is the issue?

  1. Code I posted works in Maple 2018
  2. If you are using an earlier version, I guess there *may* be a problem. What version are you using
  3. Use the big green up-arrow in the toolbar to upload two files
    1. the Excel file (.xls/.xlsx) you are using
    2. the Maple worksheet (.mw/.mws) file you are using

@das1404 

  1. No idea why you couldn't download. I deliberately saved/stored the code Maple's "older" worksheet format, ie '.mws', rather than '.mw'. Neither of these is particularly person-readable in a text editor - so as a general rule, don't bother.
  2. I can find that the seq() command was updated in Maple 10, where it states that "you can specify the increment". It would seem that prior to Maple 10, the increment was always +1??? Can't test, so can't be sure. However seq(24-j, j=1..23) will give the same downwards count, so something like [seq(j, j=1..nframes/2), seq(nframes/2-j, j=1..nframes/2-1)] *ought* to be OK for the complete list
  3. I think I've said in a previous post, that I have no way of testing in Maple 7, so you you should always treat any answer I give with "suspicion" - all I can really do is "keep it simple"

@nm 

because I was just about to post the kernelopts(opaquemodules= false); as the solution to your problem, and someone beat me to it. Reason for still commenting is that this method is documented on the help page for stopat()

Do you ever read the help before you post here?

@Carl Love 

that you know this, but for the uninitiated, in the Maple help I always recommend 'unchecking' the entry at

View->Display examples with 2D math input (F5)

All help page examples then revert to 1D input. This makes cut-and-paste into a worksheet much 'safer'

First 91 92 93 94 95 96 97 Last Page 93 of 207