Joe Riel

9530 Reputation

23 Badges

20 years, 25 days

MaplePrimes Activity


These are answers submitted by Joe Riel

It is an inert function used by some Multibody components as a flag to indicate special handling (used by the engine). In equations it is generally safe to replace it with its argument.  That is preopt(some_expr) is equivalent to some_expr.

Here is a technique I learned from a colleague.  Replace x with x/a, where a is an unassigned variable that proceeds x, lexicograhically. Apply ?normal to the result, then replace a with 1.  Thus

(**) y:=sum(x^k,k=0..infinity);
                                          1
                                 y := - -----
                                        x - 1

(**) subs(a=1, normal(subs(x=x/a,y)));                   
                                      1
                                    ------
                                    -x + 1

There is the ?RealDomain package, which might be useful.  However, it doesn't assume variables are positive, just real.  And it doesn't work with the assume facility.

Note that Maple automatically simplifies 5^(5/2) to 25*5^(1/2).

Addendum

Given the above, the most useful thing you can do is to create ``(5)^(5/2). A rather pointless one-line procedure that does that is

y := 5^2 * 5^(1/2):
map(x->`if`(x::integer,ifactor(x),`if`(x::`^`,``(op(1,x))^op(2,x),x)),y);
                                       (5/2)
                                    (5)

The blank function (``) evaluates to its argument when expanded, thus

expand(%);
                                        1/2
                                    25 5



 

Here's a different approach.

(**) y := [1,2*b] + [3,4]*(x-1)^2*3;      
                                                                    2
                                    y := [1, 2 b] + 3 [3, 4] (x - 1)

(**) evalindets(y,`*`,p->`~`[`*`](op(p)));
                                             2                2
                                   [9 (x - 1)  + 1, 12 (x - 1)  + 2 b]

expand([1,2] + [3,4]*x);
                          [3 x + 1, 4 x + 2]


Here's the idea I suggested. It uses ?ListTools[BinarySearch] to quickly search a list of "basis" vectors (here a random collection of Vectors). The basis is sorted using the same procedure (lessthan) used in the binary search.

lessthan := proc(v,w)
local i,n;
    n := upperbound(v,1);
    for i to n while v[i] = w[i] do end do;
    i<=n and v[i] < w[i];
end proc:

equal := proc(v,w)
local i,n;
    n := upperbound(v,1);
    for i to n while v[i] = w[i] do end do;
    evalb(i>n);
end proc:
     
# Generate a list of 50 random vectors with dimension 5       
L := [seq(rtable(1..5, random(1..10)), i=1..50)]:
# Use lessthan to sort the Vectors
B := sort(L,lessthan);

# Choose a member from B, and find it in B
ListTools:-BinarySearch(B, B[34], lessthan, equal);
                              34

You might try creating a table that does reverse-lookup. 

BasisIndex := table([seq(basis[i] = i, i=1..upperbound(basis,1))]):

Then, to get the index of Vector v, do BasisIndex[v]. Because v may not be in the basis, you might do

if assigned(BasisIndex[v]) then
   indx := BasisIndex[v];
else
   whatever is appropriate
end if;



A simple way is to use the ?trace command.  Execute

trace(myproc):

where myproc is the name of your procedure, then execute your procedure.  The output of each statement is printed.  From that you might be able to figure out where the error occurs.

Better is to use the debugger.  Execute the command

stoperror('all'):

That tells Maple to launch the debugger when an untrapped error occurs. Execute your procedure.  That should cause the debugger to be launched with the control at the place in the procedure that raises the error. That will likely be inside a Maple library procedure called by your procedure. To figure out the cause you can query the values of variables and expressions in the procedure.

 

 

 

 

For the filename, you can use cat("row",i), "row"||i, or sprintf("row%d",i) (similarly for the ExportMatrix command).

For the M, you can just use an indexed variable: M[i].

Use ?unapply.  For example

A[1] := 23:
unapply(piecewise(x<0, A[1], y < 1, 2, 3),x,y) ;
        (x, y) -> piecewise(x < 0, 23, y < 1, 2, 3)


The problem is that you have not initialized band[i].

You state that N is unknown. But that cannot be the case, it appears as the end point in the first for-loop.  That is, it must be known at that point.

Followup:

I see you did initialize band[i]. Not sure why that didn't work.  Anyhow, because N is known, you can use a seq statement to generate band[i]:

band[i] := [seq( ..., i = 1..2*N)]:

Addendum:

The problem with your initialization is that the for-loop only goes to N, while the assignment loop goes to 2*N.  Change the initialization loop to end at 2*N.  Alternatively, and better, is to use seq as I suggested.

Use the ?currentdir procedure to determine the active directory of each worksheet.

What do you expect the answer to be?  Seems like it should be 1=0. You can use ?frontend to compute that 

frontend(diff, [eq,diff(u(x,t),t)], [{equation,`+`,`*`},{}]);

One way is to create a simple text file that assigns the procedure and then use the ?read statement to read that file from another file or a Maple worksheet.  For example, you might create a file names myfunc.mpl:

---- start of myfunc.mpl --- 
SomeFunc := proc(x)
   return x^2;
end proc:
---- end of myfunc.mpl ---

A better approach is to save the procedure [or module] in a Maple archive (file with extension *.mla).  That can be done with the ?LibraryTools:-Save command. For example, you could include the following line at the bottom of the above file

LibraryTools:-Save('SomeFunc', "MyArchive.mla"):

If you read the entire file into Maple, it will create an archive named "MyArchive.mla" (in the ?currentdir). If that archive is saved in a location read by Maple (in the ?libname path), then the SomeFunc procedure will be available to any Maple session.

First 35 36 37 38 39 40 41 Last Page 37 of 114