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

That happens because the count is 2 levels deep - inside a loop and inside a conditional statement, and the default value of the printlevel is 1 - i.e. it prints only level 1 deep expressions.

To see the count printed, one can either use the print command, i.e. print(count) instead of the count, or increase printlevel:

printlevel:=2;

In general, filling a matrix using a loop is not a good idea - it may be good (also not very good, actually) in Fortran, but not in Maple.

Also, instead of

for count from 1 by 1 while count <= N do

you could simply write

for count to N do

because from 1 and by 1 are the default values, and while is necessary only for more complicated exit conditions.

Alec

 

writebytes("testing.txt","testing");

                                  7

close("testing.txt");
readbytes("testing.txt",infinity);

                 [116, 101, 115, 116, 105, 110, 103]

convert(%,bytes);

                              "testing"

Alec

I would use a procedure to convert from strings to numbers, which can be defined as e("a"):=1, e("A"):=1, etc - that creates a remember table for e. Similarly - for conversion from numbers to strings - d(1):="a", etc. That can be done fast using map and assign commands.

The conversion to bytes is not necessary - I used it in the Encode and Decode  post just because it was convenient for that particular alphabet.

The StringTools package contains Explode and Implode procedures which are convenient for conversion from a string to a list of characters and backwards.

Also, during encoding, the string should be padded with spaces at the end (if necessary), to make its length divisible by 3. Similarly, during decoding, the spaces at the end can be trimmed.

Alec

It's not the right way to do that, but identify works well in this example.

fsolve(log[2*sqrt(2+sqrt(3))](y)=log[2+sqrt(3)](y-1));

                             14.92820323

identify(%);

                                     1/2
                              8 + 4 3

Alec

Write the plane equation ax+by+cz=0. The coefficients can be normalized - that means a^2+b^2+c^2=1. If it contains vector (x0,y0,z0), then a*x0+b*y0+c*z0=0. Finaly, the angle between planes is the same as the angle between lines orthogonal to them, which gives c=cos(theta) or c=-cos(theta). Since changing all the signs of a,b,c gives the same plane, we can choose only one of the latter equations, say c=cos(theta).

That gives 3 equations with 3 variables a,b,c. Solve them and that's it.

Alec

It is probably, not a good idea to use powseries for that, especially in teaching.

Anyway, the geometre procedure has 2 errors. First - the initial definition of suma is wrong. Second, the result of powadd can not have the same name as one of the arguments. It is better to define geometre recursively, similarly to An.

Alec

In general, loops are the worst way to do things in Maple. Using them leads to many unnecessary intermediate calculations.

For instance, even mul in the 4th example is much more efficient than a loop.

arrays also should be avoided, and some kind of rtables should be used instead - either Arrays (with a capital A), or Vectors, or Matrices.

Alec

For example,

  1. to 1 do A:=Array([1,5,10,15,20]) od;
    
                           A := [1, 5, 10, 15, 20]
    
  2. to 1 do to 1 do B:=Array(1..4,1..4,(i,j)->i*3^(j-1)) od od;
    
                              [1     3     9     27]
                              [                    ]
                              [2     6    18     54]
                         B := [                    ]
                              [3     9    27     81]
                              [                    ]
                              [4    12    36    108]
    
  3. f:=`+`@op;
  4. g:=factorial;

The procedures in 3 and 4 work as

L:=[1,2,3];

                            L := [1, 2, 3]

f(L);

                                  6

g(4);

                                  24

Alec

In Sage, it is much more simple,

G=Graph({'a':['b','d'],'b':['d','e'],'c':['d','e']})
G.show()

135_sage0.png

G.plot(pos={'a':[-1,1],'b':[0,1],'c':[1,1],'d':[-1,0],'e':[0,0]})

135_sage2.png

The adjacency list can be obtained in several ways. In particular,

[sorted(G[i]) for i in G.vertices()]

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

Alec

Since I added a note about Sage in the later thread, I'll show how to do this thing in Sage as well.

G=Graph({'b':['a','c','d','e'],'d':['a','e','g'],
    'f':['c','e','h','i'],'h':['e','g','i']})

G.show()

135_sage3.png

G.plot(pos={'a':[-1,1],'b':[0,1],'c':[1,1],'d':[-1,0],
    'e':[0,0],'f':[1,0],'g':[-1,-1],'h':[0,-1],'i':[1,-1]})

135_sage4.png

G.eulerian_circuit(return_vertices=True)[1]

['a', 'b', 'c', 'f', 'e', 'b', 'd', 'e', 'h', 'f', 'i', 'h', 'g', 'd',
'a']

Alec

I posted that recently, so one could find that just by searching this site for Fourier,

