I'm creating a structural engineering program. It's a frame analysis program that computes the shear and moment diagrams. The frame is subjected to 2 kinds of distributed loads(only the beams(horizontal lines) were loaded): Dead load that doesn't move and a live load that change in position. In order to create the moment envelope( maximum and minimum moments at a point) I have to consider all the load patterns, which means I have to vary the live load positions and I have to consider all the positions. Here's a picture of the frame. .

And below is a picture of one of the many load patterns. First the frame is analysed without the loads values, each beam was loaded with a variable w[i] (w on the member 10 in the figure1 for an example etc...). The system is then solved and the moment values were obtained as a function of w[i] with i going from 1 to 4.

Now in order to find the maximum values of the moments for all the possible loadings I used the Tuples function:

d = DeadLoad;
pattern = Tuples[{d, d + l}, floors*spans];
patternCounter = Count[pattern, List_];


The next step was to replace the w[i] for each member with each pattern. And use the Max function to find the maximum moment.

>     BeamMid[k_] :=
>       Max[Table[{w[i] = pattern[[j]][[i]]; MemberTotalForces[k][]}, {j,
>           1, patternCounter}, {i, 1, floors*spans}]];


MemberTotalForces[k][] was obtained from the frame analysis and is a function of w[i] with i going from 1 to 4.

The problem I'm facing is time. For a 2 by 2 frame there are only 16 load patterns. For the frame in the picture below there are 65536 load patterns. And the process takes too long. Is there anyway to make the process faster?

• It looks like you are calling MemberTotalForces many times. Assuming that's the speed bottleneck, have you tried compiling this function? – bill s Feb 10 '15 at 15:07
• @bills Compiling wouldn't work since the function has variables w[i] with i going from 1 to the number of beams. Here's MemberTotalForces[] from the first figure: 409.983 + 4.04673 w + 0.120798 w + 0.00359441 w - 0.0712942 w – Mr. Pi Feb 10 '15 at 17:53

This problem is linear: that is, the moment due to a distribution of forces is equal to the sum of the moments due to the forces individually. A faster approach may be to calculate for each beam which force creates a more positive or more negative moment. Your final distribution will be the combination of each individually calculated force.

In other words, instead of looking at the patterns

{d, ... d, d, d}
{d, ... d, d, t}
{d, ... d, t, d}
.
. (2^n)
.
{t, ... t, t, d}
{t, ... t, t, t}


(where t = d+l) And choosing the max, look at the pairs of patterns

{0, ... 0, 0, d}  {0, ... 0, 0, t}
{0, ... 0, d, 0}  {0, ... 0, t, 0}
{0, ... d, 0, 0}  {0, ... t, 0, 0}
.
. (n)
.
{d, ... 0, 0, 0}  {t, ... 0, 0, 0}


Choose the maximum resultant from each, and then add each of the maxima together.

This solution is $O(n)$ instead of $O(2^n)$, so you shouldn't have any speed issues.

• d is always there so actually the patterns are of this kind: {d, ... d, d, d} {d, ... d, d, d+l} {d, ... d, d+l, d}...{d+l, ... d+l,d+l, d} {d+l, ... d+l,d+l,d+l} – Mr. Pi Feb 10 '15 at 18:38
• You're right; I was just being lazy in writing them out, fixing now. – 2012rcampion Feb 10 '15 at 20:37