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 AppendTo
too Reap
& Sow
but 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