Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Carl Love Yes, it is.  I wasn't aware of that routine.  Alas, it doesn't work with datatype=integer[4], so a new Matrix must be generated, but it is much faster.  Here's a suitable rank procedure to replace my Rank2.  Note that using that found a bug in my original code, which I've since corrected.

Rank2 := proc(M)
local n, rank;
    n := upperbound(M,1);
    LinearAlgebra:-Modular:-RowReduce(2,Matrix(M,'datatype=integer'),n,n,0,0,0,'rank',0,0,true);
    rank;
end proc:

@Carl Love Oops.  Sometimes it pays to actually test the code.

Here's a correction and an extension to handle GF2

GF2 := table([NULL
              , `0` = 0
              , `1` = 1
              , `=` = `=`
              , `+` = (() -> modp(`+`(args),2))
              , `-` = proc(a,b) ifelse(nargs=1,modp(-a,2),modp(a-b,2)); end proc
              , `*` = proc(a,b) modp(a*b,2); end proc
              , `/` = proc(a,b)
                          if b=0 then
                              error "division by zero";
                          end if;
                          a;
                      end proc
             ]):

RREF := LinearAlgebra:-Generic:-RREF[GF2]:

Rank2 := proc(M)
local R, i,j,n,rank;
global GF2,RREF;
    n := upperbound(M,1);
    R := RREF(M);
    rank := 0;
    for i to n do
        for j from i to n do
            if R[i,j] <> 0 then
                rank := rank+1;
                break;
            end if;
        end do;
    end do;
    rank;
end proc:

n := 4:

P := Iterator:-BinaryGrayCode(n^2):
M := ArrayTools:-Alias(output(P),[n,n]):
cnt := 0:
found := table():
for p in P do
    if Rank2(M) >= n-1 then
        cnt := cnt+1;
        found[cnt] := copy(M);
    end if;
end do:

cnt;

@Kitonum Marginally more efficient, but crude, is

n := 4:
P := Iterator:-BinaryGrayCode(n^2):
M := ArrayTools:-Alias(output(P),[n,n]):
cnt := 0:
found := table():
for p in P do
    if LinearAlgebra:-Rank(M) ≥ n-1 then
        cnt := cnt+1;
        found[cnt] := eval(p);
    end if;
end do:

cnt;

@Carl Love Carl's suggestion will work. Note that the call to ModuleLoad (that is, ModuleLoad()), is not strictly necessary but doesn't hurt. It is only called when the module is first assigned. It is useful when using a module assigned in a worksheet (rather than loaded from an library). If the module is is written to a Maple archive (mla file) so that, on subsequent usage, the module is loaded from the archive, ModuleLoad will be called automatically regardless whether the explicit call existed in the source (only assignments to locals and exports exist in an archive).

The basic idea is 

n := 3:
Matrix(n,n, (i,k) -> `if`(i<>k, f1(i,k), `if`(...) )):

You'll need to fill in the expressions that defines the procedure.

You didn't specify what transfer function was desired. Probably V2/Vi, however, if that is the case then you don't want to set Vi to 10.  Using Syrup one can solve this with a Ladder network:

with(Syrup):
ckt := [Vi, R1, C1, R2, C2]:
sol := Solve(ckt,ac);
     sol := {v[1] = Vi, 
             v[2] = Vi*(C2*R2*s+1)/(C1*C2*R1*R2*s^2+C1*R1*s+C2*R1*s+C2*R2*s+1), 
             v[3] = Vi/(C1*C2*R1*R2*s^2+C1*R1*s+C2*R1*s+C2*R2*s+1)}
eval(V[3]/v[1], sol);
                      1/(C1*C2*R1*R2*s^2+C1*R1*s+C2*R1*s+C2*R2*s+1)

Given that T is defined in terms of f11 and f21, and vice-versa, you're going to have a hard time evaluating that. Maybe there's a clever algebraic simplification ... 

What were you expecting?  Adding velocity to velocity squared is not consistent.

@Christopher2222 You can create a new record from an existing record, adding fields, by doing

rec1 := Record('a' = 1, "b" = 2):
rec2 := Record[rec1]("c" = 3):

Note the mix of strings and names as field identifiers; they are equivalent. Strings are allowed to avoid issues with names evaluating. While a field is normally accessed with, say, rec1:-a, you can also do rec1['a'] or rec1["a"]. The square brackets allow using a variable to index a record.

@uomcsg The immediate part that wasn't clear, and still is not, is what shape do you want for this trapezoidal waveform?  Is it a single pulse or a pulse train? For a single pulse what is its amplitude, rise-time, duration, and fall-time?  If a pulse train what is the period?  And what terminates it?  I find it strange that any or all of those parameters would be fixed.  But if they are not fixed, what controls them?  Did you try the Triggered Trapezoid?  You might need two, one for a negative pulse, another for a positive pulse.   

@uomcsg Still not clear to me.  There is a Triggered Trapezoid component, however, I'm not sure it does what you want.  But try it out and see. Just enter Triggered Trapezoid in the search box, that will bring it up. It's trigger is a boolean signal.

Alas, that isn't possible. The time-offset is a parameter.  Parameters can not change during a simulation. Do you need just one pulse, or do you want a trapezoidal pulse-train?  If you describe the signal that you want, I can probably create a model that implements it.

@neek Replace the use of the tilde operator with map

sort(ifactor(n), map(``,P));

What version of Maple are you using?  Try changing the with statement to 

with(Maplets:-Elements);

The march command can be used to manage a Maple archive, however, procedures that are members of a module frequently have linkages to other members of the module that cannot practically be reproduced without access to the source code, that is, one really needs to build the package in the normal way.

First 31 32 33 34 35 36 37 Last Page 33 of 195