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

Great question. Please do ask it.

You will get the best responses, though, if you post this as a new forum topic/question.

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

One consequence of this change is that our original posts describing the incorrect handling now appear fine.

This is not a (serious) complaint. I do find it interesting in light of the ongoing requests for an ability to edit posts after replies have been posted. It's exactly this loss of accurate reflection of the exchange that makes me question the sensibility of allowing edits after a reply has been posted.

Thank you for this improvement to the community.

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

Ternox,

Here is one approach that, I think, does what you want. I did not make many changes to your code. There are other ways to initialize your arrays of functions, but I did not mess with this. I did replace sum with add in the definition of U[j]. This could be a little faster, and is more appropriate (since there is no hope of finding a closed expression for these sums).

restart;
N := 2:
X[1] := 0: L[0] := 0: X[0] := 0: Y[0] := 0:

for j to N do
  X[j] := X[j-1]+L[j-1]*sin(Theta[j-1](t)):
  Y[j] := Y[j-1]+L[j-1]*cos(Theta[j-1](t)):
end do:
for i to N do
  X[i] := X[i]+S[i]*(sin(Theta[i]))(t)-e[i]*cos(Theta[i](t)):
  Y[i] := Y[i]+S[i]*(cos(Theta[i]))(t)+e[i]*sin(Theta[i](t)):
  Xp[i] := diff(X[i], t):
  Yp[i] := diff(Y[i], t):
  V[i] := factor(combine(Xp[i]^2+Yp[i]^2)):
  T[i] := (1/2)*M[i]*V[i]
end do:
for i to N do
  for j to N do
    TiDDThetaj[i, j] := frontend(diff, [T[i], diff(Theta[j](t), t)]):
  end do;
end do:

I created a proc (MyApprox) that uses algsubs to implement the simplifications you have described. For N=2 there is just one simplification and for N=2 there are 3 ([1,2], [1,3], and [2,3]). It seems that the most appropriate time to apply this approximation is before computing the time derivative of each U:
MyApprox := proc( A, N )
  local AA, i, j;
  AA := A;
  for i to N do
    for j from i+1 to N do
      AA := algsubs( Theta[i](t)-Theta[j](t)=0, AA );
    end do;
  end do;
  return AA
end proc:

for j to N do
  U[j] := MyApprox( add(TiDDThetaj[c, j], c = 1 .. N), N ):
  DS[j] := diff(U[j], t);
end do;

To finish, I simplified the substitutions for the second derivatives and streamlined the construction of your final matrix:

for j to N do
  ZZZ[j] := seq( diff(Theta[i](t),t,t)=`if`(i=j,1,0), i=1..N );
end do:
AAA := Matrix( N, N, (i,j)->collect( subs(ZZZ[j],DS[i]), diff(Theta[j](t), t,t) ) );

This seems to be working for both N=2 and N=3, giving the same matrix as your code did (after changing SS to DS in the defintion of SSSimplified in your code).

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

Ternox,

Here is one approach that, I think, does what you want. I did not make many changes to your code. There are other ways to initialize your arrays of functions, but I did not mess with this. I did replace sum with add in the definition of U[j]. This could be a little faster, and is more appropriate (since there is no hope of finding a closed expression for these sums).

restart;
N := 2:
X[1] := 0: L[0] := 0: X[0] := 0: Y[0] := 0:

for j to N do
  X[j] := X[j-1]+L[j-1]*sin(Theta[j-1](t)):
  Y[j] := Y[j-1]+L[j-1]*cos(Theta[j-1](t)):
end do:
for i to N do
  X[i] := X[i]+S[i]*(sin(Theta[i]))(t)-e[i]*cos(Theta[i](t)):
  Y[i] := Y[i]+S[i]*(cos(Theta[i]))(t)+e[i]*sin(Theta[i](t)):
  Xp[i] := diff(X[i], t):
  Yp[i] := diff(Y[i], t):
  V[i] := factor(combine(Xp[i]^2+Yp[i]^2)):
  T[i] := (1/2)*M[i]*V[i]
end do:
for i to N do
  for j to N do
    TiDDThetaj[i, j] := frontend(diff, [T[i], diff(Theta[j](t), t)]):
  end do;
end do:

I created a proc (MyApprox) that uses algsubs to implement the simplifications you have described. For N=2 there is just one simplification and for N=2 there are 3 ([1,2], [1,3], and [2,3]). It seems that the most appropriate time to apply this approximation is before computing the time derivative of each U:
MyApprox := proc( A, N )
  local AA, i, j;
  AA := A;
  for i to N do
    for j from i+1 to N do
      AA := algsubs( Theta[i](t)-Theta[j](t)=0, AA );
    end do;
  end do;
  return AA
end proc:

for j to N do
  U[j] := MyApprox( add(TiDDThetaj[c, j], c = 1 .. N), N ):
  DS[j] := diff(U[j], t);
end do;

To finish, I simplified the substitutions for the second derivatives and streamlined the construction of your final matrix:

