Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are replies submitted by Doug Meade

Like this?
restart;
with( ListTools ):
with( combinat ):
A := [ [1,0,1,0],[1,1,0,0],[0,0,1,1] ]:
L := map( convert, powerset(A), `+` );
 [0, [2, 1, 2, 1], [1, 1, 1, 1], [0, 0, 1, 1], [1, 0, 2, 1], [1, 0, 1, 0], 

   [1, 1, 0, 0], [2, 1, 1, 0]]
B := map(convert,[Categorize((x,y) -> evalb({x[]} = {y[]}),L)],set);
 [{0}, {[2, 1, 2, 1]}, {[1, 1, 1, 1]}, 

   {[1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1]}, {[2, 1, 1, 0], [1, 0, 2, 1]}]
Note that I did change A from a set to a list. This is done because Categorize requires the argument L to be a list. If the equivalence classes can be returned as a set (instead of as a list), then the definition of B can be simplified to
B := Categorize((x,y) -> evalb({x[]} = {y[]}),L);
        [[2, 1, 1, 0], [1, 0, 2, 1]], [[1, 1, 1, 1]], 

          [[0, 0, 1, 1], [1, 0, 1, 0], [1, 1, 0, 0]], [[2, 1, 2, 1]]
The key to this solution is the use of powerset (from the combinat package) to construct the set of all subsets of the elements of A and then to form the sum of the elements in each subset. This conversion is done with an old trick: using convert to replace a list (or set) with the sum of its elements:
P := powerset( A );
      [[], [[1, 0, 1, 0], [1, 1, 0, 0]], [[1, 1, 0, 0], [0, 0, 1, 1]], 

        [[0, 0, 1, 1]], [[1, 0, 1, 0], [0, 0, 1, 1]], [[1, 0, 1, 0]], 

        [[1, 1, 0, 0]], [[1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1]]]
P[2];
                        [[1, 0, 1, 0], [1, 1, 0, 0]]
convert( P[2], `+` );
                                [2, 1, 1, 0]
I hope this has been helpful, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
Like this?
restart;
with( ListTools ):
with( combinat ):
A := [ [1,0,1,0],[1,1,0,0],[0,0,1,1] ]:
L := map( convert, powerset(A), `+` );
 [0, [2, 1, 2, 1], [1, 1, 1, 1], [0, 0, 1, 1], [1, 0, 2, 1], [1, 0, 1, 0], 

   [1, 1, 0, 0], [2, 1, 1, 0]]
B := map(convert,[Categorize((x,y) -> evalb({x[]} = {y[]}),L)],set);
 [{0}, {[2, 1, 2, 1]}, {[1, 1, 1, 1]}, 

   {[1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1]}, {[2, 1, 1, 0], [1, 0, 2, 1]}]
Note that I did change A from a set to a list. This is done because Categorize requires the argument L to be a list. If the equivalence classes can be returned as a set (instead of as a list), then the definition of B can be simplified to
B := Categorize((x,y) -> evalb({x[]} = {y[]}),L);
        [[2, 1, 1, 0], [1, 0, 2, 1]], [[1, 1, 1, 1]], 

          [[0, 0, 1, 1], [1, 0, 1, 0], [1, 1, 0, 0]], [[2, 1, 2, 1]]
The key to this solution is the use of powerset (from the combinat package) to construct the set of all subsets of the elements of A and then to form the sum of the elements in each subset. This conversion is done with an old trick: using convert to replace a list (or set) with the sum of its elements:
P := powerset( A );
      [[], [[1, 0, 1, 0], [1, 1, 0, 0]], [[1, 1, 0, 0], [0, 0, 1, 1]], 

        [[0, 0, 1, 1]], [[1, 0, 1, 0], [0, 0, 1, 1]], [[1, 0, 1, 0]], 

        [[1, 1, 0, 0]], [[1, 0, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1]]]
P[2];
                        [[1, 0, 1, 0], [1, 1, 0, 0]]
convert( P[2], `+` );
                                [2, 1, 1, 0]
I hope this has been helpful, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
You can use the ideas in my posts to obtain and manipulate the correct Fourier cosine series for cos(3*x), as posted by Robert. There is not the division by zero problem, but you will still need to use add and value and eval as I have suggested. Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
You can use the ideas in my posts to obtain and manipulate the correct Fourier cosine series for cos(3*x), as posted by Robert. There is not the division by zero problem, but you will still need to use add and value and eval as I have suggested. Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
This will address your direct questions. I agree with Robert that there are some questions about exactly what you are doing, but I trust that you know the exact nature of your question and are asking for what you do need. Basically, you have to delay the actual execution until the value of the index is known. The easiest way to do this is with a procedure.
B := n->4/Pi*int(cos(3*x)*cos(n*x),x=0..Pi/2);
       /   /                            1   \\
     4 |int|cos(3 x) cos(n x), x = 0 .. - Pi||
       \   \                            2   //
