0
$\begingroup$

I'm writing a function and when I execute it, I get a message saying:

... function has no opening ].

If I remove the right square bracket, I get a message saying:

... needs more input

Here is my code:

PlaneTrussElement[e_, A_, {{x1_, y1_}, {x2_, y2_}}] := 
  Module[{ls, ms, L}, 
    L = Sqrt[(x2 - x1)^2 + (y2 - y1)^2];
    ls = (x2 - x1)/L;
    ms = (y2 - y1)/L;
    e A/L {{ls^2, ls ms, -ls^2, -ls ms}, 
           {ls ms, ms^2, -ls ms, -ms^2}, 
           {-ls^2, -ls ms, ls^2, ls ms}, 
           {-ls ms, -ms^2, ls ms, ms^2}}]

PlaneTrussElement[29000000, 1.73, {{-60, 420}, {-180, 480}}]

When I execute the code, it won't return a matrix.

How do I solve my problem?

$\endgroup$
  • $\begingroup$ Your code works for me. Try starting with Clear["Global`*"] or start with a fresh kernel. $\endgroup$ – Bob Hanlon Sep 22 '19 at 23:08
  • $\begingroup$ @BobHanlon Thank You. It worked $\endgroup$ – jarvisstark Sep 22 '19 at 23:23
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because no one can reproduce the problem the OP is experiencing; I suspect it is being caused by corrupted lexical elements in the OP's Mathematica notebook. $\endgroup$ – m_goldberg Sep 23 '19 at 1:47
0
$\begingroup$

Your code works fine for me, but you can get a more concise formulation by writing it like so:

Clear[PlaneTrussElement]
PlaneTrussElement[e_, A_, {p1 : {_, _}, p2 : {_, _}}] := 
  Module[{ls, ms, L},
    L = Norm[p2 - p1];
    {ls, ms} = Normalize[p2 - p1];
    e A/L {{ls^2, ls ms, -ls^2, -ls ms}, 
           {ls ms, ms^2, -ls ms, -ms^2},
           {-ls^2, -ls ms, ls^2, ls ms},
           {-ls ms, -ms^2, ls ms, ms^2}}]

Test example

PlaneTrussElement[29000000, 1.73, {{-60, 420}, {-180, 480}}]
{{299156., -149578., -299156., 149578.}, 
 {-149578., 74789., 149578., -74789.}, 
 {-299156., 149578., 299156., -149578.}, 
 {149578., -74789., -149578., 74789.}}
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.