Carl Love

Carl Love

27666 Reputation

25 Badges

12 years, 127 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

A sequence can be accumulated (as a sum or via any other function) very efficiently at the same time as it's created by using the scan option to seq:

y:= [seq['scan'= rand(1..6)]](1..10);
              y := [1, 5, 2, 5, 6, 2, 3, 4, 4, 6]

(L,H):= selectremove(`<=`, {y[]}, 3); 
                  L, H := {1, 2, 3}, {4, 5, 6}

y:= subs((L=~ -1) union (H=~ 1), y);
            y := [-1, 1, -1, 1, 1, -1, -1, 1, 1, 1]

y:= [seq['scan'= `+`]](y);
             y := [-1, 0, -1, 0, 1, 0, -1, 0, 1, 2]

#The plot can be done by
dataplot(y);

#The 1st 4 commands can be done by this single command:
y:= [seq['scan'= `+`]](seq['scan'= 2*rand(0..1) - 1](1..10));

The Maple expressions cos(x)=sqrt(1-sin(x)^2) or cos(x)=-sqrt(1-sin(x)^2) and x=0 or x<>0 automatically evaluate to false and true, respectively, before they are passed to is. The solution is to replace A or B with its inert form Or(A, B). See help page ?boolean.

To completely achieve the effect that you were hoping for from U:= U(x), you need to use alias as well as PDEtools:-declare:

restart;
alias(U=U(x)); PDEtools:-declare(U);

This will abbreviate U(x) to U for both input and output. Using declare without alias will not let you abbreviate your input.

If is an unassigned symbol, then A[B] is equivalent to A:-B. On the other hand, if is an export of A, and is also an assigned symbol outside of A, then A:-B must be used to disambiguate the Bs.

Like this:

foldl(gcd, lst1[]);

You could also use foldr. Since gcd is associative, it doesn't make any difference.

If is any set, and f is any binary operation on S, then the fold commands can be used to extend f to an arbitrary number of arguments.

After the loop, do

save f, "filename";

I don't know any way to append to a file with the save command.

Here is an implementation in Maple of an infix operator akin to the that you showed from bash. I added an additional feature that the version number is automatically incremented.

restart
:
(* An infix operator for filename formatting with automatically incrementing
   version number

Parameters:
   f::anything   the "stem" of the filename
   V::anything   the version
      If V is a variable assigned an integer, then it's incremented and used;
      if V is an unassigned variable, then it's assigned 1 and used;
      if V is anything else, it's appended to the filename as is.
   w::posint     the version field width
      The field width to use for nonnegative integer version numbers. They get
      padded with leading zeros to width w.
   ext::string   the file name "extension" 
*)

`&$`:= proc(f, V::uneval, w::posint:= 2, ext::string:= "txt")
local v:= eval(V), N:= V::name, n:= v::name, i:= v::integer, p:= `if`(N,1,0);
    String(
        f,
        0 $ w - 
            if i and (N implies v > -2) then length(v+p) + `if`(v = -p, 1, 0)
            else `if`(n,1,0)
            fi,
        `if`(N, `if`(n, (V:= 1), `if`(i, ++V, v)), v), 
        `if`(ext="", "", "."||ext)
    )
end proc
:
#Usage examples:
V:= 'V': #Erase prior value, if any
filename &$ V;
                        "filename01.txt"
filename &$ V;
                        "filename02.txt"
V;
                               2

#To change the width or extension from their defaults, use the operator in prefix form:
&$ (myfile, 7, 3, "map");
                        "myfile007.map"

 

What you want is a basic string operation, not a file operation. That might be why you had trouble finding it.

MakeName:= proc(f::string, ver::posint, wid::posint:= 2, ext::string:= "txt")
    sprintf("%s%0*d.%s", f, wid, ver, ext)
end proc:

MakeName("MyFile", 1);
                         "MyFile01.txt"

 

This works:

thaw(eval(evalindets(expr, specfunc(invlaplace), freeze), t= 0));

To understand why your other ideas can't work, look at

In1:= indets(expr, anything);
In2:= indets(expr, Not(specfunc(invlaplace)));

