Joe Riel

9660 Reputation

23 Badges

20 years, 8 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Does the revolute joint have a non-zero damping or spring constant factor? If not, the torque will be zero.  Did you select the desired signals of each probe attached to the force-moment sensor?

@Bendesarts It would be helpful if you could post, as text or an attachment, the code you have embedded as a figure. I can barely read the code in it and I'd rather not retype it.

@Carl Love Good point.  Of course, the mutable structures would also have the ln(m) factor, so it's a wash. Hmm. I suppose that isn't necessarily true because one wouldn't likely be using a set to collect them, there being no point to it.

@Alejandro Jakubi I didn't explain clearly. In the example I gave there is no reason to be modifying any of the lists, so no effective limitation on their size.  For many problems involving large numbers of lists, the common usage is not to be modifying the lists.  The point being, if lists were always mutable, then the cost of comparing them is always high (there may be ways around that, but that's the basic point).

@JVLB It might be useful to post a small version of the expr passed to lhopital.

In muldiff, why the op in subs(op(substitutionset), ...)?  If substitutionset is a set of equations, the op does not help.

@Alejandro Jakubi It depends on the task. Suppose you are creating m lists, each with n elements and collecting them into a set. Assume all lists are different. With Maple's approach the cost of this, I think, is O(m*n) [I'm imagining that constructing the hash for each n-element entity is O(n) but confess to being out of my element].  If the lists were mutable structures I believe the cost is O(m^2*n).

@nm The actual syntax is Vector([seq(i,i=1..100)]) [note the square brackets].  In newer versions of Maple you can use seq(1..100) for the sequence generation.

There's nothing wrong with using lists as data structures in Maple; they are frequently used by many the library commands and take less memory than a Vector. The problem comes about when you need to be changing a given list.  In that case, an Array or Vector is generally better.

@acer A useful extension to the ColorTools:-Color command might be a "PlotColorSpace" that returns the normal plot colors and uses integers as the coordinate (the coordinate space is unbounded, the colors repeat periodically).

Here's a variation of Acer's suggestion that adds a legend.  The first few lines kind of implement what I suggest, above.

palette := plots:-setcolors():
indx := 0:
clr := proc() global indx; indx := irem(indx,nops(palette))+1; palette[indx]; end proc:
with(DynamicSystems):
sys := TransferFunction(w^2/(s^2+2*zeta*w*s+w^2)):
plots:-display(seq(ResponsePlot(sys, Step(), parameters=[w=1,zeta=z], color=clr(), legend=z), z = 0.2 .. 1.2, 0.2));

 

@nm Details of the DynamicSystem data structures are given in the help page DynamicSystems,SystemObject, which is linked to from the main DynamicSystems help page. Alas, in the Examples section of the SystemObject help page there are no examples showing how one directly accesses a component. I'll add one. 

@Carl Love Adding the additional equation is a clever touch. 

I'm wondering how to best solve the problem the user had. The brute force search---though trivial here---isn't appealing. Alas, I wasn't able to get anything useful from msolve:

M := <2,0;0,3>:

P := Matrix(2, symbol=p):
Z := P^%T.M.P - <1,0;0,1>:
ex := convert(Z,set):msolve(ex, 5);    
                   p[1, 2] = 0, p[2, 1] = 0

That is not correct.

Here is a brute-force search, using the Iterator package (available from the Maple Application Center):

check := proc(v)
local eqs,z;
    eqs := [p[1,1]=v[1],p[1,2]=v[2],p[2,1]=v[3],p[2,2]=v[4]];
    z := eval(ex, eqs) mod 5;
    andmap(Testzero,z);
end proc

iter := Iterator:-MixedRadixTuples([5$4], 'accept' = check):
seq(i[], i = iter);

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

Consider posting your code as text, so it can be copied.  Retyping isn't much fun.

@Carl Love Thanks Carl.  Following is a revised version that uses Carl's suggestion, slightly modified, and includes an additional try/catch so that it generates a useful error message if the data file does not parse as expected. I've restored the file parameters, hopefully the use of them is clear.

