Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

20 years, 307 days
Mihailovs, Inc.
Owner, President, and CEO
Tyngsboro, Massachusetts, United States

Social Networks and Content at Maplesoft.com

I received my Ph.D. from the University of Pennsylvania in 1998 and I have been teaching since then at SUNY Oneonta for 1 year, at Shepherd University for 5 years, at Tennessee Tech for 2 years, at Lane College for 1 year, and this year I taught at the University of Massachusetts Lowell. My research interests include Representation Theory and Combinatorics.

MaplePrimes Activity


These are answers submitted by Alec Mihailovs

The same as in my earlier reply to your question about Eulerian paths,

with(GraphTheory):
G:=Graph({{a,b},{a,d},{b,d},{b,e},{c,d},{c,e}});
DrawGraph(G,style=spring);

135_graph.gif

Neighbors(G);

            [[b, d], [a, d, e], [d, e], [a, b, c], [b, c]]

Alec

MultiSeries:-series(x^n*exp(x),x);

                   (2 + n)    (3 + n)    (4 + n)    (5 + n)
   n    (1 + n)   x          x          x          x
  x  + x        + -------- + -------- + -------- + --------
                     2          6          24        120

              (6 + n)
         + O(x       )

However, seriestodiffeq doesn't work with that, too.

gfun:-seriestodiffeq(%,y(x));
Error, (in gfun:-seriestodiffeq) not a series

holexprtodiffeq works though,

gfun:-holexprtodiffeq(x^n*exp(x),y(x));

                                     /d      \
                     (-n - x) y(x) + |-- y(x)| x
                                     \dx     /

Alec

The characteristic polynomial of a 2×2 matrix is quadratic. So either your matrix is 3×3, or it has a different characteristic polynomial.

In the first case, the list of possible Jordan forms can be found as

map[3](LinearAlgebra:-JordanBlockMatrix@map2,
   `[]`,1,combinat:-partition(3))[];

             [1    0    0]  [1    0    0]  [1    1    0]
             [           ]  [           ]  [           ]
             [0    1    0], [0    1    1], [0    1    1]
             [           ]  [           ]  [           ]
             [0    0    1]  [0    0    1]  [0    0    1]

The corresponding rational canonical forms are

map(LinearAlgebra:-FrobeniusForm,[%])[];

            [1    0    0]  [0    -1    0]  [0    0     1]
            [           ]  [            ]  [            ]
            [0    1    0], [1     2    0], [1    0    -3]
            [           ]  [            ]  [            ]
            [0    0    1]  [0     0    1]  [0    1     3]

Alec

In the File menu, Export as, and then - LaTeX.

The quality of the conversion is quite low though.

Alec

Sometimes maximize and minimize commands are useful for finding the range. But that doesn't always work.

Alec

Also, you may take a look at my old blog post, Matrix Algebra over Finite Fields.

Alec

I posted an example showing how to do that few years ago in that thread.

Alec

One way is to use your own procedure including SubstituteAll, doing the necessary substitutions. For example,

F:=(f,s)-> StringTools:-SubstituteAll(
    CodeGeneration:-Fortran(f, optimize, deducetypes=false,
        defaulttype=numeric,output=string), 
    "cgret",""||s);

basex:=unapply([seq(x^i-1,i=0..9)],x);

F(basex,basex);
Warning, procedure/module options ignored

  "      subroutine basex (x, basex)
                doubleprecision x
                doubleprecision basex(10)
                doubleprecision t14
                doubleprecision t2
                doubleprecision t4
                doubleprecision t6
                t2 = x ** 2
                t4 = t2 * x
                t6 = t2 ** 2
                t14 = t6 ** 2
                basex(1) = 0
                basex(2) = x - 0.1D1
                basex(3) = t2 - 0.1D1
                basex(4) = t4 - 0.1D1
                basex(5) = t6 - 0.1D1
                basex(6) = t6 * x - 0.1D1
                basex(7) = t2 * t6 - 0.1D1
                basex(8) = t6 * t4 - 0.1D1
                basex(9) = t14 - 0.1D1
                basex(10) = t14 * x - 0.1D1
              end
        "

Alec

For example,

basex:=unapply([seq(x^i-1,i=0..9)],x);

CodeGeneration:-Fortran(basex, optimize, 
    deducetypes=false,defaulttype=numeric);

Warning, procedure/module options ignored

      subroutine basex (x, cgret)
        doubleprecision x
        doubleprecision cgret(10)
        doubleprecision t14
        doubleprecision t2
        doubleprecision t4
        doubleprecision t6
        t2 = x ** 2
        t4 = t2 * x
        t6 = t2 ** 2
        t14 = t6 ** 2
        cgret(1) = 0
        cgret(2) = x - 0.1D1
        cgret(3) = t2 - 0.1D1
        cgret(4) = t4 - 0.1D1
        cgret(5) = t6 - 0.1D1
        cgret(6) = t6 * x - 0.1D1
        cgret(7) = t6 * t2 - 0.1D1
        cgret(8) = t6 * t4 - 0.1D1
        cgret(9) = t14 - 0.1D1
        cgret(10) = t14 * x - 0.1D1
      end

Alec

