Question: Can someone help with the simplification of this code?

Please I found out that the MatrixInverse on the assignment statement P3 does not run for about three days now. Please kindly help to simplify the code. Thank you and kind regards.

restart; omega := v/h;
r := a[0]+a[1]*x+a[2]*sinh(omega*x)+a[3]*cosh(omega*x)+a[4]*cos(omega*x)+a[5]*sin(omega*x);
b := diff(r, x);

c := eval(b, x = q) = f[n];
d := eval(r, x = q+3*h) = y[n+3]; e := eval(b, x = q+3*h) = f[n+3];
g := eval(b, x = q+2*h) = f[n+2];
i := eval(b, x = q+h) = f[n+1];
j := eval(b, x = q+4*h) = f[n+4];
k := solve({c, d, e, g, i, j}, {a[0], a[1], a[2], a[3], a[4], a[5]});
Warning,  computation interrupted
assign(k);
cf := r;
s4 := y[n+4] = simplify(eval(cf, x = q+4*h));
s3 := y[n+2] = simplify(eval(cf, x = q+2*h));
s2 := y[n+1] = simplify(eval(cf, x = q+h));
s1 := y[n] = simplify(eval(cf, x = q));

with(LinearAlgebra);
with(plots);
h := 1;
YN_1 := seq(y[n+k], k = 1 .. 4);
A1, a0 := GenerateMatrix([s1, s2, s3, s4], [YN_1]);
eval(A1);
YN := seq(y[n-k], k = 3 .. 0, -1);
A0, b1 := GenerateMatrix([s1, s2, s3, s4], [YN]);
eval(A0);
FN_1 := seq(f[n+k], k = 1 .. 4);
B1, b2 := GenerateMatrix([s1, s2, s3, s4], [FN_1]);
eval(B1);
FN := seq(f[n-k], k = 3 .. 0, -1);
B0, b3 := GenerateMatrix([s1, s2, s3, s4], [FN]);
eval(B0);
ScalarMultiply(R, A1)-A0;
det := Determinant(ScalarMultiply(R, A1)-A0);
P1 := A1-ScalarMultiply(B1, z);
P2 := combine(simplify(P1, size), trig);
P3 := MatrixInverse(P2);
P4 := A0-ScalarMultiply(B0, z);
P5 := MatrixMatrixMultiply(P3, P4);
P6 := Eigenvalues(P5);
f := P6[4];
T := unapply(f, z);
implicitplot(f, z = -5 .. 5, v = -5 .. 5, filled = true, grid = [5, 5], gridrefine = 8, labels = [z, v], coloring = [blue, white]);

 

Please Wait...