for j to N do
  ZZZ[j] := seq( diff(Theta[i](t),t,t)=`if`(i=j,1,0), i=1..N );
end do:
AAA := Matrix( N, N, (i,j)->collect( subs(ZZZ[j],DS[i]), diff(Theta[j](t), t,t) ) );

This seems to be working for both N=2 and N=3, giving the same matrix as your code did (after changing SS to DS in the defintion of SSSimplified in your code).

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

This is a start, but more information is needed. Can you provide some explicit details about your "iterative procedure"? How were you saving the solution? Were you trying to write to a file? If so, did the file already exist or was it a new file? Which command(s) for writing to a file did you use?

???

As Scott originally requested, a sample worksheet would be very helpful. Short of that, we do need more information before we can fully diagnose your problem.

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

This is a start, but more information is needed. Can you provide some explicit details about your "iterative procedure"? How were you saving the solution? Were you trying to write to a file? If so, did the file already exist or was it a new file? Which command(s) for writing to a file did you use?

???

As Scott originally requested, a sample worksheet would be very helpful. Short of that, we do need more information before we can fully diagnose your problem.

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

Before I head off on a tangent, let me ask if you are sure you need to know the index of the negative elements. I know I used to think this way (based on my experiences with other programming languages). I find that Maple allows me to think more mathematically about an algorithm. I find myself  using select and remove (and selectremove) to extract the desired elements and to process them accordingly. In your case, this would start with:

L := [1, 2, 3, 4, 5, 6, 7, 8, 9, -5, -.2]:
select( is, L, negative );
                                 [-5, -0.2]

Now the promised tangent.

It would be nice if ListTools:-SearchAll accepted search criteria other than an exact match. What I have in mind is something along the lines of select and remove (see ?select), and Select and Remove in StringTools  (see ?StringTools).

More generally, while packages like ListTools and StringTools are useful, they are missing many commands that would make them even more useful. For example, why is there not a Catenate or Zip? These are easily done by other means, but these are natural operations that should be covered by ListTools. (I note that LinearAlgebra does have a Zip command.)

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

Before I head off on a tangent, let me ask if you are sure you need to know the index of the negative elements. I know I used to think this way (based on my experiences with other programming languages). I find that Maple allows me to think more mathematically about an algorithm. I find myself  using select and remove (and selectremove) to extract the desired elements and to process them accordingly. In your case, this would start with:

L := [1, 2, 3, 4, 5, 6, 7, 8, 9, -5, -.2]:
select( is, L, negative );
                                 [-5, -0.2]

Now the promised tangent.

It would be nice if ListTools:-SearchAll accepted search criteria other than an exact match. What I have in mind is something along the lines of select and remove (see ?select), and Select and Remove in StringTools  (see ?StringTools).

More generally, while packages like ListTools and StringTools are useful, they are missing many commands that would make them even more useful. For example, why is there not a Catenate or Zip? These are easily done by other means, but these are natural operations that should be covered by ListTools. (I note that LinearAlgebra does have a Zip command.)

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

Paulina,

Thank you for this clarification and update. I will be eager to see these improvements, and stand available to provide my opinions and other feedback if that would be 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

If you really want to replace ALL sin's by 0 and ALL cos's by 1, then you can just use:

A:=(1/2)*M[2]*(-2*L[1]*(diff(Theta[1](t), t, t))*e[2]*sin(Theta[1](t)-Theta[2](t))-2*L[1]*(diff(Theta[1](t), t))*e[2]*cos(Theta[1](t)-Theta[2](t))*(diff(Theta[1](t), t)-(diff(Theta[2](t), t)))+2*S[2]*(diff((sin(Theta[2]))(t), t, t))*e[2]*sin(Theta[2](t))+2*S[2]*(diff((sin(Theta[2]))(t), t))*e[2]*cos(Theta[2](t))*(diff(Theta[2](t), t))+2*e[2]^2*(diff(Theta[2](t), t, t))+2*S[2]*(diff((cos(Theta[2]))(t), t, t))*e[2]*cos(Theta[2](t))-2*S[2]*(diff((cos(Theta[2]))(t), t))*e[2]*sin(Theta[2](t))*(diff(Theta[2](t), t))):
A0 := eval( A, [sin=0,cos=1] );
1      /        / d             \      // d             \   / d             \\
- M[2] |-2 L[1] |--- Theta[1](t)| e[2] ||--- Theta[1](t)| - |--- Theta[2](t)||
2      \        \ dt            /      \\ dt            /   \ dt            //

           2 / d  / d             \\\
   + 2 e[2]  |--- |--- Theta[2](t)|||
             \ dt \ dt            ///

