Joe Riel

7969 Reputation

22 Badges

14 years, 349 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Use LinearAlgebra:-Equal to test equality of Matrices (with expressions as elements). For more general testing, you can use verify (with appropriate verification argument).
with(LinearAlgebra):
A := <<1,2>>:
B := Copy(A):
Equal(A,B);
             true

A := <<1,2>>:
B := <<1.001, 1.99>>:
verify(A,B,'Matrix'(float(5,digits=3)));
                                     true

verify(A,B,'Matrix'(float(5,digits=4)));
                                     false
Use exp(x) for e^x
Yes. Explain what it is you want to do.
Your comments are basically correct. The statement (x -> x.x)(procname(x,n/2)) passes the argument procname(x,n/2) to the anonymous procedure x -> x.x. It is equivalent to doing tmp := procname(x,n/2); tmp.tmp but avoids the local variable tmp. The reason that . was used rather than * is to allow this to work with Matrices: Pow(<<1|2>,<3|4>>,-2); [11/2 -5/2] [ ] [-15/4 7/4 ]
Here's one approach:
> M := Matrix([[x,0],[0,y],[y,0],[0,x]]);
                                      [x    0]
                                      [      ]
                                      [0    y]
                                 M := [      ]
                                      [y    0]
                                      [      ]
                                      [0    x]

> DM := map(v -> `if`(v=0,0,rcurry(diff,v)),M);
                    [() -> diff(args, x)             0         ]
                    [                                          ]
                    [         0             () -> diff(args, y)]
              DM := [                                          ]
                    [() -> diff(args, y)             0         ]
                    [                                          ]
                    [         0             () -> diff(args, x)]

> map(apply,DM,x^2+y);
                                 [2 x     0 ]
                                 [          ]
                                 [ 0      1 ]
                                 [          ]
                                 [ 1      0 ]
                                 [          ]
                                 [ 0     2 x]
This doesn't solve the problem of applying it to a Matrix.
As Roman suggests, create a procedure rather than a polynomial. However, if you have already created the polynomial, you then need to convert it to a procedure. The procedure unapply is useful here.
P := a*x1^2 + 3*x2^2 + b:
f := unapply(P, [x1,x2]):
f(z1,z2);
            a*z1^2+3*z2^2+b
Note that your example use of eval is incorrect. Proper usage is eval(P, [x=1,y=2]).
> LengthU := norm(u,2);
                         2
Unlike many other elements, Maple does not consider rtables (the low-level struture that includes Vectors) equal even if they have the same elements. The LinearAlgebra command Equal can be used to determine element by element (or just structure) equality of two Vectors. One way to do what you want is to convert the set to a list, then use ListTools:MakeUnique, passing LinearAlgebra:-Equal as the optional comparison procedure. Thus lst := convert(s, list): lst := ListTools:-MakeUnique(lst,1,Equal): s := convert(lst, set); An interesting observation is that if you had done s := {UnitVector(1,2), UnitVector(1,2)}: s would have been assigned a singleton. The reason for that is subtle, Maple applies its set simplification to the input before UnitVector is called, so at that point the set consistents of two identical function calls. This simplification can result in incorrect results if the functions return different values.
Try spacecurve([2*t,0,0],t=0..1)
You must have used the command with(inttrans) somewhere, otherwise Maple wouldn't have plotted the first y1. However, I have no problem with the second. What version of Maple are you using? Note that y1 is expressed in terms of the Heaviside function, which may have caused problems for some versions of Maple (my memory is fuzzy).
A mathematical, rather than programmatical, approach is the simpler
SplitPolynomialEvenOdd := proc(poly::polynom(anything,v), v)
description "return the even and odd parts of a polynomial in v";
local p,m;
    p := collect(poly,v);
    m := subs(v=-v,p);
    return ((p+m)/2, (p-m)/2);
end proc:
Here's one approach.
assume(p::positive,l::positive,a::positive,q::positive);
eqn :=-p*(l^2-a^2)^(3/2)+a^3*q;
                                   2     2 (3/2)     3
                     eqn := -p~ (l~  - a~ )      + a~  q~

eqn2 := isolate(eqn,a^3);
                                            2     2 3/2
                                  3   p~ (l~  - a~ )
                        eqn2 := a~  = -----------------
                                             q~

map(x -> x^(2/3), %);
                                  /      2     2 3/2\(2/3)
                        3 (2/3)   |p~ (l~  - a~ )   |
                     (a~ )      = |-----------------|
                                  \       q~        /

combine(%,power);
                              /      2     2 3/2\(2/3)
                          2   |p~ (l~  - a~ )   |
                        a~  = |-----------------|
                              \       q~        /

# At this point it is tricky to get Maple to distribute
# the power.  Easier just to do it by hand:
eqn3 := a^2 = (p/q)^(2/3)*(l^2-a^2);
                               2   / p~ \(2/3)    2     2
                     eqn3 := a~  = |----|      (l~  - a~ )
                                   \ q~ /

sol := solve(eqn3,a):
sol[1];
                     //    / p~ \(2/3)\ / p~ \(2/3)\1/2
                     ||1 + |----|     | |----|     |    l~
                     \\    \ q~ /     / \ q~ /     /
                     -------------------------------------
                                    / p~ \(2/3)
                                1 + |----|
                                    \ q~ /
Again, distribute the power by hand. Is there a command that does that? It's easy to write one, though it won't be rigorous. You could try using the RealDomain package; that nearly solved the problem in one go but I couldn't figure out a clever way to factor out the common terms in the numerator and denominator.
You write "maxima", meaning more than one maximum. What do expect to get for the given expression, assuming the chosen component is one? That is, do you want to get the indices 1 and 2, corresponding to the two components whose first element is 8? If that is what you want, then the following will return the list of indices: maxima_indices := proc(indx::posint, lst::list) local elem,i,val; val := max(seq(op(indx,elem),elem in lst)); return [seq](`if`(op([i,indx],lst)=val,i,NULL) ,i = 1..nops(lst)) end proc: H1 := [[8,9,11],[8,10,11],[5,10,6]]: map(maxima_indices,[1,2,3],H1); [[1, 2], [2, 3], [1, 2]]
I'm unsure as to the precise mechanism, however, this is probably caused by the assuming keyword making a substitution into the table (a local variable z~ with assumptions replacing z), the result evaluated, then the original z replacing the z~. At the conclusion of this we are left with a different table, identical to the original. It has no name and must be displayed as a table. I don't know what your second question means.
I'm not sure what you want. Currently, the only way for users to generate help pages is by writing them in the Maple gui (templates are available), saving them as worksheets, then using Maple commands (makehelp and INTERFACE_HELP) to save the worksheets as help pages in a help database. This is acceptable for a small package with a few help pages but is cumbersome for larger packages with many help pages. I wrote a small package, generichelp, that can be used to strip the user style table from a user created help-page/worksheet. The reason for doing this is that it ensures that the created help pages behave like the ones supplied by Maplesoft; that is, they do not contain character and paragraph styles that are specific to the creator. The original version is available at my home page. I've recently revised it to be compatible with Maple 10 but need to finish it. About a year ago I began work on a package for generating Maple help pages from text files using a custom markup language. Alas, it is not ready for release and I haven't been motivated to work on it for awhile.
First 99 100 101 102 103 Page 101 of 103