Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The command is ssystem. See its help page (?ssystem). If the result is a number in string form, use parse to make it a number. I think that it'd be preferable (and perhaps necessary) to make your shell commands into a single command. The assignment to result within the shell seems superfluous. So, for example,

Result:= ssystem("`python model.py 1 2 3 4 5 6 7 8 9 10`"); #Inner quotes may not be needed.
if Result[1]=0 then result:= parse(Result[2]) fi;

You may also be interested in Maple's built-in Python interpreter. See ?Python.

No, there's no software that can do that.

First, you need to choose a name for the independent variable. I chose x. Then

dsolve({diff(y(x),x$2)-y(x), y(0)=0, y(1)=1})

The returned result is obviously equivalent to sinh(x)/sinh(1), but if you want Maple to express it in this form, a few extra steps are needed.

I think that using the method= custom option of Sample means that the sampling procedure to be used should be supplied as the RandomSample option of the Distribution command.

I propose the following algorithm for generating a random sample of size n from MIXTURE:

1. Generate a sample S of size from Uniform(0,1).
2. Count members of S less than p. Call this n1, and let n2:= n - n1.
3. Generate samples S1 and S2 of sizes n1 and n2 from U1 and U2, respectively.
4. Return the concatenation of S1 and S2 in the appropriate rtable format.

This should work for any U1 and U2, regardless of whether they're uniform or whether their supports are disjoint or overlapping.

Edit: I just saw that you proposed a sampling method that uses solve. I think that the above will be faster because it's purely numeric.

Where did you find RandomSampleSetup

There are eight simple algorithms (really just interpolation formulas) that Maple can use for quantiles of raw data, including quartiles. These are documented on help page ?QuaNtile (not ?QuaRtile), but the same method options can be used with either command. To get 2.5, do

Statistics:-Quartile([1,2,3,4,5,6,7,8], 1, method= 4); 

In the following, I've changed your integral to one that is actually possible.

J:= unapply(int(W^2*(CN-CT*sin(theta)), theta= 0..Pi), [W,CN,CT]);
F:= (w, Cn, Ct)-> sigma/2/Pi/v^2*add(J~(w, Cn, Ct)):
F(w, Cn, Ct);

 

Another way:

N:= 5:
Matrix([[0$(N+1)], [$1..N]], scan= band[0,1]);

The option scan= band is often a convenient way to define matrices that are organized along diagonals. The [0,1] represents nonzero diagonals below the main and 1 above.


 

I agree that that increasing the offset sends you back to 1902 is a bug, but it's easy to explain how it occurs. The timestamp must be a 32-bit signed integer, so values between 2^31 and 2^32-1 are treated as negatives. If you pass such a value directly to option timestamp, you'll rightly get an error. But apparently option offset is allowing some hardware arithmetic with those 32-bit integers.

The Eastern Standard (EST) epoch ends precisely at 

StringTools:-FormatTime("%Y-%m-%d %R:%S", 2^31-1-iolib(25));
                     
"2038-01-18 22:14:07"

Recall from my previous Answer that the EST epoch began "1969-12-31 19:00:00". So the epoch ends precisely 68 years, 18 days, 3 hours, 14 minutes, and 7 seconds after it began. I'm going to add 1 second to that; you'll see why in a moment. So, it's 8 seconds. If we take the start of the epoch and subtract that amount of time from it, we get precisely "1901-12-13 15:45:52". So, if I "add 1 second to" the FormatTime input, I'll get that. Lo and behold:

StringTools:-FormatTime("%Y-%m-%d %R:%S", 2^31-iolib(25));
                     "1901-12-13 15:45:52"
 

I don't know to what extent it helps to know this, but infinity (like Pi) is both a name and a constant. But they aren't names which have been explicitly assigned values (outside of a floating-point context). How they are treated depends on the code that they are passed to looking for them and treating them specially. If they get no special treatment, then they act just like any other unassigned name.  

Other than that, several of the "arithmetic of infinity" examples that you show are bugs: Automatic simplification is causing the subtraction of identical symbolic terms to be before "noticing" that those terms contain infinity (rather than any other name) and thus deserve special handling.

