I am new to this website and Mathematica, but I have a problem with partial derivatives. What i am trying to do is get the Lagrangian equation of my system using x,y coordinates. The problem is i think in the last part with T,L1,L2,L3 and L. The code is given here:

Clear[m, \[Alpha], \[Beta], l1, x, l3, l4, l5, L1, L2, L3, L, r]
n = 12;
l2 = 1;
m = 1;

f[\[Theta]_] := {\[Theta], 0, 2*Pi}
\[Alpha] = \[Alpha] /. Solve[(Pi - \[Alpha])*n == 2*Pi];
\[Beta] = (Pi - \[Alpha])/2;
l1 = 2*(Cos[\[Beta] ]/l2);
l3 = (l1*Cos[\[Beta] + \[Theta]])/Cos[Pi - \[Alpha]];
l4 = (l2*Cos[\[Theta]])/Cos[1/2*(Pi - \[Alpha])];
(*The calculation of the x coordinate of the whole system*)
For[i = 1, i <= n, i++ , x[i] = l3*Cos[((i - 1)*(Pi - \[Alpha]))];]
For[i = n + 1, i <= 2*n, i++ , 
 x[i] = l4*Cos[((i - 1/2)*(Pi - \[Alpha]))]]
l5 = l3 + 2*x[n + 1];
For[i = 2*n + 1, i <= 3*n, i++ , 
 x[i] = l5*Cos[((i - 1)*(Pi - \[Alpha]))]]

(*The calculation of the y coordinate of the whole system*)
For[i = 1, i <= n, i++ , y[i] = l3*Sin[((i - 1)*(Pi - \[Alpha]))]];
For[i = n + 1, i <= 2*n, i++ , 
  y[i] = l4*Sin[((i - 1/2)*(Pi - \[Alpha]))]];
For[i = 2*n + 1, i <= 3*n, i++ , 
  y[i] = l5*Sin[((i - 1)*(Pi - \[Alpha]))]];

(*The calculation of the velocity, the v here is v^2*)
For[i = 1, i <= 3*n, i++, v[i] = Dt[x[i]]^2 + Dt[y[i]]^2]

T = Simplify[Sum[1/2 m*Simplify[v[i]], {i, n*3}]];
L1 = Simplify[D[T, Dt[\[Theta]]]];
L2 = Dt[L1]
L3 = Simplify[[D[T, \[Theta]]]]
L = L2 - L3;

The answer is: enter image description here

The problem is that the derivative of Dt[\[Theta]] should be a constant when deriving a derivative only with respect to \[Theta]. Furthermore, why is the r in D[T, \[Theta]] lighter blue than the \[Theta] at L3 = Simplify[[D[T, \[Theta]]]]?

The simplified example is given beneath:

f[r_] := {r, 0, 2*Pi}
a = r;
b = r^2;
F = a^2 + b^2;
F1 = Dt[F];
D[F1, r]

Where the answer is: 2 r !(*SubscriptBox[([PartialD]), (r)](Dt[r])) + 4 r^3 !(*SubscriptBox[([PartialD]), (r)](Dt[r])) + 2 Dt[r] + 12 r^2 Dt[r]

  • $\begingroup$ I think that Dt[r] is not a constant because Mathematica doesn't know what "r" is. Indeed, r could also be a function of some other variable. The fact that in a=r the r is blue it's because that's an undefined variable in the notebook, while in D[F1,r] "r" is an argument of the function. $\endgroup$ – Fraccalo May 23 '18 at 13:28
  • $\begingroup$ In my problem r should be a variable that will very between 0 and 2pi. If i add this: f[r_] := {r, 0, 2*Pi} It still doesn't work. $\endgroup$ – Rik Koppelman May 23 '18 at 13:46
  • $\begingroup$ Please do not post images of your work. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. This will make it easier to reproduce your problem and to experiment with possible solutions. $\endgroup$ – m_goldberg May 23 '18 at 14:24
  • $\begingroup$ @m_goldberg. I've added the code itself to the problem $\endgroup$ – Rik Koppelman May 23 '18 at 14:39
  • $\begingroup$ I have a feeling that your code does not express what you are after (even if with errors), but something else. It may be a good idea, if you first write the expression you want to calculate in traditional mathematical notations. Than we will probably understand what's wrong with the Mathematica code. $\endgroup$ – Alexei Boulbitch May 23 '18 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.