I'm trying to speed up my Code, but I'm facing problems with changing the AppendTo section in my code with something "Faster". I've read through some other examples that explain the use of Reapand Sow.
Understanding Sow and Reap documentation
Writing Faster Mathematica Code - Sow and Reap?
https://blog.wolfram.com/2011/12/07/10-tips-for-writing-fast-mathematica-code/
I can't figure out how to apply the Solutions given in the links for my problem.
n = 20;
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]];
a,b,vA,RF,B,PhiAmeant to be numerical values? Then please define them first. That will speed up already quite a lot. – Henrik Schumacher Jan 10 '20 at 12:12a,b,RFandBto the numerical values. I justed overlocked to change them in the first place. ButPhiAandvAwill be later one solved in the Code. – CR36 Jan 10 '20 at 12:18ListLinePlot[LeafCount /@ VecAList]tells me that this is not a good idea. Better numericisePhiAandvAand use a numerical linear solver instead. – Henrik Schumacher Jan 10 '20 at 12:21