Joe Riel

9660 Reputation

23 Badges

20 years, 17 days

MaplePrimes Activity


These are replies submitted by Joe Riel

You should have mentioned what you wanted (or I failed to read it).

with(StringTools):
map2(Select,IsDigit,L);
                                                           ["345", "532", "6422"]

Alternatively,

map2(RegSubs, "[^0-9]+"="", L);
                                                           ["345", "532", "6422"]

 

and once more, with the ~ operator:

Select~(IsDigit,L);            
                                                           ["345", "532", "6422"]

Hmm.  The least-significant digit in that elaspsed time corresponds to 1 yocto-second, a truly remarkable precision 8-).

As you suggested, that Maple routine is poorly written.

Hmm.  The least-significant digit in that elaspsed time corresponds to 1 yocto-second, a truly remarkable precision 8-).

As you suggested, that Maple routine is poorly written.

The last one is the strange one.  I originally wrote it using iquo(nops(a),2) but knew that that wouldn't work because the initializer has the wrong number of elements so went with the shorter version. However, it is better in that it throws an error message rather than returning a weird result. To mimic the first, which ignores the last element, if an odd index, you could do

convert(Matrix(iquo(nops(L),2,'r'),2,L[..-1-r]),listlist);

That's slightly dangerous in that it depends on the evaluation order of the arguments, that is, the iquo must be evaluated before L[..,-1-r], otherwise r is unassigned. Safer [at least hypothetically] is to compute

m := iquo(nops(L), 'r');
convert(Matrix(m,2,L[..-1-r), listlist);

 


 

The last one is the strange one.  I originally wrote it using iquo(nops(a),2) but knew that that wouldn't work because the initializer has the wrong number of elements so went with the shorter version. However, it is better in that it throws an error message rather than returning a weird result. To mimic the first, which ignores the last element, if an odd index, you could do

convert(Matrix(iquo(nops(L),2,'r'),2,L[..-1-r]),listlist);

That's slightly dangerous in that it depends on the evaluation order of the arguments, that is, the iquo must be evaluated before L[..,-1-r], otherwise r is unassigned. Safer [at least hypothetically] is to compute

m := iquo(nops(L), 'r');
convert(Matrix(m,2,L[..-1-r), listlist);

 


 

With Maple 13 you can use the ~ operator:

L := [1,2,3]:
L +~ 3;
                   [4, 5, 6]

I'm surprised that zip works; map is more natural here:

map(`+`, L, 3);
                   [4, 5, 6]

 

Note that taylor generally returns an expression of Maple type series.  Use convert/polynom to convert it to a polynomial.  See ?taylor,details.

Note that taylor generally returns an expression of Maple type series.  Use convert/polynom to convert it to a polynomial.  See ?taylor,details.

I don't believe it is documented, though it should be.  A problem with returning the user-supplied name is that if it is later assigned a value, then one cannot use the eval technique to extract the value.  Of course, as it is, one can never use that technique, directly. 

I'd probably do something like the following (in Maple 13):

restart;
ode := diff(x(t),t)=x(t)*(A-x(t)):
ic := x(0)=x0:
params := [A,x0]:  # save the parameter names.
sol := dsolve( {ode,ic}, x(t), numeric, 'parameters'=params):
sol( parameters=[2,1] );

eval( A,  params =~ rhs~(sol('parameters')));
                                                                         2.

 

The %f format expects a floating point number.  Does vij(1,5)[k] evaluate to a floating point number for k=1..4?  An easy way to see what is happening is to rename printf to something inert, so %fprintf(...).  Then see what the arguments expand to.

The %f format expects a floating point number.  Does vij(1,5)[k] evaluate to a floating point number for k=1..4?  An easy way to see what is happening is to rename printf to something inert, so %fprintf(...).  Then see what the arguments expand to.

Yes, a nice variation.  Thanks.

Here's a variation on the manner of applying the permutation.  It uses a notation that that was developed for rtables but apparently also applicable to lists. That is, one can generate permutations (and more) by appending nested indices.  For example
 

L := [seq("a" .. "f")];
                                 L := ["a", "b", "c", "d", "e", "f"]

Select and reverse a portion of the list:
L[[4,3,2,1]];
                                        ["d", "c", "b", "a"]

In the original blog entry (top of page), where permutation P is applied to list L2, 

[seq(L2[p], p in P)];

one can do instead

L2[P];
                              [b, d, c, a, f, e]


 

Alas, frontend always recursively freezes powers of integers, so there is no good way to handle that.  Here is a homebrew version.  Its third argument is a type that specifies the objects to freeze.

FrontEnd := proc(p, x::list, typ::type)
local frz, eqs, O, k;
    frz := indets(x, typ);
    eqs := {seq(frz[k] = `tools/gensym`(O[k]), k = 1..nops(frz))};
    eval(p(eval(x, eqs)[]), map(rhs=lhs, eqs));
end proc:

y := x^2*sin(x):
FrontEnd(diff, [y, x^2], identical(x^2));
                                                           sin(x)
FrontEnd(diff, [y, sin(x)], identical(sin(x)));
                                                            x^2

Apologies, my memory was wrong, add does not take an optional third argument as does its cousin, seq.  You could combine the two

add(exp(-r*x)*l[x +1]*m[x+1], x = [seq(0..50,5)]);

Apologies, my memory was wrong, add does not take an optional third argument as does its cousin, seq.  You could combine the two

add(exp(-r*x)*l[x +1]*m[x+1], x = [seq(0..50,5)]);
First 90 91 92 93 94 95 96 Last Page 92 of 195