Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

20 years, 308 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

If you write a list of numbers in the outputfile, you can't open it as letters - only as a list of numbers. It can be parsed though and converted to letters after,

parse(readline(outputfile));

                       [72, 101, 108, 108, 111]

convert(%,bytes);

                               "Hello"

close(outputfile);

Alec

No need to do such complicated things in Q1. Just

readbytes(document, infinity);

                       [72, 101, 108, 108, 111]

fprintf(outputfile,"%a",%);

                                  24

close(document, outputfile);

I don't exactly understand Q2. Probably, you could use Embedded Components for that, such as TextArea and Button - drag them from the Components Palette (at the left hand side) into a worksheet and use DoumentTools:-Do to set the necessary actions. There should be an additional step before encryption - using bytes (in ASCII) is not good enough. For example, a space has ASCII code 32, and b has ASCII code 98, and 98 mod 33 =32. So if you use a procedure with mod 33, they will be indistinguishable. The more or less standard way is using a string containing alphabet instead - something like " abc...", starting with a space, and assign space to 0, "a" to 1 etc. correpondingly to that alphabet string. Also, the result of the encryption is also usually a string of letters in that alphabet, and not a list of numbers.

Alec

plots:-intersectplot(z = x*y,x = sqrt(9-y^2),
    x=0..3,y=-3..3,z=-4.5..4.5,axes=box);

Alec

Also, ColumnSpace would work (used on the Matrix constructed from those vectors.)

In this particular example, any 2 of these 3 vectors would form a basis, too.

Alec

Compare that with how much easier that could be done without the powseries package,

A:=f->diff(f,x)-eval(diff(f,x),x=0)+f*x^2;

                          /d   \   /d   \|           2
                A := f -> |-- f| - |-- f||      + f x
                          \dx  /   \dx  /|x = 0

A(sin(x));

                                      2
                        cos(x) - 1 + x  sin(x)

s:=add(a[i]*x^i,i=0..10);

                        2         3         4         5
  s := a[0] + x a[1] + x  a[2] + x  a[3] + x  a[4] + x  a[5]

                 6         7         8         9          10
         + a[6] x  + a[7] x  + a[8] x  + a[9] x  + a[10] x

series(A(s),x);

                              2                    3
  2 a[2] x + (3 a[3] + a[0]) x  + (4 a[4] + a[1]) x  +

                         4                    5      6
        (5 a[5] + a[2]) x  + (6 a[6] + a[3]) x  + O(x )

G:=(f,n)->expand(1+add((A@@i)(f),i=1..n));

                                        (i)
        G := (f, n) -> expand(1 + add((A   )(f), i = 1 .. n))

series(G(s,5),x,3);

  1 + (24 a[4] + 6 a[1] + 720 a[6] + 38 a[0] + 38 a[2] + 234 a[3]

         + 120 a[5]) x + (60 a[5] + 360 a[6] + 19 a[0] + 2520 a[7]

                                                      2      3
         + 117 a[3] + 828 a[4] + 18 a[2] + 117 a[1]) x  + O(x )

Alec

LinearAlgebra package already has such a procedure, Pivot.

How to find the pivot position? That depends on the goal - either choose a position that contains a non-zero element, or a positive one etc.

Also, the simplex method is implemented in the simplex package and in the Optimization:-LPSolve.

Alec

matrix and Matrix are 2 different things. LinearAlgebra works with Matrices (with a capital M).

Alec

Actually, there is a way to draw a graph in Maple that way,

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}});

SetVertexPositions(G, 
    [seq(seq([i, j], i = -1 .. 1), j = 1 .. -1, -1)]);

DrawGraph(G);

135_pos1.gif

Alec

It looks as if the expressions become very long already on the second step. What is your estimation of the length of the expression after 10 steps? I wonder how it possibly could be used.

Alec

 

Actually, there is a way to draw a graph in Maple that way,

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