rtables, including Matrices and Vectors, use () for indexes now, so one can't use such things as bases(x) for Vectors of procedures. Instead, basex should be defined as a procedure. For example, as

basex:=unapply(<seq(x^i-1,i=0..9)>,x);

With that, your Fortran command works,

CodeGeneration:-Fortran(basex(x), optimize,
    deducetypes=false, defaulttype=numeric);

      t2 = x ** 2
      t4 = t2 * x
      t6 = t2 ** 2
      t14 = t6 ** 2
      cg(1) = 0.0D0
      cg(2) = x - 0.1D1
      cg(3) = t2 - 0.1D1
      cg(4) = t4 - 0.1D1
      cg(5) = t6 - 0.1D1
      cg(6) = t6 * x - 0.1D1
      cg(7) = t6 * t2 - 0.1D1
      cg(8) = t6 * t4 - 0.1D1
      cg(9) = t14 - 0.1D1
      cg(10) = t14 * x - 0.1D1

Also, using procedures and unapply is not necessary. In this example, basex can be defined just as a Vector of polynomials

restart;
basex:=<seq(x^i-1,i=0..9)>;
CodeGeneration:-Fortran(basex, optimize, 
    deducetypes=false,defaulttype=numeric);

with exactly the same result.

Alec

There should be 2 procedures - one for encoding and one for decoding.

Assuming that AlphaNumeric is

StringTools:-Iota(32..126);

  " !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^\
        _`abcdefghijklmnopqrstuvwxyz{|}~"

that can be done as

AffineMatEncode:=proc(t,A,B)
    local i,m,n,T,V;
    uses LinearAlgebra:-Modular, ArrayTools, 
        LinearAlgebra, StringTools;
    m:=Dimension(B);
    if irem(length(t),m,n)=0 then 
        else n:=n+1 fi;
    T:=Mod(95, Map(`-`, Matrix(n,m,convert(
        PadRight(t,m*n),bytes)), 32), integer[]);
    V:=Replicate(B^%T,n,1);
    AddMultiple(95,Multiply(95,T,A^%T),V,T);
    convert([seq(i,i=Map(`+`,T,32))],bytes)
end;

AffineMatDecode:=proc(t,A,B)
    local i,m,n,T,V;
    uses LinearAlgebra:-Modular, ArrayTools, 
        LinearAlgebra, StringTools;
    m:=Dimension(B);
    if irem(length(t),m,n)=0 then 
        else error "Number of characters 
            should be divisible by %1", m fi;
    T:=Mod(95, Map(`-`, Matrix(n,m,
        convert(t,bytes)), 32),integer[]);
    V:=Replicate(B^%T,n,1);
    AddMultiple(95,94,T,V,T);
    TrimRight(convert([seq(i,i=Map(`+`, 
        Multiply(95,T,Inverse(95,A^%T)),32))],bytes))
end;

For example,

A:=LinearAlgebra:-Modular:-Mod(95,
    Matrix(2, 2, [17, 22, 4, 53]), integer[]); 
B:=LinearAlgebra:-Modular:-Mod(95,
    Vector([19, 82]), integer[]); 

AffineMatEncode("abcdefghijklmno",A,B);

                          "+Hy[hnW"F55H$[@2"

AffineMatDecode(%,A,B);

                          "abcdefghijklmno"

Alec

The GraphTheory package has IsEulerian command, which can return the Eulerian trail. In your example that can be done as follows,

with(GraphTheory);
G := Graph({{a, b}, {a, d}, {b, c}, {b, d}, {b, e}, {c, f}, 
{d, e}, {d, g}, {e, f}, {e, h}, {f, h}, {f, i}, 
{g, h}, {h, i}});
DrawGraph(G, style = spring);
DrawGraph(G, style = spring, redraw);

135_Trail.gif

IsEulerian(G, T);
                                    true
T;

             Trail(a, b, c, f, e, b, d, e, h, f, i, h, g, d, a)

Alec

Here is how that can be done using LinearAlgebra,

var:=Vector[row]([seq(seq(x^i*t^j,j=0..3-i),i=0..3)]);

                 [       2   3             2   2   2     3]
          var := [1, t, t , t , x, x t, x t , x , x  t, x ]

p:=map(unapply,var,[x,t]):
X:=<0, 1/3, 2/3, 1, 0, 1/2, 1, 0, 1, 1/2>:
T:=<0, 0, 0, 0, 1/3, 1/3, 1/3, 2/3, 2/3, 1>:
A:=Matrix(10,(i,j)->p[j](X[i],T[i]));
b:=Vector(10,[1]);
a:=LinearAlgebra:-LinearSolve(A,b);
base:=var.a;

                       189  2   117  3                              2
  base := 1 - 49/8 t + --- t  - --- t  - 11/2 x + 45/4 x t - 9/2 x t
                       16       16

              2         2          3
         + 9 x  - 27/4 x  t - 9/2 x

Alec

linalg is deprecated. It is better to avoid using vectors. I don't see the need of using codegen either.

  1. XX has a floating point entry 0.5. Changing it to 1/2 might give answers in the fraction form (I didn't check that though.)
  2. A normal way would be to define the set of equations directly, preferably using seq or zip instead of a loop.

Alec

It's easier to just use R.

Alec

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