Joe Riel

9590 Reputation

23 Badges

19 years, 139 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The arguments of an unevaluated function call, which is what your exp(I*theta) is, can be extracted, as an expression sequence, using the op command:
op(exp(I*theta));
            exp*theta
Use op with an integer to extract a particular argument:
op(2, f(a,b,c));
                 b
Be aware that the Maple structure array has been largely superceded by Array. A simple procedure that does generates an Array, indexed from 0 to n and initialized with corresponding values 0 to n, is
MyArray := proc(n::nonnegint) Array(0..n, [seq(0..n)] ) end proc:
If you want to start the indexing from 1, you might use a Vector, which is, more or less, a one-dimensional Array with an index that starts from unity:
MyVector := proc(n::nonnegint) Vector([seq(0..n)]) end proc:
The problem is with the formal parameters. Indexed variables (the subscripted variables) don't work as formal parameters. Nor does the imaginary unit (by default `I'). It is, by the way, an appropriate place to ask.
For a few ideas, possibly not relevant to your application, you might look at a package I created quite a while ago, called manifold. It's written for Maple V R4, so is quite dated and rather crude. However, the documentation isn't too bad (there is a postscript of the typeset source code). It isn't limited to three dimensions and can integrate forms over manifolds. I don't have a local copy, but it is available here.
To generate all permutations, do
> with(combinat):
> perms := permute([1$9,2$9,3$9],9): # you don't want to print them
> perms[1];
         [1, 1, 1, 1, 1, 1, 1, 1, 1]
> perms[234];
         [1, 1, 1, 1, 3, 3, 2, 3, 3]
> perms[-1]; # last one
         [3, 3, 3, 3, 3, 3, 3, 3, 3]
To just count the number of permutations, you can do
> numbperm([1$9,2$9,3$9],9);
                19683
How long did you wait? Does your loop do anything? On my machine:
convert(90*time(proc() to 10^7 do od end())*Unit(sec), units, Unit(minute));
           4.528500000*Unit(min)
Maple V R5 is old; I don't have a version that runs on Linux, so can only give some hints. First, read the file as one long text string. One way is to read each line and catenate:
fd := fopen(filename);
input := "";
line := readline(fd);
while line <> 0 do
   input := cat(input,line);
   line := readline(fd);
od;
fclose(filename);
Now you need to convert `input' to a set of sets of characters. In Maple 10 this can be readily accomplished with
use StringTools in
  RegSplit("[^a-zA-Z]", input);
  map(str -> {op}(Explode(str)),{%});
  remove(`=`,%,{});
  map(curry(map,parse),%);
end use;
With Maple V you have some work to do. You'll need to use the substring command to access each character, then determine whether to convert it to a name (via parse) or to split the string and start a new set. I don't recall whether Maple V has any regular expression matching, I think not. So you might designate just a few characters as `splitters' (comma, space, newline) and check for those individually.
I've always used rpn (first was my dad's HP-35) and struggle with algebraic entry. I've owned an HP-15 since they came on the market (early 80s). About six years ago there was a version of Maple that ran on a handheld device, a Casioppia, I believe. I got to use it for a few months. It proved useful when I was consulting and didn't have a laptop (still don't).
Use the print command. If a copyright is included in the options statetement, you will also need to set interface(verboseproc=2), otherwise, in the gui it is displayed as proc() ... end proc.
interface(verboseproc=2):
print(simplify);
Try the following
i := diff(q(t),t);
KirchoffLaw:=E[R]+E[L]+E[C]-E[emf]=0;
E[R]:=R*i;
E[L]:=L*diff(i,t);
E[C]:=1/C*q(t);
KirchoffLaw;
et := convert(piecewise(t<1,0,t<3,100,0),Heaviside);
odeQ := eval( KirchoffLaw, {E[emf]=et,R=50,C=0.01,L=1});
ics:=q(0)=0, D(q)(0)=0;
dsolve({odeQ,ics},q(t));
Check out the VectorCalculus package (?VectorCalculus). The ?examples,VectorCalculus worksheet gives examples of line integrals.
In the Standard GUI you can create symbols with arrows over them. Open the Layout palette, insert the Symbol with the `b' over the `A', then open the Arrows palette and change the `b' to the desired arrow shape. If you use lprint to print the Maple output, you can see how to create this via typing. The code inserted by the palettes contains optional fields to set the colors. If you are happy with the defaults you can omit them and then do, for example:
xvec := `#mover(mi("x"),mo("&rarr;"))`;
That displays xvec as an x with a right pointing arrow on top. Now, if you actually want to assign a Vector to the fancy x, things get a little tricker. Messing with the palettes gets tedius, so, you could set an alias (see ?alias for details). Using worksheet mode in the Standard GUI you could do
restart:
alias(`#mover(mi("x"),mo("&→"))` = xvec):
If you then type
xvec := <1,2,3,4>;
an assignment is displayed with the left side being the x with the arrow over it, the right side being the Vector. This can also be done in Document mode, but because the left side of assignments are normally suppressed, the x with an → over it is not shown, so there isn't much point. To simplify the process you can assign a procedure
MakeVector := x ->  nprintf("#mover(mi(\"%A\"),mo(\"&rarr;\"))", x):
then use it as
alias(MakeVector(x) = xvec, MakeVector(y) = yvec):
xvec := <1,2,3>;
yvec := <4,5,6>;
I'll assume that you are looking for a numeric, rather than symbolic, solution (good luck with the latter). The following works: y := sin(x)/x: dy := diff(y,x): sol := fsolve(dy,{x},0..10); # the third parameter restricts the domain sol := {x = 4.493409458} eval(dy,sol); # check the result 1*10^(-11) eval(y,sol); # evaluate the expression -0.2172336282
Here's one way, probably not the best.
tmp := Int(D[3](F)(x,t,y(x,t),diff(y(x,t),x),diff(diff(y(x,t),t),x))(diff(yv(x,t),t,x)),t):
tmp2 := convert(tmp,D):
indets(tmp2, typefunc(anything, typefunc(identical(yv),specindex(posint,D)))):
convert(%,diff);
                  {diff(yv(x, t), x, t)}

Your observation is correct, collect works with power of integers, not symbolics. For the simple example you gave, factor will do nicely. However, consider

poly := a*x^b + x^b + a*x^(b+1) + c*x^(b+1);

The collect command can also handle unevaluated function calls, so one approach is to convert the monomial terms to function calls, collect, then convert back:

subsindets(poly, identical(x)^anything, () -> f(op(args)));

         a*f(x, b) + f(x, b) + a*f(x, b + 1) + c*f(x, b + 1)

collect(%,f);

                (a + 1)*f(x, b) + (a + c)*f(x, b + 1)

eval(%, f=`^`);

                 (a + 1)*x^b + (a + c)*x^(b+1)
First 109 110 111 112 113 114 Page 111 of 114