SetVertexPositions(G, [[-1, 1], [0, 1], [1, 1], [-1, 0], [0, 0]]); 

DrawGraph(G)

135_pos.gif

Alec

GraphTheory package doesn't support multiple edges and loops. The deprecated networks package supports them partially - without drawing multiple edges, and counting a loop only once in vdegree instead of 2. Also letter e can not be used as a vertex name in the networks package.

The simplest way, probably, is just using lists of vertices and edges, and not using GraphTheory or networks packages.

V:=[a,b,c,d,e]:
E:=[{a},{a,b}$3,{a,e},{b,c},{b,d},{b,e},{c},{c,d}$3,{d,e}]:

nops(V);

                                  5

nops(E);

                                  13

seq(deg(i)=numboccur(E,i)+numboccur({i},E),i=V);

      deg(a) = 6, deg(b) = 6, deg(c) = 6, deg(d) = 5, deg(e) = 3

Alec

F:=x^2;
                                     2
                               F := x

to 5 do F:=F+int(F,x) od:
F;
          2        3        4        5         6           7
         x  + 5/3 x  + 5/6 x  + 1/6 x  + 1/72 x  + 1/2520 x

That can be also done without using a loop as

restart;
A:=F->F+int(F,x);

F:=(A@@5)(x^2);

             2        3        4        5         6           7
       F := x  + 5/3 x  + 5/6 x  + 1/6 x  + 1/72 x  + 1/2520 x

Alec

The mean is actually different. Here is an example,

with(Statistics):
mx:=Mean(Gumbel(a,b));

                          mx := a + gamma b

sx:=StandardDeviation(Gumbel(a,b));

                                  1/2
                                 6    b Pi
                           sx := ---------
                                     6

my:=Mean(Normal(c,d));

                               my := c

sy:=StandardDeviation(Normal(c,d));

                               sy := d

sol:=solve({mx=Mx,my=My,sx=Sx,sy=Sy},{a,b,c,d});

                          1/2                  1/2
               -gamma Sx 6    + Mx Pi      Sx 6
   sol := {a = ----------------------, b = -------, c = My, d = Sy}
                         Pi                  Pi

X:=RandomVariable(Gumbel(1,2)):
Y:=RandomVariable(Normal(3,4)):
S1:=Sample(X,1000):
S2:=Sample(Y,1000):
Mx:=Mean(S1);

                          Mx := 2.240218115

My:=Mean(S2);

                          My := 3.067301772

Sx:=StandardDeviation(S1);

                          Sx := 2.722818358

Sy:=StandardDeviation(S2);

                          Sy := 4.098078947

evalf(sol);

  {a = 1.014804979, b = 2.122972764, c = 3.067301772, d = 4.098078947

        }

Compare that with loglikelihood solutions,

F1 := LogLikelihood(Gumbel(a, b), S1):
Optimization:-NLPSolve(-F1, a = 0 .. 5, b = 1 .. 6)[2];

          [a = 1.03677611690796589, b = 2.06246083655606504]

F2:= LogLikelihood(Normal(c, d), S2):
Optimization:-NLPSolve(-F2, c = 0 .. 5, d = 1 .. 6)[2];

          [c = 3.06730175562503148, d = 4.09602939616200422]

Practically the same results for the normal component, and very close - for Gumbel. But the calculations with the means and the standard deviations are much more simple.

Alec

You could try declare,

E:= 1/(x^2 + y^2) + (x^2+y^2);

                                1       2    2
                        E := ------- + x  + y
                              2    2
                             x  + y

PDEtools:-declare(t(x,y));

                  t(x, y) will now be displayed as t

algsubs(x^2+y^2=t(x,y),E);

                               1/t + t

diff(%,x);
                             
                              t[x]
                            - ---- + t[x]
                                2
                               t

Alec

Perhaps, you could use moments - find few moments for your sample and for the distribution, and solve for a,b,c,d when they are equal.

Alec

First 29 30 31 32 33 34 35 Last Page 31 of 76