1

I'm 16 and I'm pretty new to Mathematica. I've been working on a personal coding project which has some funky maths in it and I am kinda struggling. I've solved for the 4 polynomials but they answers are rather long and complex. I was wondering if anyone could help me simplify these (if they can be simplified that is). I tried using Simplify[%] but it didn't work for me.

Here's my code so far:

vars = {theta1'', phi1'', theta2'', phi2''}
sys = {2 l1 (Cos[theta1] theta1' phi1' + Sin[theta1] phi1'') + 
    l1 (Sin[theta2] Sin[phi1 - phi2] (theta2')^2 + 
       2 Cos[theta2] Cos[phi1 - phi2] theta2' phi2' + 
       Sin[theta2] Sin[phi1 - phi2] (phi2')^2 - 
       Cos[theta2] Sin[phi1 - phi2] theta2'' + 
       Cos[phi1 - phi2] Sin[theta2] phi2'') == 0, 
  l1 (-Sin[theta1] Sin[phi1 - phi2] (theta1')^2 + 
       2 Cos[theta1] Cos[phi1 - phi2] theta1' phi1' - 
       Sin[theta1] Sin[phi1 - phi2] (phi1')^2 + 
       Cos[theta1] Sin[phi1 - phi2] (theta1'')^2 + 
       Cos[phi1 - phi2] Sin[theta1] phi1'') + 
    l2 (2 Cos[theta2] theta2' phi2' + Sin[theta2] phi2'') == 0, 
  l1 (Sin[2 theta1] (theta1')^2 + 
       2 Sin[2 theta1] (phi1')^2 - (3 + Cos[2 theta1]) theta1'') + 
    2 (g Sin[theta1] + 
       Cos[theta1] l2 (Cos[phi1 - phi2] Sin[theta2] (theta2')^2 - 
          2*Cos[theta2] Sin[phi1 - phi2] theta2' phi2' + 
          Cos[phi1 - phi2] Sin[theta2] (phi2')^2 - 
          Cos[theta2] Cos[phi1 - phi2] theta2'' - 
          Sin[theta2] Sin[phi1 - phi2] phi2'')) == 0, 
  g Sin[theta2] + (1/2) l2 (Sin[2 theta2] (phi2')^2 - 2 theta2'') + 
    Cos[theta2] l1 (Cos[phi1 - phi2] Sin[theta1] (theta1')^2 + 
       2 Cos[theta1] Sin[phi1 - phi2] theta1' phi1' + 
       Cos[phi1 - phi2] Sin[theta1] (phi1')^2 - 
       Cos[theta1] Cos[phi1 - phi2] theta1'' + 
       Sin[theta1] Sin[phi1 - phi2] phi1'') == 0}

sol = NSolve[sys, vars]

sorry the equations are so long :)

also of there is any easier way to do this it would be greatly appreciated.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • 1
    ' is usually used to denote a derivative in Mathematica, so I would highly suggest avoiding them in your variables. – J. M.'s missing motivation May 04 '20 at 12:31
  • but they are derivatives of the variable. Sorry i'm really new i don't really understand the syntax, should I replace the variable names? with something along the lines of theta1_dd or theta1_d ??? – Samuel Cobb May 04 '20 at 12:36
  • 1
    _ is used for pattern matching (e.g. f[x_] := Sin[x]), so that's out too. I now notice that you have parameters like l1, l2, and g that do not have numerical values assigned to them, so NSolve[] (which is intended for numerical solutions) is definitely not going to succeed here. – J. M.'s missing motivation May 04 '20 at 12:39
  • I'm just trying to solve for the values like this: θ1'' = −g (2 m1 + m2) sin θ1 − m2 g sin(θ1 − 2 θ2) − 2 sin(θ1 − θ2) m2 (θ2'2 L2 + θ1'2 L1 cos(θ1 − θ2)) / L1 (2 m1 + m2 − m2 cos(2 θ1 − 2 θ2)) This solves for the second derivative of theta in a 2d double pendulum. My project is a 3d double spherical pendulum. Would it be OK to solve for something like this? – Samuel Cobb May 04 '20 at 12:43
  • here is the link I got that from: https://myphysicslab.com/pendulum/double-pendulum-en.html its at the bottom. Also, could I put something like thetaD or thetaDD? sorry for so many questions i'm very inexperienced :| – Samuel Cobb May 04 '20 at 12:50
  • Is there an algebraic solution then instead of a numerical solution? – Samuel Cobb May 04 '20 at 13:30
  • vars /. Solve[sys, vars] seems to work. The solutions are really unwieldy. – Suba Thomas May 04 '20 at 15:04
  • 2
    The double pendulum is a set of differential equations, so Solve[]/NSolve[] aren't appropriate. You want NDSolve[] for this, after specifying numerical values for the parameters. Have you seen this and this? – J. M.'s missing motivation May 04 '20 at 15:06
  • Wow, Thanks for the help w/ NDSolve dude, I didn't see those posts because I wasn't really searching for how to solve for those equations because those are in 2d, whereas i'm trying 3d. Thanks a bunch tho :))) So should NDSolve be in the most simplified form as well? – Samuel Cobb May 04 '20 at 23:56
  • How to I use NDSolve dude, I'm rather confused. I have the system of equations and the variables I need to solve for but I need a 3rd thing (the time) which I haven't implemented. How do you implement the t value or whatever that I've seen? – Samuel Cobb May 05 '20 at 06:53
  • The examples in the given links ought to be easily adaptable to your case. You only need to put in the equations and initial conditions in NDSolve[], as well as the functions to solve for, and the time interval you are considering. I would suggest (in general, not just for this problem) always making yourself familiar with simpler versions of your actual problem, before tackling the one of concern. In your specific situation, understand the 2D case well, so you can easily adapt to 3D. – J. M.'s missing motivation May 13 '20 at 01:07
  • I understand the 2d maths as a whole, but in most examples, the equation for the second time derivative is solved for. I have a working simulation already, which I can just set the velocity to a constant. I just need to solve for the second time derivative – Samuel Cobb May 13 '20 at 01:12
  • Here is the link i used: https://www.assignmentexpert.com/homework-answers/physics-answer-69717.pdf. could you help me as to identify which equations and which functions to use. – Samuel Cobb May 13 '20 at 01:15
  • @SamuelCobb have you tried implementing NDSolve[] on a simpler version of the problem, e.g. 2D as suggested by J.M? Even if you are given a solution where the differential equations are already analytically solved, you can use NDSolve to solve them numerically. As for the link you showed, what you want to put into NDSolve are your equations of motions, that is, the four equations that you get by solving the Euler-Lagrange equation. I had a quick look and it seems you have the correct equations in your Question here. – a20 May 13 '20 at 10:41

0 Answers0