For any type TNot(T) is also a type; it doesn't help you do want you want in this case.

Just add this to your initialization file:

plots:-setoptions(size= [300, 300]):

For some of the negative values of in your given range (-0.9 .. 0.2*Pi), the solve command in Proc returns (correctly) results with nonzero imaginary parts. This causes problems for some of the subsequent plotting commands. If you change the range to -0.4 .. 0.2*Pi, for example, then the command completes fine. I'm not saying that this is the widest range that'll work, simply that it's one that works.

Both your mysterious lack of randomization and the absence of infolevel printouts are due to the integral's value being "remembered" by evalf. If you simply put forget(evalf) into your loops, those anomalies will disappear.  Indeed, all that you need is this forget; you can remove the randomize.

restart:
infolevel[`evalf/int`]:= 4:
to 3 do
    ## seed:= randomize(rand());
    forget(evalf);
    J:= (evalf@Int)(
        4*x1*x3^2*exp(2*x1*x3)/(1+x2+x4)^2, 
        [x||(1..4)]=~ 0..1, method= _MonteCarlo, epsilon= 1e-2
    )
    ## print('seed' = seed,  'J' = J);
od;

Furthermore, it seems as if you were to use randomize, it would have no effect. I suspect (but I'm not sure) that this is because the random numbers are being generated by externally compiled code rather than by the Maple call-backs mentioned by @acer. This is unfortunate, because it means that the values cannot be stabilized by using randomize(key) where key is a loop invariant. The lack of stable answers makes debugging difficult.

I find this little utility procedure useful, because it lets you "forget" without needing a separate line of code for it (thus promoting functional programming):

forgotten:= C-> (forget(C), C):

Then in the loop, remove forget(evalf), and replace evalf@Int with forgotten(evalf)@Int.

For polynomials in C[x], the distinguishing of roots is done by the index option of RootOf. See help pages ?RootOf and ?RootOf,indexed. An ordering of the complex numbers based on argument and magnitude is used for this purpose. The ordering can be changed (this is described on ?RootOf,indexed). Since it looks like you're a new Maple user, I wouldn't recommend changing the ordering on your own just yet.

Here is an example:

The RootOf command always has a single bound variable, which it changes to _Z regardless of your initial specification. In the case of an insoluble irrecducible polynomial in C[x] with exact coefficients, the allvalues command separates to roots by index.

Rts:= [allvalues](RootOf(x^5+x^2+1, x));

[RootOf(_Z^5+_Z^2+1, index = 1), RootOf(_Z^5+_Z^2+1, index = 2), RootOf(_Z^5+_Z^2+1, index = 3), RootOf(_Z^5+_Z^2+1, index = 4), RootOf(_Z^5+_Z^2+1, index = 5)]

NRts:= <evalf(Rts)>:
DataFrame(<NRts | argument~(NRts) | abs~(NRts)>, columns= [Root, Arg, Abs]);

DataFrame(Matrix(5, 3, {(1, 1) = .7515192324+.7846159210*I, (1, 2) = .8069402580, (1, 3) = 1.086463667, (2, 1) = -.1545896767+.8280741332*I, (2, 2) = 1.755357607, (2, 3) = .8423803999, (3, 1) = -1.193859111, (3, 2) = 3.141592654, (3, 3) = 1.193859111, (4, 1) = -.1545896767-.8280741332*I, (4, 2) = -1.755357607, (4, 3) = .8423803999, (5, 1) = .7515192324-.7846159210*I, (5, 2) = -.8069402580, (5, 3) = 1.086463667}), rows = [1, 2, 3, 4, 5], columns = [Root, Arg, Abs])

 

Download IndexedRootOf.mw

This works:

thaw(PDEtools:-Solve(subs(Ys=~ (Fz:= freeze~(Ys)), sys), Fz));

The variable names that have session-dependent assumptions are the indices of the table `property/OrigName`. Thus the following supplies the information that you're looking for, although not exactly in the format that you showed:

about(indices(`property/OrigName`, 'nolist'));

You can learn where the information is stored by reading the code of about, which is fairly short and straightforward:

showstat(about);

1 2 3 4 5 6 7 Last Page 1 of 392