This works because Maple treats constants as constant functions. That is 3(anything)=3 and so this command tells Maple to replace sin(anything) with 0(anything) which is just 0 and cos(anything) = 1(anything) = 1. (If you are using 2d math input, be sure you don't leave a space between the function name and its arguments. If Maple sees a space there it will be interpreted as multiplication, for example: 1 (anything) = anything.)

But, if you intend to simplify only some of the sin and cos to 0 and 1, then there is more work to be done. Can you tell us exactly which terms you want to keep? Maybe it would be easier to do by modifying the process by which you arrived at the equation you call A.

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

If you really want to replace ALL sin's by 0 and ALL cos's by 1, then you can just use:

A:=(1/2)*M[2]*(-2*L[1]*(diff(Theta[1](t), t, t))*e[2]*sin(Theta[1](t)-Theta[2](t))-2*L[1]*(diff(Theta[1](t), t))*e[2]*cos(Theta[1](t)-Theta[2](t))*(diff(Theta[1](t), t)-(diff(Theta[2](t), t)))+2*S[2]*(diff((sin(Theta[2]))(t), t, t))*e[2]*sin(Theta[2](t))+2*S[2]*(diff((sin(Theta[2]))(t), t))*e[2]*cos(Theta[2](t))*(diff(Theta[2](t), t))+2*e[2]^2*(diff(Theta[2](t), t, t))+2*S[2]*(diff((cos(Theta[2]))(t), t, t))*e[2]*cos(Theta[2](t))-2*S[2]*(diff((cos(Theta[2]))(t), t))*e[2]*sin(Theta[2](t))*(diff(Theta[2](t), t))):
A0 := eval( A, [sin=0,cos=1] );
1      /        / d             \      // d             \   / d             \\
- M[2] |-2 L[1] |--- Theta[1](t)| e[2] ||--- Theta[1](t)| - |--- Theta[2](t)||
2      \        \ dt            /      \\ dt            /   \ dt            //

           2 / d  / d             \\\
   + 2 e[2]  |--- |--- Theta[2](t)|||
             \ dt \ dt            ///

This works because Maple treats constants as constant functions. That is 3(anything)=3 and so this command tells Maple to replace sin(anything) with 0(anything) which is just 0 and cos(anything) = 1(anything) = 1. (If you are using 2d math input, be sure you don't leave a space between the function name and its arguments. If Maple sees a space there it will be interpreted as multiplication, for example: 1 (anything) = anything.)

But, if you intend to simplify only some of the sin and cos to 0 and 1, then there is more work to be done. Can you tell us exactly which terms you want to keep? Maybe it would be easier to do by modifying the process by which you arrived at the equation you call A.

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

I agree with Laurent's summary. As a member of the set of "experienced users", I do admit that it is nice to have the ability to use 2d math when the situation calls for it. My request is not for one mode to conquer the other and become "the" input mode. In fact,I would like to see both modes prosper.

One step towards this would be to have the two parsers implement the same language.

Is there a fundamental reason why this cannot be achieved?

Are there any reasons why this would not be a benefit to all users?

As I prepared an example to illustrate my point, I discovered that the differece might not be in 1d vs 2d input. Rather, it appears that there are different parsers for worksheets and documents. If this is the case, then I need to modify my original request. Still, I would like to see all (reasonable) input strings treated the same way.

Here's my simple example. Note there is a space between the n and the left parenthesis. In a document, this is interpretted as sin * x. This error, or ones equivalent to it, have tripped up many new users (in document mode).

Input        Output Worksheet    Output Document   Comment
sin(x);           sin(x)              sin(x)       both systems see parens as function eval
sin (x);          sin(x)              sin x        worksheet eats the blank space; document treats as *

3(x);               3                  3 x         worksheet sees a function eval; document treats as *
3 (x);              3                  3 x         extra space does not change how either parser treats input
3 x;              Error                3 x         full error message is "Error, missing operator or `;`"

(x+2) (x-2);   x(x - 2) + 2         (x+2)(x-2)     worksheet see 2nd parens as function eval; document as *
(x+2)(x-2);    x(x - 2) + 2         x(x-2) + 2     both systems see 2nd parens as function eval

3(x+2) (x-2)        3              3(x+2)(x-2)     this is a combination of the two previous examples

It's my belief that both output columns should be the same. I can live with either interpretation, but really struggle to explain why the output depends on the exact mode in which Maple is being used. (I can't call these two different dialogues. The meanings are totally different; they are different languages.)

My thoughts and ideas. I'm happy to hear conflicting points of view. This old Doug can is always eager to learn new tricks.

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

 

Me too!

I hope there are more installments to come. I have some projects that could utilize threads. I am just waiting for time to be able to put these ideas into play.

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

The automatic insertion of links to the online Maple help webpages is nice. But, it's not yet perfect.

In a post I made yesterday I included ?sum and ?add on the same line of the post. The hyperlink was added to only the second reference to Maple help. (If I am correct about this, the same thing will be true in this message.)

Just now I read a post that included a hyperlink that included a question mark. The automatic hyperlink that was created was meaningless (and possibly interferred with an intended hyperlink to uploaded content).

I hope these problems can be resolved. Having this functionality is very nice, but it needs to work as advertised.

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

The discussion continues in the different parsers [new topic] topic.

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
First 17 18 19 20 21 22 23 Last Page 19 of 76