Joe Riel

9660 Reputation

23 Badges

20 years, 2 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@acer See below

interface('typesetting=standard'):
writeto("foo"):
for i to 2 do
    Y := rand(1..10)();
    printf("X[ %d ]:= %d;\n", i, Y);
end do;
writeto('terminal'):

The file foo now contains

                                   Y := 7

X[ 1 ]:= 7;
                                   Y := 10

X[ 2 ]:= 10;

I doubt the centered lines are desired.

@acer Those changes remove the Typesetting functions but still put extraneous stuff in the ouput file. It's better, but I doubt that is what is desired.  A crude solution would be to use kernelopts('printlevel'=1).  Probaby the better approach is to use fprintf in lieu of writeto and printf.

@mugwort I doubt it makes the solution easier, just thought it was kind of a neat approach.  Note that the unit function fails at t=0, but that could be avoided by slightly shifting the curve so it doesn't go through the origin.

@Anthrazit Maple behaves in the same way.  For example

m := Array(0..1,0..1,[[1,2],[3,4]]):
a := 0:
m[a,0]; #--> 1
a := 1:
m[a,0]; #--> 3

The issue with your first post is that you assign to b, b := m[a,1], and then expect b to be updated when a is changed. That won't happen, the value assigned to b is the entry in m[a,1], not a reference to its location.

@Fzen That's not quite right because combinat:-fibonacci(n) returns the n'th fibonacci number. Fixing it is easy enough.  Note that that method is quite inefficient cpu-wise in that combinat:-fibonacci starts over each time.  Practically it's faster (human-wise) not to worry about such things.

@Kitonum Using is is not a good way to do this; it is a fairly complicated interpreted procedure intended to deal with expressions with assumptions.  Better would be to use evalb, a builtin designed to evaluate boolean expressions. This sort of testing is tricky.  Here is one approach, which uses a preprocessor macro to avoid excessive typing (this will only work in command-line maple, which you should probably be using anyway when testing for speed).

$define Time(x) restart; \
                proc() \
                local data := [seq(1..10^6)]; \
                    CodeTools:-Usage(proc() to 10^4 do \
                                                evalb(x) \
                                            end do; \
                                     end proc()); \
                end proc()
Time(true): # baseline
Time(numelems(data)<>0):
Time(nops(data)<>0):
Time(data<>[]):
Time(not data::[]):
# repeat
Time(true):
Time(numelems(data)<>0):
Time(nops(data)<>0):
Time(data<>[]):
Time(not data::[]):

The results are that they are close enough that you shouldn't care, but, as I expected, using nops or numelems (they are equivalent) is slightly slower. I've generally used data <> [] because I find it the clearest.

Note that data was declared a local. Using a global would be a mistake as globals get fully evaluated in a procedure so the time would depend on its size.

@mmcdara See the Maple help page ?worksheet,reference,initialization.  It's a text file with standard Maple statements.

@Carl Love That is very clever.  For those confused by what Carl did, here is a bit of deconstruction.  Note that all of this only works in fairly recent versions of Maple.

Assign an iterator, J, that generates all 4-combinations of integers 0 to 5.

J := Iterator:-Combination(6,4):

Use the output method of the iterator object to return the Array that is updated with each iteration.

V := output(J):

Create an alias to V that looks like a 2x2 matrix.

M := ArrayTools:-Alias(V,[2,2]):

Loop through the iterator, adding 1 to each element in the matrix so the content are integers from 1 to 6. The surrounding parentheses causes the do-expression to return a sequence of all the expressions generated

(in J do M+~1 od);

The necessity to add one to each element in the Matrix seems unfortunate, it would nicer if the iterator had an option to do that. I'm updating Combination to provide such an option, however, even with that option one would still have to evaluate the structure otherwise the generated sequence would consist of duplicates of the last matrix. I was surprised that the tilde operator was required; M+1 "should" have worked. It doesn't because ArrayTools:-Alias produces a Matrix rather than an Array (adding a value to an Array increments all elements of the Array, adding to a Matrix increments the main diagonal elements).

@Carl Love Thanks; changed it.  I wondered about that one, was sure the third case needed the parentheses.  Also changed my original use signum to sign as it is a builtin and we don't care about the value if the endpoints match. 

A binary search is only useful if the data is already sorted, i.e. there is no good reason to first sort the data as doing so is more expensive than a linear search.

It's not clear to me that your example makes sense.  As I expect, F1 is a vector field with components functions of the two coordinates, x1 and x2 (p1 and p2 are fixed parameters).  F2 is only a function of p1 and p2; as such it is a constant vector field. Is that what you want?

A StepResponsePlot method could be useful; I'll look into adding one.  In the meantime, creating the step response for a discrete system is easy enough:

ResponsePlot(sysz,<[1$100]>);

Inspecting it reveals the issue with this system; the system has no DC component, i.e. the step response's final value (total step) is 0. The various computations of StepProperties are normalized to that magnitude, so they all become undefined.

@Anthrazit Property is the sole export of the module.  AISCTable is a local variable to the module. The way I discovered that was by interactively debugging the Property procedure:

with(AISCShapes):
stopat(Property): # instrument Property procedure to launch debugger when called
Property("W8X21","W"); # this should invoke the debugger

With the debugger started, execute a few into commands to step into a nested conditional. You'll then see the Maple statement

    AISCShapes:-AISCTable[requiredMember][requiredPar];

From that you can determine that AISCTable is a local variable assigned a table (possibly a record, but in fact is a table). It's entries are also tables, hence the second index.

Possibly easier is to just print and inspect the Property procedure

showstat(Property);
AISCShapes:-Property := proc(requiredMember::string, requiredPar::string)
local parPos, memberPos;
   1*  if _npassed = 2 then
   2       if requiredMember in AISCShapes:-memberNames and requiredPar
             in AISCShapes:-parNames then
   3           AISCShapes:-AISCTable[requiredMember][requiredPar]
           else
   4           if not (requiredMember in AISCShapes:-memberNames or 
                 requiredPar in AISCShapes:-parNames) then
   5               error "Member and parameter not found"
               elif not requiredMember in AISCShapes:-memberNames then
   6               error "Member not found"
               elif not requiredPar in AISCShapes:-parNames then
   7               error "Parameter not found"
               end if
           end if
       elif _npassed = 3 and _passed[3] = "metadata" then
   8       parPos := ListTools:-Search(requiredPar,AISCShapes:-parNames);
   9       return AISCMetadata[parPos+1,5]
       elif _npassed = 1 and _passed[1] = "allmembers" then
  10       return AISCShapes:-memberNames
       end if
end proc

Apologies for the typo in the original response, it happens.

@Kitonum If you don't mind reverse lexicographic order, there is an iterator for that

P := Interator:-Partition(5):
for p in P do printf("%{}d\n", p[1..length(P)]); end do:
5
4 1
3 2
3 1 1
2 2 1
2 1 1 1
1 1 1 1 1

Will look into adding an option to reverse the order

Note that the first statement in acer's response assigns the list of items that appear in the listbox.  The next statement selects one of those items; that is, it must be an item in the list already stored in the listbox.

*Followup* this more or less precludes storing the same item twice in a listbox.

First 15 16 17 18 19 20 21 Last Page 17 of 195