n -> -----------------------------------------
                        Pi                    
B(2);
                                     12 
                                    ----
                                    5 Pi
B(3);
                                      1
Now, you can get the formal result you listed as
sum( B(i)*cos(i*x), i=0..infinity );
                       infinity                       
                        -----        /1     \         
                         \     12 cos|- Pi i| cos(i x)
                          )          \2     /         
                         /     -----------------------
                        -----          /      2\      
                        i = 0       Pi \-9 + i /      
But, this is not correct. This is not defined because of the singularity when i=3. This brings us to a second problem. The sum command is intended for formal sums that will be reduced by a summation formula. While you can evaluate this sum for a specific value of x, it's not possible to get a numeric value for the sum. (There is the problem when i=3, but the real problem is the infinite sum.)
eval( %, x=0 );
                           infinity              
                            -----        /1     \
                             \     12 cos|- Pi i|
                              )          \2     /
                             /     --------------
                            -----      /      2\ 
                            i = 0   Pi \-9 + i / 
evalf( % );
                           infinity              
                            -----        /1     \
                             \     12 cos|- Pi i|
                              )          \2     /
                             /     --------------
                            -----      /      2\ 
                            i = 0   Pi \-9 + i / 
You are not likely to really want an infinite sum. I'll bet that at some point you are intending to use a finite sum. For this, you will do better to use the add command:
add( B(i)*cos(i*x), i=0..10 );
     4     12 cos(2 x)              12 cos(4 x)   4 cos(6 x)   12 cos(8 x)
  - ---- + ----------- + cos(3 x) + ----------- - ---------- + -----------
    3 Pi      5 Pi                     7 Pi          9 Pi         55 Pi   

       12 cos(10 x)
     - ------------
          91 Pi    
Now, evaluating for a specific value of x,
eval( %, x=0 );
                                 109136     
                                -------- + 1
                                45045 Pi    
evalf( % );
                                 1.771208075
You can use many more than 10 terms, if necessary. In these cases I would probably suppress the output. I hope this gets you closer to what you are trying to do. Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
This will address your direct questions. I agree with Robert that there are some questions about exactly what you are doing, but I trust that you know the exact nature of your question and are asking for what you do need. Basically, you have to delay the actual execution until the value of the index is known. The easiest way to do this is with a procedure.
B := n->4/Pi*int(cos(3*x)*cos(n*x),x=0..Pi/2);
       /   /                            1   \\
     4 |int|cos(3 x) cos(n x), x = 0 .. - Pi||
       \   \                            2   //
n -> -----------------------------------------
                        Pi                    
B(2);
                                     12 
                                    ----
                                    5 Pi
B(3);
                                      1
Now, you can get the formal result you listed as
sum( B(i)*cos(i*x), i=0..infinity );
                       infinity                       
                        -----        /1     \         
                         \     12 cos|- Pi i| cos(i x)
                          )          \2     /         
                         /     -----------------------
                        -----          /      2\      
                        i = 0       Pi \-9 + i /      
But, this is not correct. This is not defined because of the singularity when i=3. This brings us to a second problem. The sum command is intended for formal sums that will be reduced by a summation formula. While you can evaluate this sum for a specific value of x, it's not possible to get a numeric value for the sum. (There is the problem when i=3, but the real problem is the infinite sum.)
eval( %, x=0 );
                           infinity              
                            -----        /1     \
                             \     12 cos|- Pi i|
                              )          \2     /
                             /     --------------
                            -----      /      2\ 
                            i = 0   Pi \-9 + i / 
evalf( % );
                           infinity              
                            -----        /1     \
                             \     12 cos|- Pi i|
                              )          \2     /
                             /     --------------
                            -----      /      2\ 
                            i = 0   Pi \-9 + i / 
You are not likely to really want an infinite sum. I'll bet that at some point you are intending to use a finite sum. For this, you will do better to use the add command:
add( B(i)*cos(i*x), i=0..10 );
     4     12 cos(2 x)              12 cos(4 x)   4 cos(6 x)   12 cos(8 x)
  - ---- + ----------- + cos(3 x) + ----------- - ---------- + -----------
    3 Pi      5 Pi                     7 Pi          9 Pi         55 Pi   

       12 cos(10 x)
     - ------------
          91 Pi    
