2
$\begingroup$

I'm facing a Problem in Mathematica, where I have to solve a large number of equations generated by an AppendTo.

n = 200;
dz = 1000/n;
RollLM[l_, EM_, Ixx_, p_] := {{1, l, Power[l, 2] / (2 EM Ixx), Power[l, 3] / (6 EM Ixx), p Power[l, 4] / (24 EM Ixx)}, {0, 1, l / (EM Ixx), Power[l, 2] / (2 EM Ixx), p Power[l, 3] / (6 EM Ixx)}, {0, 0, 1, l , p Power[l, 2] / 2}, {0, 0, 0, 1, p l}, {0, 0, 0, 0, 1}};
BearLM[d_, c_] := {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, d, 1, 0, 0}, {-c, 0, 0, 1, 0}, {0, 0, 0, 0, 1}};
pBF = Function[z, Piecewise[{{989000/500, 250 <= z <= 750}}]];

Vec1A = {vA, PhiA, 0, 0, 1};
Vec2A = BearLM[810000, 850000].Vec1A;
VecAList = {Vec2A};
Do[AppendTo[VecAList, RollLM[dz, 210000, 262440000 \[Pi], pBF[(i-0.5)dz]] .VecAList[[i]]], {i, n}];
Vec3A = BearLM[810000, 850000].Last[VecAList];
SolA = Solve[{Vec3A[[3]] == 0, Vec3A[[4]] == 0},{vA,PhiA}][[1]]

I'm now trying to tune this code performancewise and first thought about switching from AppendTotoo Reap & Sowbut the most time consuming factor is the solving. Is there any option how to speed this up?

Also I already asked a similar question here: Switching from AppendTo to Reap & Sow

$\endgroup$
5
$\begingroup$

If I understand your computations, this can be done with Fold:

Fold[RollLM[dz, 210000, 262440000 π, pBF[(#2 - 0.5) dz]].#1 &, Vec2A, Range[n]] // Simplify;

This gives the same result as your Do[...] // Last // Simplify. Next let's compute Vec3A and solve:

Vec3A = BearLM[810000, 850000].% // Simplify
Solve[{%[[3]] == 0, %[[4]] == 0}, {vA, PhiA}][[1]]

{vA -> 989/1700, PhiA -> 271975/(1944 (1 + 136080 π))}

If you need all parts of VecAList, you can use FoldList.

|improve this answer|||||
$\endgroup$
0
$\begingroup$

There is plenty of room for performance optimization in this. Have a try on the thread:

Performance tuning in mathematica

Better look deep into Mathematica on Stackexchange to avoid double questions.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ I already read that thread, refered in the Thread I linked in the question. The question is more like is there any method one can choose for Solve to tune the speed of the programm. $\endgroup$ – CR36 Jan 14 at 9:02

Your Answer

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

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