## 703 Reputation

18 years, 22 days

## nops and op f := 2*x+3*y+2; ...

nops and op

`f := 2*x+3*y+2;                                2 x + 3 y + 2nops(f);                                      3op(1, f);                                     2 xop(2, f);                                     3 yop(3, f);                                      2`
`op(f);                                 2 x, 3 y, 2`

---

Duncan

## evalf can be used to obtain a numerical ...

evalf can be used to obtain a numerical solution

`r := RootOf(189*_Z^6-756*_Z^5+567*_Z^4+819*_Z^3-1386*_Z^2+672*_Z-104):evalf(r);                                0.3260605103s := allvalues(r);      /      6         5         4         3          2                 RootOf\189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104,            \        /  index = 1/, RootOf\        6         5         4         3          2                          \    189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104, index = 2/,         /      6         5         4         3          2                   RootOf\189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104,            \        /  index = 3/, RootOf\        6         5         4         3          2                          \    189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104, index = 4/,         /      6         5         4         3          2                   RootOf\189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104,            \        /  index = 5/, RootOf\        6         5         4         3          2                          \  189 _Z  - 756 _Z  + 567 _Z  + 819 _Z  - 1386 _Z  + 672 _Z - 104, index = 6/t := evalf(s);    0.3260605103, 0.6407586587, 0.8042832092, 1.033180831, 2.475877226,       -1.280160435`

---

Duncan

## Assume real...

The problem appears to be that the unknowns are assumed to be complex quantities.  ?evalc assumes that the unknown variables are real-valued. Applying evalc gives the desired solution

`G := s -> 1 / (1 + 2*zeta*s / Omega + (1/(Omega)^2)*s^2):abs( G(I*omega) ):evalc(%):diff(%, omega):sols := solve(%, omega);                           (1/2)                      (1/2)                    /          2\              /          2\                      0, \1 - 2 zeta /      Omega, -\1 - 2 zeta /      Omegaomega_peak := sols[2];                                       (1/2)                                /          2\                                     \1 - 2 zeta /      Omega`

the same result can be achieved using assume:

`assume(omega::real, Omega::real, zeta::real);G := s -> 1 / (1 + 2*zeta*s / Omega + (1/(Omega)^2)*s^2):abs( G(I*omega) ):diff(%, omega):sols := solve(%, omega);                          (1/2)                        (1/2)                   /           2\               /           2\                     0, \1 - 2 zeta~ /      Omega~, -\1 - 2 zeta~ /      Omega~`

---

Duncan

## Converting into functions...

You don't give an example of the result set, but assuming the results have the form given below, then they can be programmatically converted into functions.

```resultset := {f=x^2+1, g=x^2*y+2};                         /     2           2      \                         { f = x  + 1, g = x  y + 2 }                         \                        / for p in resultset do
expr := rhs(p);
funcname := lhs(p);
varnames := op( indets(expr, name) );
assign( funcname=unapply(expr, varnames) );
od:print(f);      2    x -> x  + 1print(g);           2      (x, y) -> x  y + 2f(5);                                     26g(3,2);                                     20```

---

Duncan

## Two problems...

(1) Maple uses upper case I as sqrt(-1) not lower case i. (2) Maple interprets omega[n] as an indexed version of plain omega instead of an atomic identifier. In the following I have replaced i with I and omega[n] with Omega.

`G(s) := 1/(1+2*zeta*s/Omega+(1/(Omega)^2)*s^2):'abs(G(j*omega))'=subs(s=I*omega,abs(G(s))):Abs := simplify(normal(rhs(%))):diff(Abs,omega):solve(%,omega);                                I zeta Omega`

If you must have omega with subscript n, one way to achieve this is to use 2D Math and convert omega_n to an atomic identifier

---

Duncan

## ?applyrule is one option applyrule...

?applyrule is one option

`applyrule(a::integer^(-n)*b::integer^(n)=(b/a)^(n), t);(2/5)^n`

---

Duncan

## plot([sin(x), sin(x + 120/180 * Pi), sin...

plot([sin(x), sin(x + 120/180 * Pi), sin(x + 240/180 * Pi)]);

---

Duncan

## Ctrl+Alt+0...