f := 4/Pi*sum(sin((2*n-1)*x)/(2*n-1),n=1..infinity);

plot(f);

Alec

One can also use MetaPost to produce a picture. For example, one can create the following graph.mp file,

verbatimtex
\documentclass[12pt]{article}
\begin{document}
etex
beginfig(0)
  u:=1in;
  pair A,B,C,D,E;
  A := (-u,u);
  B := (0,u);
  C := (u,u);
  D := (-u,0);
  E := (0,0);
  draw D--A--B--E--C--D--B;
  dotlabel.top(btex $a$ etex, A);
  dotlabel.top(btex $b$ etex, B);
  dotlabel.top(btex $c$ etex, C);
  dotlabel.bot(btex $d$ etex, D);
  dotlabel.bot(btex $e$ etex, E);
endfig;
end.

Then run mpost on it to produce graph.0 file,

mpost -tex=latex graph.mp

Then rename graph.0 to graph.mps and run pdflatex on the following tex file,

\documentclass[12pt]{article}
\usepackage{graphics}
\begin{document}
\begin{figure}
\includegraphics{graph.mps}
\end{figure}
\end{document}

That produces a pdf file with the following picture (without the red box):

Alec

fsolve works OK in many cases. In particular, in this example,

f:=0.1165096616e-4+1.12290098*10^(-10)*t-
    0.28086e-5*(-0.9827864558e-1-9.362*10^(-7)*t)^2+
    0.74930e-4*cos(1.714985063+0.7493e-5*t)*cos(0.9827864558e-1+
    9.362*10^(-7)*t)-0.93620e-5*sin(1.714985063+
    0.7493e-5*t)*sin(0.9827864558e-1+9.362*10^(-7)*t);

fsolve(f);
                             0.1273387833

To assure positivity, something like the following can be used,

mysolve:=(f,t)->min(fsolve(f,t=0,0..infinity,
    avoid={t=0}));

If 0 is acceptable, then the avoid option should be excluded.

Alec

Of course, with about the same effort, the picture could be created in LaTeX,

\documentclass[12pt]{article}
\begin{document}
\begin{picture}(160,90)
\multiput(10,15)(70,0){2}{\circle*{5}}
\multiput(10,85)(70,0){3}{\circle*{5}}
\put(10,85){\line(1,0){70}}
\multiput(10,15)(70,0){2}{\line(0,1){70}\line(1,1){70}}
\put(10,15){\line(2,1){140}}
\put(7,0){$d$} \put(77,0){$e$}
\put(7,90){$a$} \put(77,90){$b$} \put(147,90){$c$}
\end{picture}
\end{document}

Alec

intsolve does that in one step,

eq := 1/2*Int(x*y/(y+1)*f(y),y=0..1) + x^3/2 = f(x);

intsolve(eq,f(x));
                        /  2                      \
                        | x          -7 + 12 ln(2)|
                 f(x) = |---- - 1/12 -------------| x
                        \ 2          -5 + 2 ln(2) /

The iterative process can be done also with expressions, similarly to the iterative process using functions, described by Robert Israel above,

psi:= f -> 1/2*(x*int(f*x/(x+1),x=0..1)+x^3);

f:=0;

to 12 do f:=evalf(psi(f)) od;

                                            3
                         f := 0.5000000000 x
                                                     3
                f := 0.02745346180 x + 0.5000000000 x
                                                     3
                f := 0.03010474118 x + 0.5000000000 x
                                                     3
                f := 0.03036078474 x + 0.5000000000 x
                                                     3
                f := 0.03038551180 x + 0.5000000000 x
                                                     3
                f := 0.03038789978 x + 0.5000000000 x
                                                     3
                f := 0.03038813039 x + 0.5000000000 x
                                                     3
                f := 0.03038815266 x + 0.5000000000 x
                                                     3
                f := 0.03038815481 x + 0.5000000000 x
                                                     3
                f := 0.03038815502 x + 0.5000000000 x
                                                     3
                f := 0.03038815504 x + 0.5000000000 x
                                                     3
                f := 0.03038815504 x + 0.5000000000 x

From here, the exact solution can be found using ansatz

f:=A*x+x^3/2;

psi(f);
                                                         3
                                                        x
          1/2 x (- 7/24 + 1/2 ln(2) - A/2 + ln(2) A) + ----
                                                        2

solve(psi(f)=f,{A});

                                 -7 + 12 ln(2)
                      {A = -1/12 -------------}
                                 -5 + 2 ln(2)

eval(f,%);

                                                3
                          (-7 + 12 ln(2)) x    x
                    -1/12 ----------------- + ----
                            -5 + 2 ln(2)       2

Alec

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