There is a special command for redefining I. If you want to change it to _i, do

interface(imaginaryunit= _i):

At this point, you can simply use as a variable, or you can declare it local with no warning message.

The imaginary unit is the only constant that Maple treats in this weird way. It's not a name, nor will any amount of quotes (either ' or `) "unevaluate" it to a name.

I recommend that you never use the method shown by Tom Leslie because it is extremely inefficient for long L. Even if you don't plan on having a long list, using this method is reinforcing a bad habit that is likely the number-one cause of unnecessarily slow Maple programs.

The precise thing NOT to do is this: Build a list, sequence, or set by iteratively adding elements to an existing list, sequence, or set. That operation requires time proportional to the square of the final size; whereas building a container should ideally require only time proportional to the final size itself. Unlike these immutable containers--lists, sequences, sets--the mutable ones--Arrays, Vectors, tables (as used by Kitonum)--do not have this problem.

If you have Maple 2019, the following will build your list efficiently, yet retain most of your original code structure:

restart:
(x, y, s):= (12, 46, 0):
L:= [
    while 0 < y do
        if y::odd then s+= x; --y else x*= 2; y/= 2 fi;
        (x,y,s)
    od
];
L := [24, 23, 0, 24, 22, 24, 48, 11, 24, 48, 10, 72, 96, 5, 72, 
  96, 4, 168, 192, 2, 168, 384, 1, 168, 384, 0, 552]

 

The epoch starts at midnight, 01-Jan-1970, in the GMT time zone. The corresponding time in the Eastern Standard time zone (EST) is 7:00:00 pm, 31-Dec-1969. If you're in EST and you format the hours, minutes, and seconds for timestamp= 0, that's the time that you'll get.

There is a recursive formula to count partitions which is fairly simple computationally but fairly weird mathematically (as recursive formulas go). Here it is coded in Maple:

restart:
nPart:= proc(n::integer)
option remember;
local k;
    if n<=0 then `if`(n=0,1,0)
    else
        -add(
            (-1)^k*(thisproc(n-k*(3*k-1)/2) + thisproc(n-k*(3*k+1)/2)),
            k= 1..floor((sqrt(24*n+1)+1)/6)
        )
    fi
end proc:

For large n, there are some more-complicated formulas that are faster. But the above isn't horribly slow for moderately large n.

I post this not because it's any better than combinat:-numbpart but because it's simple enough to have significant educational value.

You have 6 algebraic equations to fit 6 parameters. So it's very likely that the solution space is a 6 - 6 = 0-topological-dimension subset of C^6 (C = complex numbers), so the probability that there's an integer 6-tuple in that subset is infinitesimal. 

Note that you mistakenly used in the solve command.

Here are four non-hackish ways to do it. The first, unapply, requires that the recurrence have a closed-form solution. The others have no such requirement.

The second, makeproc, requires that the recurrence be expressible as a single algebraic formula. The remaining two do not have that requirement, and they allow formulas and procedures of arbitrary complexity.

The third, module, is a very general technique that's important to learn. They're like classes in C++. Both the local and export variables retain their values between invocations, thus avoiding the need for globals. Nearly all large pieces of Maple code are written as modules.

The fourth, procname/thisproc, is also important to learn. It uses a technique called memoization: building a table matching all input with its output. Memoization can also be made automatic by giving a procedure option remember. In this technique, the procedure's own name takes the place of the global.

restart:
Last:= unapply(rsolve({f(n)=4*f(n-1)+n, f(0)=1}, f(n)), n):
seq(Last(k), k= 1..10);

restart:
Last:= rsolve({f(n)=4*f(n-1)+n, f(0)=1}, f(n), makeproc):
seq(Last(k), k= 1..10);

restart:
Last:= module()
local _Last, ModuleApply:= (k::posint)-> (_Last:= 4*_Last+k);
export Init:= N-> (_Last:= N);
end module:
Last:-Init(1):
seq(Last(k), k= 1..10);

restart:
Last:= (k::posint)-> (procname(k):= 4*thisproc(k-1) + k):
Last(0):= 1:
seq(Last(k), k= 1..10);

 

First 117 118 119 120 121 122 123 Last Page 119 of 395