Now, evaluating for a specific value of x,
eval( %, x=0 );
                                 109136     
                                -------- + 1
                                45045 Pi    
evalf( % );
                                 1.771208075
You can use many more than 10 terms, if necessary. In these cases I would probably suppress the output. I hope this gets you closer to what you are trying to do. Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
Colin, > Many thanks for you comment on my forum question, it should solve my problem. Unfortunately, your post was truncated. Is there any chance that you could fix it. Caught by the less-than-sign again. It's now fixed. Wishing you a Merry Christmas, Doug P.S. I tried to send this as a private message, but could not. The problem was that everytime I select the recipient, the To field shows "Colin" but then MaplePrimes responds that this user is unknown. I've had this problem before. Is this a bug, or is there something I am not doing correctly?
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
Colin, > Many thanks for you comment on my forum question, it should solve my problem. Unfortunately, your post was truncated. Is there any chance that you could fix it. Caught by the less-than-sign again. It's now fixed. Wishing you a Merry Christmas, Doug P.S. I tried to send this as a private message, but could not. The problem was that everytime I select the recipient, the To field shows "Colin" but then MaplePrimes responds that this user is unknown. I've had this problem before. Is this a bug, or is there something I am not doing correctly?
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
isolve is much less common and not a command that most users will think to use. Thankfully, it is not neceessary as the same solution can be obtained with solve, using either dollars (float) or cents (integer).
eq1:= q + d = 8:
eq2:= 0.25*q + 0.10*d = 1.25:
solve({eq1, eq2});
                              {d = 5., q = 3.}
eq1:= q + d = 8:
eq2:= 25*q + 10*d = 125:
solve({eq1, eq2});
                               {d = 5, q = 3}
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
You have already received some pretty detailed help. You should be able to take what you have been given and come close to what you need to produce. One suggestion: try to do this step-by-step then gradually start to combine steps to put together a general tool:
LO := 1;
HI := 5;
steps to find F1 through F5
Good luck, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
You have already received some pretty detailed help. You should be able to take what you have been given and come close to what you need to produce. One suggestion: try to do this step-by-step then gradually start to combine steps to put together a general tool:
LO := 1;
HI := 5;
steps to find F1 through F5
Good luck, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
As I re-read the original post the first phrase jumped out at me:
I subs (a^2=4b, expression)
subs and eval work best when the substitution is given in the form NAME=NEW_VALUE. For more complicated (algebraic) substitutions such as the one in your post, you should look at algsubs. See ?algsubs for details and examples. The similarly named trigsubs is completely different. See ?trigsubs for more information. I hope this is helpful, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
As I re-read the original post the first phrase jumped out at me:
I subs (a^2=4b, expression)
subs and eval work best when the substitution is given in the form NAME=NEW_VALUE. For more complicated (algebraic) substitutions such as the one in your post, you should look at algsubs. See ?algsubs for details and examples. The similarly named trigsubs is completely different. See ?trigsubs for more information. I hope this is helpful, Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
Enough! There is no reason for your repeated posting of the same question. You will get a response when people see your question. It's only now 8:00am in the Eastern US. Why is this so urgent? Is it something you were supposed to have done much earlier? Possibly something due at the end of your semester? I'm glad to help, but please respect this site and its regular visitors. Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
If you do not need your result to be used in anything else (purely visual), then you could use nprintf to create a more appealing output. Here's how this might look.
restart;
aa := [ [1,0,1,0], [1,1,0,0], [0,0,1,1] ]:
alias( a[1]=[1,0,1,0], a[2]=[1,1,0,0], a[3]=[0,0,1,1] ):
A := {aa[1],aa[2],aa[3]};
                             {a[1], a[2], a[3]}
MyAdd := (a,b)->a+b:
MyEqual := (a,b)->evalb(sort(a)=sort(b)):
EquivalenceClass := proc( A, BinOper, Equal )
  local b, B, s, S;
  S := combinat[choose](A,2);
  B := {};
  while S<>{} do
    for b in B do
      S := select( s->not Equal(BinOper(s[1],s[2]),BinOper(b[1],b[2])), S );
    end do;
    if S<>{} then B := B union {S[1]} end if;
  end do;
#  return B;                      # choose output format desired
#  return map( b->b[1]&+b[2], B );
  return map( b->nprintf("%a + %a",b[]), B );
end proc:
EquivalenceClass( A, MyAdd, MyEqual );
                         {a[1] + a[2], a[2] + a[3]}
Doug
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
First 55 56 57 58 59 60 61 Last Page 57 of 76