## Alec Mihailovs

Dr. Aleksandrs Mihailovs

## 4470 Reputation

20 years, 16 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.

## Another way...

Another way can be seen in action in the procedure in that post.

It is done not in a loop though, which makes it (much) more effective (efficient too, but in this particular examle it's not that important).

Now - my this answer was voted down only once - unlike another answer voted down 3 times in this thread? That's a (nice) surprise! Some of "down voters" got scared of my tongue? Nah. Just have to wait for a little bit longer, I guess.

_______________
Alec Mihailovs, PhD
Maplesoft Member

## A downside...

A downside of using that signature is that I've started receiving tons of email (mostly from Asia), requiring immediate assistance to their Maple problems - they think that I am working in Customer Support.

_______________
Alec Mihailovs, PhD
Maplesoft Member

## Works now...

Seems to be working now,

```f[1]:=x->x+a: (f[1]@f[1])(x);

x + 2 a
```

_______________
Alec Mihailovs, PhD
Maplesoft Member

## gfun...

Starting from 0,

```L:=[2,3,3,3,4,5,5,5,6,7,7,7,8,9,9,9,10,11,11,11,12]:
gfun:-listtorec(L,a(n));

[{(n + 7) a(n + 1) + (-n - 6) a(n + 2) + (n + 7) a(n + 3)

+ (-n - 6) a(n + 4), a(0) = 2, a(1) = 3, a(2) = 3, a(3) = 3}

, ogf]

rsolve(%[1],a(n));
```

```seq(%,n=0..20);

2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 9, 10, 11, 11, 11, 12
```

Subtract 4 from n if you want to start from 4,

`expand(eval(%%,n=n-4));`

```seq(%,n=4..24);
2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 9, 10, 11, 11, 11, 12
```

_______________
Alec Mihailovs, PhD
Maplesoft Member

## For example...

For example,

`trigsubs(sin(x)+sin(y))[];`

`eval(%,y=x+Pi/3);`

___________
Alec Mihailovs, PhD
Maplesoft Member

## FormatMessage...

Also, StringTools:-FormatMessage might be useful for formatting the error message in try...catch. For example, with f from the first answer,

```for i to 6 do
try print(f(i))
catch "bad argument at":
printf(StringTools:-FormatMessage(
"%-1 i created a problem", i))
end
od:

1st i created a problem

g(2)

3rd i created a problem

g(4)

5th i created a problem

g(6)
```

_______________
Alec Mihailovs, PhD
Maplesoft Member

## Select and Remove...

?Statistics package has Select, Remove, SelectNonNumeric, RemoveNonNumeric, SelectInRange, RemoveInRange commands which can be applied to both Arrays and lists.

_______________
Alec Mihailovs, PhD
Maplesoft Member

## Sphere point picking...

Sphere point picking article in Mathworld describes several ways of constructing randomly distributed points on a sphere.

_______________
Alec Mihailovs, PhD
Maplesoft Member

## save...

I didn't look deep into the code, and it, probably, could be modified to avoid restarting - it is not something that people usually do. But, theoretically speaking, one could use `save` command to save the variables and then `read` to retrieve them.

__________________
Alec Mihailovs, PhD
Maplesoft Member

## Shortcut keys and packages index...

Shortcut keys are available at ?worksheet/reference/shortcutkeys and the package index at  ?index,package .

_______________
Alec Mihailovs, PhD
Maplesoft Member

## loops in descending order...

Your code was correct (well, the posted part of it). It should work. For example,

```for i from 100 by -0.01 to 0 do
if frem(i,20)=0 then print(i) fi
od;
100
80.00
60.00
40.00
20.00
0.
```

_______________
Alec Mihailovs, PhD
Maplesoft Member

## remove...

The list should be in second place, and additional arguments - after that,

```L1:=remove(`<>`, L, 3);

L1 := [3, 3]
```

or

```select(`=`,L,3);

[3, 3]
```

__________________
Alec Mihailovs, PhD
Maplesoft Member

## DifferentialGeometry, ExteriorDerivative...

Also, one could use  ?DifferentialGeometry/ExteriorDerivative (a rather new package, but still useful for some tasks).

```with(DifferentialGeometry):
DGsetup([r,theta],M);

frame name: M

ExteriorDerivative(r*sin(theta));
```

_______________
Alec Mihailovs, PhD
Maplesoft Member

The answers (very clever) were submitted by Robert Israel. I came to this page with an intention to mark them up, and wasn't able to, because both of them were classified here as comments.

_______________
Alec Mihailovs
Maplesoft Member

## Compositions of rational functions...

Compare the expression for the composition of 2 rational functions,

```collect(normal(eval((a*s+b)/(c*s+d),s=(A*s+B)/(C*s+D))),s);

(a A + b C) s + a B + b D
-------------------------
(c A + d C) s + c B + d D
```

with the matrix multiplication,

```Matrix([[a,b],[c,d]]).Matrix([[A,B],[C,D]]);

[a A + b C    a B + b D]
[                      ]
[c A + d C    c B + d D]
```

Now, the composition repeated n times can be calculated using the n-th power of matrix

`g:=Matrix([[0,1-p],[-p,1]]);                               [0     1 - p]                          g := [           ]                               [-p      1  ]F:=LinearAlgebra:-MatrixPower(g,n);  F :=        [   n    (n + 1)            n        [  p  - p        - p (1 - p)        [- -------------------------- ,         [           -1 + 2 p                n    n            n    (n + 1)]        -(1 - p)  + p  + p (1 - p)  - p       ]        --------------------------------------]                       -1 + 2 p               ]        [         n    (n + 1)    (n + 1)          n            n]        [p (1 - p)  - p          p        - (1 - p)  + p (1 - p) ]        [--------------------- , --------------------------------]        [      -1 + 2 p                      -1 + 2 p            ]`

_______________
Alec Mihailovs
Maplesoft Member

 First 6 7 8 9 10 11 12 Last Page 8 of 76
﻿