Alec Mihailovs

Dr. Aleksandrs Mihailovs

4455 Reputation

21 Badges

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

Maple gives the wrong sign in `evalf/Sum`.

evalf(Sum(-1/n,n=1..infinity));

                           Float(infinity)

The bug seems to be in returning Float(infinity) at the end of `evalf/Sum/LevinU_Symb/1_inf`. The following confirms that,

restart:
`evalf/Sum/LevinU_Symb/1_inf`:=parse(
    StringTools:-Substitute(sprintf("%a",
        eval(`evalf/Sum/LevinU_Symb/1_inf`)),
            "Float(infinity)","Float(-infinity)")):

evalf(Sum(-1/n,n=1..infinity));

                           Float(-infinity)

evalf(Sum(1/n,n=1..infinity));

                           Float(-infinity)

Alec

The scalling can be also added in the Array initializer. In the example above,

myprint2(Array(10..20,i->A(i/10)));
3.0000d+00
3.1000d+00
3.2000d+00
3.3000d+00
3.4000d+00
3.5000d+00
3.6000d+00
3.7000d+00
3.8000d+00
3.9000d+00
4.0000d+00

For lists, writedata can be used. Something like

myprint1:=x->writedata('terminal',x,string,
    (f,n)->fprintf(f,"%s",StringTools:-SubstituteAll(
        sprintf("%.4e",n),"e","d"))):

myprint1([seq(A(i),i=1..2,0.1)]);
3.0000d+00
3.1000d+00
3.2000d+00
3.3000d+00
3.4000d+00
3.5000d+00
3.6000d+00
3.7000d+00
3.8000d+00
3.9000d+00
4.0000d+00

Alec

In your original example,

eval(t);
                              [5, 4, 3]

arrays are deprecated, in general, and Arrays are more convenient - in particular, they are displayed without eval.

Alec

For example, you could do

a:=[1,2,3];

for i to nops(a) do cat(a_,i):=a[i]; 
save cat(a_,i), cat("a_",i,".m") od;

That doesn't seem to have much sense though. Why do you want to use save? There are more convenient output procedures in Maple. ExportMatrix, writedata, and fprintf, for instance.

Alec

Also, sometimes double brackets are needed. For example,

A[[1..3,5]];
                                 [1]
                                 [ ]
                                 [2]
                                 [ ]
                                 [3]
                                 [ ]
                                 [5]

Alec

combinat:-randcomb(10^20,6);

  {17662883439475955429, 20789237297151719392, 57139535049024513574,

        76286085921364900591, 77262010396232936800,

        96311078789820074939}

Alec

I got 2 and not 2. in your example. Perhaps, you have either 1. instead of 1 or 3. instead of 3 in q?

Alec

Note that if the integral in the l.h.s. diverges, that may be wrong - in sense that the l.h.s is not defined and the r.h.s. may be defined. For example, for f(x)=sin(2*Pi*x), in which case the r.h.s. is 0.

Assuming that the integral in the l.h.s. converges, If you write it as the sum of integrals from i to i+1 for i from 0 to infinity, and the integral from n to n+p as the sum of integrals from i to i+1 for i from n to n+p-1, then each integral from i to i+1 has coefficient p in the l.h.s., and coefficient p in the r.h.s.

Also, that can be done by induction. Denote S(p) the r.h.s. Then S(1) = int(f(x),x=0..infinity), so the identity is true for p=1. Suppose that it is true for p-1 in place of p. Now, S(p)-S(p-1) = sum(int(f(x),x=n+p-1..n+p),n=0..infinity) + sum(int(f(x),x=n-1..n),n=1..p-1) = int(f(x),x=p-1..infinity) + int(f(x),x=0..p-1) = int(f(x),x=0..infinity), so S(p) = S(p-1)+int(f(x),x=0..infinity) = (p-1)*int(f(x),x=0..infinity) + int(f(x),x=0..infinity) = p*int(f(x),x=0..infinity), q.e.d.

Alec

If 2 digits after the + or - sign are enough, that can be done as follows,

myprint2:=x->printf("%s",StringTools:-SubstituteAll(
    sprintf("%{c\n}.4e",x),"e","d")):

myprint2(Vector(10,exp));
2.7183d+00
7.3891d+00
2.0086d+01
5.4598d+01
1.4841d+02
4.0343d+02
1.0966d+03
2.9810d+03
8.1031d+03
2.2026d+04

If minimum 3 digits are required, that can be done as

myprint:=x->printf("%s",
    StringTools:-RegSubs(
        "(d[-+])([0-9][0-9](\n|$))"="\\10\\2",
        StringTools:-SubstituteAll(
            sprintf("%{c\n}.4e",x),
            "e","d"))):

myprint(Vector(10,exp));
2.7183d+000
7.3891d+000
2.0086d+001
5.4598d+001
1.4841d+002
4.0343d+002
1.0966d+003
2.9810d+003
8.1031d+003
2.2026d+004

