Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The for loop

for i from a by b to c while d do
     e
end do

is equivalent to the do loop

i:= a:
do
     if (i > c) or not d then  break  end if;
     e;
     i:= i+b
end do;

 

The problem is that your function is undefined at 0. Are you looking for a rational function that closely approximates M6? We can expand at a=1 rather than a=0:

numapprox:-pade(M6, a=1, [3,3]);

The [3,3] indicates the degree of the numerator and denominator respectively.

There are several cases to consider:

The number of indices is known at the time the program is written: In this case, use nested loops:

for i from 1 to Ni do
     for j from 1 to Nj do
         
...
             for n from 1 to Nn do
                  ...
             end do
        ...
     end do
end do;

More generally, if the index values are stored in sets or lists  Si, Sj, ..., Sn:

for i in Si do
     for j in Sj do
         ...
               for n in Sn do
                      
...
                   end do
           
... 
    end do
end do;

The next two cases involve Cartesian products of the sets or lists of indices.

The number of indices is unknown at the time the program is written: In this case, use an iterator over the Cartesian product:

Iter:= combinat:-cartprod([Si, Sj, ..., Sn]);
while not Iter[finished] do
     v:= Iter[nextvalue]();
     # Now use v[1] as i, v[2] as j, etc.
    
...
end do;

The number of indices is unknown at the time the program is written and the Cartesian product is relatively small (say, less than 10 million entries): In this case, we generate the entire Cartesian product at once, because it is faster to do so:

CartProdSeq := proc(L::seq({set,list}))
local Seq,i,j;
option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;
    eval([subs(Seq=seq, foldl(Seq
                              , [cat(i,1..nargs)]
                              , seq(cat(i,j)=L[j],j=nargs..1,-1)
                             ))]);
end proc:

for v in CartProdSeq(Si, Sj, ..., Sn) do
    # Now use v[1] as i, v[2] as j, etc.
    
...
end do;

The flush: The fancifully named pigeonhole principle states that if you put p pigeons into holes then at least one hole will have at least x = ceil(p/h) pigeons. The 17 cards are the pigeons and the 4 suits are the holes: ceil(17/4) = 5. So how can we compute p = 17 knowing x = 5 and h = 4? p = (x-1)*h + 1.

The probability of a flush in a five-card draw is not as you state. It is binomial(4,1)*binomial(13,5)/binomiql(52,5). Permutations are not used because order does not matter.

The straight: Suppose that you had all the cards excepts the 5s and 10s. Then you'd have 44 cards and no straight. Add one 5 or 10 and now you have 45 cards and a straight (5*4^4 = 1280 straights in fact).

The probability of a straight in a five-card draw is 10*4^5/binomial(52,5).

You need to replace print(y) with print(eval(y)).

I don't think that I can give an adequate explanation of why. But try reading ?eval, beginning with the seventh paragraph under Description, the one beginning "The two remaining calling sequences...." The paragraphs above that apply to the two-argument version of eval, which is an unrelated command.

To make a column vector from a sequence, you enclose the sequence in angle brackets, like this

S:= 1,2,3: #a sequence
< S >;

If you end your printf statements with semicolons, then those characters will not appear.

The return value of a printf statement is NULL. When two printfs are juxtaposed in 2D input, the juxtaposition is interpreted as multiplication. NULL*NULL = NULL^2, which prints as ()^2. If there is an intervening semicolon, then they are not juxtaposed.

@John Fredsted It is not ad hoc: evalc assumes that variables are real unless otherwise specified.

In your first code, you were accidentaly assuming that the variables were real, but Maple was not. Maple could not put any variables on the diagonal in that case because they were not known to be real.

There is a three-dimensional figure called a Gomboc which was discovered with the help of Maple. See this Wikipedia page.

I'd recommend

1. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, by Donald Knuth. This book has been translated into Spanish and many other languages.

2. Modern Computer Algebra, by Joachim von zur Gathen and Jurgen Gerhard.

3. Matrix Computations, by Gene H. Golub and Charles F. Van Loan.

You have 8 data points and 15 parameters. The number of data points must be greater than or equal to the number of parameters.

This is considered linear data fitting rather than nonlinear because the model function is linear in the parameters. The fact that it is nonlinear in the independent variables is irrelevant.

If you had enough data, the commands would be

x1_values:= < 0.1, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80 >:
x2_values:= < 1, 2, 3, 4, 5, 6, 7, 8 >:
x3_values:= < 11, 12, 13, 14, 15, 16, 17, 18 >:
x4_values:= < 10, 20, 30, 40, 50, 60, 70, 80 >:
y_values:= < 30, 40, 60, 70, 90, 120, 150, 200 >:
model:=
     a + b*x1 + c*x2 + d*x3 + e*x4 + f*x1^2 + g*x2^2 + h*x3^2 + i*x4^2 + j*x1*x2 +
     k*x1*x3 + l*x1*x4 + m*x2*x3 + n*x2*x4 + p*x3*x4
:

Statistics:-LinearFit(
     model,
     < x1_values | x2_values | x3_values | x4_values >,
     y_values,
     [x||(1..4)]
);

Note that the old stats package is deprecated and has been replaced by Statistics.

Your main problem is that you have used = for assignment statements when you should be using :=. Here's my Collatz procedure:

Collatz:= proc(val::posint)
local res:= val, k;
     for k while res <> 1 do
          if irem(res, 2, 'res') = 1 then res:= 6*res+4 end if;
     end do;
     k-1
end proc;

This uses the fact that irem also computes the quotient and returns it in the third argument, if present. You may ask "Why 6*res+4 instead of 3*res+1?" The reason is that I need to compensate for the fact that the integer quotient of the odd number has already been taken. So it's 3*(2*n+1) + 1, which is 6*n+4. The return value is the number of iterations required to get to 1.

Everything on the left side of eq2 cancels, leaving just 0:

simplify(eq2);

So there is no C left to solve for.

Change your plot command from

plot([f(r)[1],f(r)[2],-18..18]);

to

plot([f(r)[1], f(r)[2], u=-18..18]);


Your code can be vastly simplified. I'll do that later.

Give the command

interface(rtablesize= 12);

Then you will be able to see the contents of your Matrix. I picked 12 because that's the largest dimension of your Matrix.

First 326 327 328 329 330 331 332 Last Page 328 of 395