A useful improvement is to check that i=0 after exiting the loop; if not it means the last Matrix was not completed. I'll let the OP handle that.

Compute := proc( data :: string, ofile :: string, dim :: posint )
local A, cnt, fd1, fd2, fmt, i, j, line, linenum, p, row, x;

    try
        fd1 := fopen(data,'READ');
        fd2 := fopen(ofile, 'WRITE');
        fmt := StringTools:-Repeat("%f",dim);
        A := Matrix(dim);       # working Matrix
        cnt := 0;               # number of Matrices read
        i := 0;                 # number of rows in current Matrix
        for linenum do
            line := readline(fd1);
            if line :: string then
                line := StringTools:-Trim(line);
            end if;
            if line = 0 or line = "" or line[1] = "#" then
                if i = dim then
                    # Matrix complete
                    cnt := cnt+1;
                    # Compute charpoly and extract coefficients as Vector
                    p := LinearAlgebra:-CharacteristicPolynomial(A,x);
                    p := PolynomialTools:-CoefficientVector(p,x,'termorder=reverse');
                    fprintf(fd2,"%{c,}a\n",p); # see ?rtable_printf for details
                    i := 0;
                end if;
                if line = 0 then
                    # end of file, exit loop
                    break;
                end if;
            else
                # Parse row and insert in Matrix
                i := i+1;
                try
                    row := sscanf(line, fmt);
                    for j to dim do
                        A[i,j] := row[j];
                    end do;
                catch:
                    error "problem scanning line %1: %2", linenum, line;
                end try;
            end if;
        end do;
    finally
        fclose(data,ofile);
    end try;
    cnt; # return number of Matrices
end proc:

# Assign these the appropriate file names for your system
data_file := "read-data-compute-charpoly.dat":
poly_file := "read-data-compute-charpoly.poly":

(Compute)( data_file, poly_file, 3);

@liushunyi You can remove the parameter declarations from the procedure assignment, but you then have to assign values to local variables data and ofile inside the procedure body.

A := Matrix(0, 1..cols) assign a Matrix with 0 rows and 'cols' columns; more usual is Matrix(0, cols). The assignment, later, A(i,j) := row[j], uses parentheses notation so that, if needed, a row is added to A. Simpler is do A := Matrix(dims), which assigns a square matrix with dims rows and columns and use the normal bracket notation.  I've made that change, below. 

B := A[1..i, ..] assigns B the submatrix of A consisting of the rows from 1 to i.  

Because B and A should always be square, it doesn't really make sense to do that. Following is a modified version of the code that implements these changes. I've added a try statement so that the data files are closed if an error interrupts the operation.

Compute := proc( dim :: posint )
local A, cnt, data, fd1, fd2, fmt, i, j, line, ofile, p, row, x;

    data := "read-data-compute-charpoly.dat";
    ofile := "read-data-compute-charpoly.poly";
   
    try
        fd1 := fopen(data,'READ');
        fd2 := fopen(ofile, 'WRITE');
        fmt := StringTools:-Repeat("%f",dim);
        A := Matrix(dim);       # working Matrix
        cnt := 0;               # number of Matrices read
        i := 0;                 # number of rows in current Matrix
        do
            line := readline(fd1);
            if line = 0 or line = "" or line[1] = "#" then
                if i = dim then
                    cnt := cnt+1;
                    # Compute charpoly and extract coefficients as Vector
                    p := LinearAlgebra:-CharacteristicPolynomial(A,x);
                    p := PolynomialTools:-CoefficientVector(p,x,'termorder=reverse');
                    fprintf(fd2,"%{c,}a\n",p); # see ?rtable_printf for details
                    i := 0;
                end if;
                if line = 0 then
                    # end of file, exit loop
                    break;
                end if;
            else
                # Parse row and append to Matrix
                i := i+1;
                row := sscanf(line, fmt);
                for j to dim do
                    A[i,j] := row[j];
                end do;
            end if;
        end do;
    finally
        fclose(data,ofile);
    end try;
    cnt; # return number of Matrices
end proc:

Compute(3);

@Axel Vogt Probably a quirk of CodeGeneration, particularly noting that 2 is rendered as 0.2e1.

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