Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am using Mathematica to get the Equations of Motion (EOM) for a mechanical system (using Lagrangian Mechanics). While I get the EOM in symbolic form, on introducing the following code for assigning numerical values to constants, the resulting EOMs of the system end up having complex coefficients.

Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]];

(*Segment C*)
Subscript[ρ, Al] = 2.7;   (*Density of Aluminium 6061 in g/cc*)
Subscript[ρ, MS] = 7.85; (*Density of Mild Steel in g/cc*)
Subscript[ρ, Fl] = 0.9;  (*Density of hyraulic fluid in g/cc*)

Subscript[r, C1] = 0.5;
Subscript[l, C1] = 4.2;
Subscript[r, C2] = 2;
Subscript[t, C2] = 0.25;
Subscript[l, C2] = 16.4;
Subscript[l, C3B] = 17.8;
Subscript[r, C3Bouter] = 1;
Subscript[r, C3Binner] = 0.45;
Subscript[r, C3s] = 2;
Subscript[l, C3s] = 0.6;
Subscript[l, C2f] = Subscript[l, C2] - Subscript[l, C3s];

Subscript[m, C1] = Subscript[l, C1] Subscript[ρ, Al] 
\!\(\*SubsuperscriptBox[\(r\), \(C1\), \(2\)]\) N[π];
Subscript[m, C3s] = Subscript[l, C3s] Subscript[ρ, MS] 
\!\(\*SubsuperscriptBox[\(r\), \(C3s\), \(2\)]\) N[π];
Subscript[m, C3B] = Subscript[l, C3B] Subscript[ρ, MS] (\!\(
\*SubsuperscriptBox[\(r\), \(C3Bouter\), \(2\)] - 
\*SubsuperscriptBox[\(r\), \(C3Binner\), \(2\)]\)) N[π];
Subscript[m, C2s] = Subscript[l, C2] Subscript[ρ, Al] ((Subscript[r, C2] + Subscript[t, C2])^2 -\!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\)) N[π];
Subscript[m, C2f] = Subscript[l, C2f] Subscript[ρ, Fl] \!\(\*SubsuperscriptBox[\(r\), \(C2\), \(2\)]\) N[π];
Subscript[m, C3] = Subscript[m, C3B] + Subscript[m, C3s];
Subscript[m, C] =  Subscript[m, C1] + Subscript[m, C2f] + Subscript[m, C2s] + Subscript[m, C3];

(*Segment B*)
Subscript[λ, P5] = 4.8; (*Linear mass density of Profile 5 \bars in g/cm*)
Subscript[b, B1] = 2;
Subscript[b, B2] = 4.367;
Subscript[l, B2] = 1.5;
Subscript[l, B1] = 32;
Subscript[l, B4] = 23.8;
Subscript[b, B4] = Subscript[b, B1];
Subscript[b, B3] = 8;
Subscript[l, B3] = 4;
Subscript[l, B] = 9.2;
Subscript[t, B2] = Subscript[b, B1];
Subscript[t, B3] = Subscript[b, B1];

Subscript[m, B1] = Subscript[λ, P5] Subscript[l, B1];
Subscript[m, B2] = Subscript[b, B2] Subscript[l, B2] Subscript[ρ, MS] Subscript[t, B2];
Subscript[m, B3] = Subscript[b, B3] Subscript[l, B3] Subscript[ρ, MS] Subscript[t,
Subscript[m, B4] = Subscript[λ, P5] Subscript[l, B4];
Subscript[m, B] = Subscript[m, B1] + Subscript[m, B2] + Subscript[m, B3] + Subscript[m, B4];

(*Segment D*)
Subscript[l, D1] = 36.8;
Subscript[b, D1] = 3;
Subscript[b, D2] = 6.8;
Subscript[l, D2] = 4;
Subscript[t, D2] = Subscript[b, B1];
Subscript[m, D1] = Subscript[λ, P5] Subscript[l, D1];
Subscript[m, D2] = Subscript[b, D2] Subscript[l, D2] Subscript[ρ, MS] Subscript[t,
Subscript[m, D] = Subscript[m, D1] + Subscript[m, D2];

(*Segment E*)
Subscript[l, E] = 75;
Subscript[b, E] = 22;
Subscript[m, E] = 50000; (*50 kg = 50,000 g*)

(*Terms used in the displacement constraints*)
Subscript[l, GB] = Subscript[l, B]/2;
Subscript[h, B] = Subscript[b, B1] + Subscript[b, B3] + Subscript[b, B4];
Subscript[h, GB] = Subscript[h, B]/2;
Subscript[l, GD] = Subscript[l, D1]/2;  
Subscript[h, GD] = Subscript[b, D2]/2;
Subscript[l, GE] = Subscript[l, E]/2;
Subscript[l, D] = Subscript[l, D1];
α = 0.5;
Subscript[l, BL] = 2;
Subscript[h, BL] = Subscript[b, B2];
Subscript[l, DU] = 6;
Subscript[h, DU] = Subscript[b, D2];
g = 981; (*cm/sec^2*)
c = 3 10^7; (*3*10^4 is the average damping coefficient whilst using \kg and m*)
Subscript[W, g] = 15000 g;
Subscript[T, H] = 5*10^7; (*5 N-m = 5*10^7 when g and cm is employed instead of kg \and m*)
Subscript[T, K] = 5*10^7;

I guess I have made some mistake in this assignment due to which 'iota' somehow creeps into my resultant equations, but I am not able to figure out where the mistake is.

share|improve this question
Please have a look at What are the most common pitfalls awaiting new users –  Jens Jul 20 '13 at 21:55
Consider that the expression you assign to Subscript[m, C1] evaluates to 35.6257 \!(*SubsuperscriptBox[(r), (C1), (2)]). Is that what you expected? Or did you expect a numerical value? Basically, I see your problem as being that not all your assignments to your constants produce actual numerical values. –  m_goldberg Jul 21 '13 at 1:03
Thanks for the tips. @m_goldberg, I tried accessing all these values in the output by removing the semi-colon at the end, and all outputs were numbers. Even if I replace these symbols from their subscript form by a normal form (eg. replacing Subscript[m, C1] by mC1) and evaluate the code, the output is still yielding complex values. Maybe the problem lies elsewhere in the code. Here is the complete code –  electech Jul 21 '13 at 18:16
@Nasser I copied the first three lines (for clearing the variables and symbolizing subscript terms) from a post in stackexchange. Everything else is manually typed in. It works fine on my system though. I'm not sure why this output is showing up on yours! –  electech Jul 25 '13 at 23:37
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.