# I have code which is giving me results. I want to improve the code

m1 = Piecewise[{{5.27107*10^-16 Cos[1.57088 x1] -
2.80045*10^-17 Cosh[1.57088 x1] + 0.707304 Sin[1.57088 x1] +
0.0000332641 Sinh[1.57088 x1], x1 <= 1.66667},
{0.35357 Cos[1.57088 (-1.66667 + x1)] +
0.000226813 Cosh[1.57088 (-1.66667 + x1)] -
0.612135 Sin[1.57088 (-1.66667 + x1)] -
0.00022711 Sinh[1.57088 (-1.66667 + x1)], x1 >= 1.66667}}]

m2=Piecewise[{{(-2.11473*10^-15 Cos[2.35624 x1] -
7.8246*10^-16 Cosh[2.35624 x1] + 0.707039 Sin[2.35624 x1] -
3.76568*10^-6 Sinh[2.35624 x1]),
x1 <= 1.66667}, {-0.499992 Cos[2.35624 (-1.66667 + x1)] -
0.0000955323 Cosh[2.35624 (-1.66667 + x1)] -
0.500104 Sin[2.35624 (-1.66667 + x1)] +
0.0000955355 Sinh[2.35624 (-1.66667 + x1)], x1 >= 1.66667}}]

m3 = Piecewise[{{-1.67621*10^-7 Cos[2.13353 x1] -
5.30286*10^-7 Cosh[2.13353 x1] + 0.816848 Sin[2.13353 x1] +
0.0187942 Sinh[2.13353 x1] , x1 <= 1.66667}, {
-0.328821 Cos[2.13353 (-1.66667 + x1)] +
0.328821 Cosh[2.13353 (-1.66667 + x1)] -
0.089538 Sin[2.13353 (-1.66667 + x1)] -
0.328852 Sinh[2.13353 (-1.66667 + x1)] , x1 >= 1.66667}}]

m4 = Piecewise[{{-1.7389*10^-6 Cos[2.88372 x1] +
1.92984*10^-6 Cosh[2.88372 x1] + 0.346661 Sin[2.88372 x1] +
0.00564411 Sinh[2.88372 x1] , x1 <= 1.66667}, {
-0.345138 Cos[2.88372 (-1.66667 + x1)] +
0.345138 Cosh[2.88372 (-1.66667 + x1)] +
0.722795 Sin[2.88372 (-1.66667 + x1)] -
0.345139 Sinh[2.88372 (-1.66667 + x1)], x1 >= 1.66667}}]
W = Expand[c1*m1 + c2*m2 + c3*m3 + c4*m4];
Wxx = Expand[(D[W, {x1, 2}])];
in1 = Expand[(Wxx)^2];
in2 = Expand[W^2];
terms1 = List @@@ List @@ in1;
integrals1 = GatherBy[#, MemberQ[#, x1, Infinity] &] & /@ terms1;
v1 =  (Total[(Times @@@
integrals1[[All, 1]])*(NIntegrate[Times @@ #, {x1, 0, 4},
Method -> {Automatic, "SymbolicProcessing" -> 0}] & /@
integrals1[[All, 2]])]);
terms2 = List @@@ List @@ in2;
integrals2 = GatherBy[#, MemberQ[#, x1, Infinity] &] & /@ terms2;
t1 = (Total[(Times @@@
integrals2[[All, 1]])*(NIntegrate[Times @@ #, {x1, 0, 4},
Method -> {Automatic, "SymbolicProcessing" -> 0}] & /@
integrals2[[All, 2]])]);


I have a working code, but I am getting some warning messages and the codes seem bit lengthy. How to reduce it without compromising on the results. I am using numerical integration function. If I go for regular integration it takes a lot of time to get the result.

• I have only messages in the execution code. Apparently not defined parameters, for example,c1,c2,c3,c4, const1,const2, L1 – Alex Trounev Oct 11 '18 at 10:55
• Ok I slightly changed the question, Now have values for L1 is replaced with 4. But how to suppress the warnings – acoustics Oct 11 '18 at 14:07
• I put all the constants = 1,L1=1, {c1 -> 1, c2 -> 1, c3 -> 1, c4 -> 1}. Code run without messages. – Alex Trounev Oct 11 '18 at 15:16
• I want the results of NIntegrate with constants c1,c2,c3,c4, that is why I have written such huge code. is there any other ways to do that? – acoustics Oct 11 '18 at 15:49
• You cannot use a numerical integral with indefinite constants. – Alex Trounev Oct 11 '18 at 15:56