Group Abstract Group Abstract

Message Boards Message Boards

Solution of a quite long differential equation (Lagrange Equation)

Posted 9 years ago

Hello,

I want to solve the following Lagrange equation:

L[xp1_[t], xp2_, xe1_, xe2_] :=  1/2[mp1*xp1'[t]^2 + mp2*xp2'^2] - 1/2*k*[xp1[t] - xp2]^2 +  2 me1*Le1*[xp1[t] - cos[xe1]] xp1'[t] xe1' + me1*Le1*xe1'^2 +  1/2*[2*me2*Le2*[x2 - cos[xe2]]*x2'*xe2' + me2*Le2^2*xe2'^2]

with

Dt[D[L, xp1'[t]], t] - D[L, xp1[t]] == 0

here only for xp1(t). Later I want to solve it for all variables. Everytime I try to solve it it gives me 0 or true as a result, even when I trace the calculation I don´t get a satisfying result. I actually only want the final equation, which indeed should be very long.

Thanks in advance, Thimo

POSTED BY: Thimo Merkel
10 Replies
Posted 9 years ago

Works. Only one variable was wrong. And everything is completely different again in the programming. I have much to learn. Thanks a lot.

POSTED BY: Thimo Merkel

I tried to include all variables in one Lagrangian, changing the approach a bit:

lagrangian = 
  1/2 (mp1*xp1prime^2 + mp2*xp2prime^2) - 1/2 k (xp1 - xp2)^2 + 
   2 me1Le1 (xp1 - Cos[xe1]) xp1prime*xe1prime + me1Le1*xe1prime^2 + 
   1/2 ((2 me2Le2 (xp2[t] - Cos[xe2])) xp2prime xe2prime + 
      me2Le2^2 xe2prime^2);
vars = {xp1, xp2, xe1, xe2};
varsPrime = {xp1prime, xp2prime, xe1prime, xe2prime};
replacements = 
 Thread[Join[vars, varsPrime] -> {xp1[t], xp2[t], xe1[t], xe2[t], 
    xp1'[t], xp2'[t], xe1'[t], xe2'[t]}]
lagEq = D[D[lagrangian, {varsPrime}] /. replacements, 
    t] - (D[lagrangian, {vars}] /. replacements) == 0

Check the Lagrangian, please, because I may have misread your original formula.

POSTED BY: Gianluca Gorni
Posted 9 years ago

Ok, coming back to the original problem (post above is not relevant, only interesting for me in terms of learning mathematica). I did change the equation to the other variables according to what G.Gorni showed me.Here for example on xe2:

L[t_, xe2_, xe2prime_] = 1/2 (mp1*xp1'[t]^2 + mp2*xp2'[t]^2) - 1/2 k (xp1[t] - xp2[t])^2 + 2 me1Le1 (xp1[t] - Cos[xe1[t]]) xp1'*xe1'[t] + me1Le1*xe1'[t]^2 + 1/2 ((2 me2Le2 (xp2[t] - Cos[xe2])) xp2'[t] xe2prime +  me2Le2^2 xe2prime^2);

lagEq = D[D[L[t, xe2, xe2prime], xe2prime] /. {xe2 -> xe2[t], xe2prime -> xe2'[t]}, t] - (D[L[t, xe2, xe2prime], xp2] /. {xe2 -> xe2[t],      xe2prime -> xe2'[t]}) == 0

DSolveValue[lagEq /. {xp2 -> Identity, xe1 -> Identity, xp1 -> Identity}, xe2[t],t]

Obviously it does not work. It seems to me there is a probelm in the solution of the chain rule. However the output it generates seems to have no information value, while the error messages and the helpfunction do not lead me to a solution. If your cup of tea is already hot and you are bored of television, I would be pleased for any suggestions.

POSTED BY: Thimo Merkel
Posted 9 years ago

So I better do this for all variables xp2, xe1, xe2 and then it´s fine and I can add up the equations. This should work, I will do so. On the other hand I tried to calculate the equation for two more variables and it´s messed up again. Why can´t one justelongate the equation and fine? I don´t get it. Here is what I have done:

L[t_, xp1_, xp1prime_, xp2_, xp2prime_] =   1/2 (mp1*xp1prime^2 + mp2*xp2prime^2) - 1/2 k (xp1 - xp2)^2 +    2 me1Le1 (xp1 - Cos[xe1[t]]) xp1prime*xe1'[t] + me1Le1*xe1'[t]^2 +    1/2 ((2 me2Le2xe2 - Cos[xe2[t]]) x2'[t] xe2'[t] +      me2Le2^2 xe2'[t]^2);

lagEq = D[    D[L[t, xp1, xp1prime, xp2, xp2prime], xp1prime, xp2prime] /. {xp1 -> xp1[t], xp1prime -> xp1'[t], xp2 -> xp2[t],
       xp2prime -> xp2'[t]}, t] - (D[L[t, xp1, xp1prime, xp2, xp2prime], xp1, xp2] /. {xp1 -> xp1[t], xp1prime -> xp1'[t], xp2 -> xp2[t], 
      xp2prime -> xp2'[t]}) == 0

DSolveValue[lagEq /. {xe1 -> Identity, xe2 -> Identity}, xp1[t], xp2[t], t]
POSTED BY: Thimo Merkel
Posted 9 years ago

Is xp1[t] really the only generalized coordinate in the Lagrangian? Or are the other functions of t also coordinates of the motion? Can you write the complete Lagrangian in terms of all the coordinates and there derivatives, using Mathematica notation?

POSTED BY: David Keith

Here is an explanation: the Lagrangian L is defined in terms of plain symbols xp1 and xp1prime, so that you can take the derivative with respect to xp1 and xp1prime. After taking that derivative, you replace xp1 with xp1[t] and xp1prime with xp1'[t].

POSTED BY: Gianluca Gorni
Posted 9 years ago

That works very well. I don´t know yet what you have done, but I will look up the "cryptic" commands ;-). Thanks a lot.

POSTED BY: Thimo Merkel

Here is an attempt of mine at parsing your nonstandard syntax:

L[t_, xp1_, xp1prime_] = 
  1/2 (mp1*xp1prime^2 + mp2*xp2'[t]^2) - 1/2 k (xp1 - xp2[t])^2 + 
   2 me1Le1 (xp1 - Cos[xe1[t]]) xp1prime* xe1'[t] + 
   me1Le1*xe1'[t]^2 + 
   1/2 ((2 me2Le2x2 - Cos[xe2[t]]) x2'[t] xe2'[t] + 
      me2Le2^2 xe2'[t]^2);
lagEq = D[
    D[L[t, xp1, xp1prime], xp1prime] /. {xp1 -> xp1[t], 
      xp1prime -> xp1'[t]}, 
    t] - (D[L[t, xp1, xp1prime], xp1] /. {xp1 -> xp1[t], 
      xp1prime -> xp1'[t]}) == 0

Mathematica does not solve the equation in its general form, but it does if I specialize the functions xp2 and xe1:

DSolveValue[lagEq /. {xp2 -> Identity, xe1 -> Identity}, xp1[t], t]
POSTED BY: Gianluca Gorni
Posted 9 years ago

Thanks for the fast help, but the answer of mathematica is still not satisfying. Now it´s "true" instead of an equation, even if I put "trace" in front of the equation. Are my expectations wrong? Before I was only using Matlab and Maple for computer calculations... I would still be glad about any helpful comment.

POSTED BY: Thimo Merkel

Mathematica syntax uses square brackets [] to indicate the argument of functions, not to show the order of operations. Moreover, you cannot leave the derivatives xe1' without the [t]. Please check if this is what you meant:

1/2 (mp1*xp1'[t]^2 + mp2*xp2'[t]^2) - 1/2 k (xp1[t] - xp2[t])^2 + 
 2 me1Le1 (xp1[t] - Cos[xe1[t]]) xp1'[t] xe1'[t] + me1Le1*xe1'[t]^2 + 
 1/2 ((2 me2Le2x2 - Cos[xe2[t]]) x2'[t] xe2'[t] + me2Le2^2 xe2'[t]^2)
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard