I have derived 3 linear equations symbolically with variables C4, C5 and C6, and I would like to convert these into matrix-vector format [A][x]=[0]
. I have found another question on this forum that relates to this: Turning system of linear equations into a matrix, but I don't know how to apply that in this case.
E, Iz, A, l, kt, aL, dT, N0 ,C4, C5, C6 = var('E, Iz, A, l, kt, aL, dT, N0, C4, C5, C6')
w(x) = C4*(x^3 -l*x^2) + C5*(x^4 - l^2*x^2) + C6*(x^5 - l^3*x^2)
dw(x) = diff(w(x), x, 1); dw(x)
d2w(x) = diff(w(x), x, 2); d2w(x)
V1 = 1/2*E*Iz*((d2w(x))^2); V1
V2 = 1/2*N0*((dw(x))^2); V2
V = integral(V1, x, 0, l) + integral(V2, x, 0, l); show(V.simplify())
The equations to put in matrix-vector format:
dVdC4 = diff(V, C4).collect(C4).collect(C5).collect(C6) == 0; dVdC4
2/15*(N0*l^5 + 30*E*Iz*l^3)*C4 + 1/30*(7*N0*l^6 + 240*E*Iz*l^4)*C5 +
1/42*(13*N0*l^7 + 504*E*Iz*l^5)*C6 == 0
dVdC5 = diff(V, C5).collect(C4).collect(C5).collect(C6) == 0; dVdC5
1/30*(7*N0*l^6 + 240*E*Iz*l^4)*C4 + 4/105*(11*N0*l^7 + 441*E*Iz*l^5)*C5 +
1/30*(17*N0*l^8 + 780*E*Iz*l^6)*C6 == 0
dVdC6 = diff(V, C6).collect(C4).collect(C5).collect(C6) == 0; dVdC6
1/42*(13*N0*l^7 + 504*E*Iz*l^5)*C4 + 1/30*(17*N0*l^8 + 780*E*Iz*l^6)*C5 +
1/63*(49*N0*l^9 + 2592*E*Iz*l^7)*C6 == 0
Then I created the next matrix by hand; but I assume there is a smarter way to construct a matrix:
matrix1 = matrix([
[2/15*(N0*l^5 + 30*E*Iz*l^3), 1/30*(7*N0*l^6 + 240*E*Iz*l^4), 1/42*(13*N0*l^7 + 504*E*Iz*l^5)],
[1/30*(7*N0*l^6 + 240*E*Iz*l^4), 4/105*(11*N0*l^7 + 441*E*Iz*l^5), 1/30*(17*N0*l^8 + 780*E*Iz*l^6)],
[1/42*(13*N0*l^7 + 504*E*Iz*l^5), 1/30*(17*N0*l^8 + 780*E*Iz*l^6), 1/63*(49*N0*l^9 + 2592*E*Iz*l^7)]
])
matrix1