Have you tried Ctrl+Alt+0?

---

Duncan

## Not using Shift...

The correct shortcut is Ctrl+= not Ctrl+Shift+=. On my keyboard, the = sign is below the + sign so I don't need to hold down Shift to enter =. Do you need to hold down Shift to enter =? If not, what happens when you enter Ctrl+= instead of Ctrl+Shift+=? There is also Ctrl+Alt+0 (Cmd+Alt+0, on Macintosh) for international keyboards.

---

Duncan

## The GenAdd procedure, as you have define...

The GenAdd procedure, as you have defined it, writes to Array a that is in the global namespace. The solution is to create a new Array inside the procedure

`GenAdd := proc(at, bt)  local tempvec;  tempvec := Array(Dimensions(at)[1]);  tempvec[bt] := 1;  at+tempvecend proc:a;                             [1, 2, 3, 1, 1, 2]GenAdd(a, 3);                             [1, 2, 4, 1, 1, 2]a;                             [1, 2, 3, 1, 1, 2]`

---

Duncan

## zip...

zip is one option

`u:=<1,1,1>:v:=<2,3,4>:f:=(x,y)->ln(x-y):zip(f, u, v);                               [    I Pi    ]                               [            ]                               [ln(2) + I Pi]                               [            ]                               [ln(3) + I Pi]`

although map can also be used for the example given

`u-v;                                    [-1]                                    [  ]                                    [-2]                                    [  ]                                    [-3]map(ln, %);                               [    I Pi    ]                               [            ]                               [ln(2) + I Pi]                               [            ]                               [ln(3) + I Pi]`

---

Duncan

## If beta is an element of a finite field,...

If beta is an element of a finite field, the corresponding minimal polynomial can be found by calculating the powers of beta, beta^2, beta^(2^2) until we find the least positive integer d for which beta^(2^d) = beta. This d is the degree of minimal polynomial g and g is given by g(x) = (x-beta)*(x-beta^2) ... (x-beta^(2^(d-1)))

`restart;f := x -> x^4+x+1; # Field polynomial      4        x -> x  + x + 1m := degree(f(x));                                      4alias(alpha=RootOf(f(x))):`

```beta := alpha^3;                                        3                                   alpha beta := Rem(beta, f(x), x) mod 2;                                        3                                   alpha L := NULL:
for d from 1 to 2^m do
d;
t := Powmod(beta, 2^d, f(x), x) mod 2;
L := L, t:
if t = beta then
break
end if;
end do:mul(x - L[i], i = 1 .. nops([L]));/         3        2\ /         3        2            \ /         3        \ / \x - alpha  - alpha / \x - alpha  - alpha  - alpha - 1/ \x - alpha  - alpha/ \x          3\   - alpha /Expand(%) mod 2;                             4    3        2                                x  + x  + x + x  + 1g := unapply(%, x);      4    3        2    x -> x  + x  + x + x  + 1g(beta);                        12        9        3        6                       alpha   + alpha  + alpha  + alpha  + 1Expand(%) mod 2;                                      0```

---

Duncan

## Quote the argument to sum...

Quote sum's first argument to prevent premature evaluation

```y:=n->sum('y(k)',k=0..n-1):
y(0):=a:y(4);                                     8 a```

This is a common problem when using sum.

---

Duncan

## various options...

There are various options some of which are operating system dependent,

My preferred solution would be to export or print to PDF:

http://www.maplesoft.com/support/help/Maple/view.aspx?path=worksheet%2fmanaging%2fexportPDF

---

Duncan

## curry...

Another option is to use the  ?curry procedure. In the examples below, the procedure with three arguments, g, is transformed into procedures taking two arguments, g's first argument having been supplied in the call to curry.

http://en.wikipedia.org/wiki/Currying

```g := proc(w, x, y)
x + y^w
end proc:h := curry( g, 2 ):h(x, y);                                        2                                   x + y for j to 3 do
f[j] := curry(g, j);
end do:f[1](x, y);                                    x + yfor j to 3 do
f[j](x, y)
end do;                                    x + y                                        2                                   x + y                                         3                                   x + y ```

---

Duncan

 1 2 3 4 5 6 7 Page 1 of 7
﻿