myprint(Array(-5..5,exp));
6.7379d-003
1.8316d-002
4.9787d-002
1.3534d-001
3.6788d-001
1.0000d+000
2.7183d+000
7.3891d+000
2.0086d+001
5.4598d+001
1.4841d+002

myprint(Array(1000..1001,exp));
1.9701d+434
5.3552d+434

myprint(Array(-3001..-3000,exp));
4.8113d-1304
1.3078d-1303

Alec

Assuming that absolute value of g needs to be minimized for large n, this is the same as in previous examples - find the error term asymptotic.

asympt and series of g don't give a good enough answer,

g:=(1+1/(n))^(((n^(1/(a))+(n+1)^(1/(a) ))/(2))^(a))-exp(1);

                        // (1/a)          (1/a)\a\
                        ||n        (n + 1)     | |
                        ||------ + ------------| |
                        \\  2           2      / /
          g := (1 + 1/n)                           - exp(1)

asympt(g,n) assuming posint;

                                  1
                               O(----)
                                   2
                                  n

which is a bug, but the following works,

asympt(ln(g+exp(1)),n) assuming posint;

             a - 1   a - 1
      1/12 - -----   ----- - 1/12
              8 a     8 a
  1 + ------------ + ------------
            2              3
           n              n

                                    3       2
             7 (a - 1)          15 a  - 14 a  + 2 - 3 a
           - --------- + 3/40 - -----------------------
               96 a                          3
                                        384 a                1
         + -------------------------------------------- + O(----)
                                 4                            5
                                n                            n

solve(1/12-(a-1)/8/a);

                                  3

So the asymptotic of g is O(1/n^2) unless a=3, in which case it is

asympt(eval(g,a=3),n);

                              exp(1)      1
                       1/6480 ------ + O(----)
                                 4         5
                                n         n

which is O(1/n^4).

Alec

It is not difficult, just points are not always aligned well with lines and need some manual adjustment.

The quality of wikipedia plots can be achieved in many ways - in particular, writing the svg code directly, or LaTeX, or Metapost, or other free tools. In Maple or Mathematica that also could be done, but with a lot of work and with a low resolution and low quality fonts, with better results in Mathematica.

Alec

For F2 and F3, one can just do calculations mod 2 and mod 3. For F4, one can use GF(2,2).

Matrix(Array(0..1,0..1,`+`) mod 2);

                               [0    1]
                               [      ]
                               [1    0]

Matrix(Array(0..1,0..1,`*`) mod 2);

                               [0    0]
                               [      ]
                               [0    1]

Matrix(Array(0..2,0..2,`+`) mod 3);

                            [0    1    2]
                            [           ]
                            [1    2    0]
                            [           ]
                            [2    0    1]

Matrix(Array(0..2,0..2,`*`) mod 3);

                            [0    0    0]
                            [           ]
                            [0    1    2]
                            [           ]
                            [0    2    1]

F:=GF(2,2);

                     F := Z[2]*[T]*`/`*`<,>`(T^2+T+1)

Felements:=F:-input~([0,1,2,3]);

                    Felements := [0, 1, T, 1 + T]

alias(A=%[3],B=%[4]):

Matrix(4,(i,j)->F:-`+`(Felements[i],Felements[j]));

                          [0    1    A    B]
                          [                ]
                          [1    0    B    A]
                          [                ]
                          [A    B    0    1]
                          [                ]
                          [B    A    1    0]

Matrix(4,(i,j)->F:-`*`(Felements[i],Felements[j]));

                          [0    0    0    0]
                          [                ]
                          [0    1    A    B]
                          [                ]
                          [0    A    B    1]
                          [                ]
                          [0    B    1    A]

Alec

You could translate the plot - something like

plottools:-translate(
    Statistics:-ColumnGraph(L[..,2]),
    235,0);

Or use offset and view options,

Statistics:-ColumnGraph(L[..,2],
    offset=235, view=[235..275,0..10]);

Alec

In addition to seq, Array or Vector[row] also can be used,

f:=n->(1+I)^n+(1-I)^n:
interface(rtablesize=20):
Array(1..20,f);

  [2, 0, -4, -8, -8, 0, 16, 32, 32, 0, -64, -128, -128, 0, 256, 512,

        512, 0, -1024, -2048]

Vector[row](20,f);

  [2, 0, -4, -8, -8, 0, 16, 32, 32, 0, -64, -128, -128, 0, 256, 512,

        512, 0, -1024, -2048]

Alec

X := proc()
    uses Statistics; 
    Sample(Normal(0, 1), 1)[1] 
end:

profile(X); 

X():  X():

profile_calls["X"];

                                  2

Alec

First 18 19 20 21 22 23 24 Last Page 20 of 76