0

I'm trying to find the symbolic determinant of a 4x4 matrix that has bessel functions (and their derivatives) in every element. I successfully managed this in matlab, but I'm trying to learn Python by moving the project over. For context, I'm trying to find the natural frequencies of an annular plate. General workflow is to assemble the system of matrices A*x = 0 (In the code, X*y = 0). Find the determinant of A, set that equal to zero to find something called the frequency parameter (lambda or lam in my code), which is the roots of the equation (det=0). I'm struggling to a) find the determinant of the symbolic matrix (it took hours and didn't give me anything back) and b) to then swap from a symbolic equation and solve it numerically to find its roots (lambda).

very very grateful for any help offered, and apologies if I've formatted this post/code wrong!

import sympy as sp
import numpy as np
import scipy.optimize
from sympy import *
from sympy import lambdify

k,r,theta,n,A,B,C,D,w,v,var,lam,alph,omega = symbols("k,r,theta,n,A,B,C,D,w,v,var,lam,alph,omega")
"""
define the mode shape equation
"""
w = ((A*besselj(n,k*r) + B*bessely(n,k*r) + C*besseli(n,k*r) + D*besselk(n,k*r))*cos(n*theta))
"""
Define Boundary Conditions
"""
dw = diff(w,r)/k
Qw = (diff(w,r,3) +(1/r)*diff(w,r,2)-(1/r**2)*diff(w,r)+(2-v)*(1/r**2)*diff(diff(w,r),theta,2)-(3-v)*(1/r**3)*diff(w,theta,2))/k**3
Mw = (diff(w,r,2)+ v*((1/r)*diff(w,r)+(1/r**2)*diff(w,theta,2)))/k**2
"""
sub in correct radius for the appropriate condition
"""
w_a,dw_a,Qw_b,Mw_b,a,b = symbols("w_a,dw_a,Qw_b,Mw_b,a,b")

w_a = w.subs(r,a)
dw_a = dw.subs(r,a)
Qw_b = Qw.subs(r,b)
Mw_b = Mw.subs(r,b)
"""
Assemble equations into a matrix
"""
eq,x = symbols("eq,x")

eq = Matrix([[w_a], [dw_a], [Mw_b], [Qw_b]])
x = Matrix([[A],[B],[C],[D]])

X,y = linear_eq_to_matrix(eq,[A,B,C,D])
coeff_mat = X/cos(n*theta)
"""
trying to get lambda and alpha to be the only unknowns in the determinant
"""
A = lam/k
B = lam*alph*k
K = lam/a

np.savetxt('Coefficient_Matrix_1.csv', coeff_mat, delimiter=',', fmt='%s')

coeff_mat = coeff_mat.subs(a,A)
coeff_mat = sp.simplify(coeff_mat.subs(b,B))
coeff_mat = coeff_mat.subs(k,K)

np.savetxt('Coefficient_Matrix_2.csv', coeff_mat, delimiter=',', fmt='%s')
"""
alpha and v need to be defined to leave the determinant unknown in only lambda
"""
coeff_mat = coeff_mat.subs([(alph,0.3), (v,0.3)])

np.savetxt('Coefficient_Matrix_3.csv', coeff_mat, delimiter=',', fmt='%s')
"""
looks like the "a"s havent been compltely removed, but it does look like they should all cancel out - try to solve without submitting, then check if
value of a has any impact - if they cancel the value shouldn't matter
  • A couple of issues. The symbolic and numeric codes are better integrated in MATLAB. While it is common to use a star import with sympy, it is also harder to to identify where its's being used. I for one can't follow sympy code without seeing intermediate results. In this code are you using numpy for anything besides `savetxt`? You may need to focus the code and question.. – hpaulj Oct 16 '22 at 22:59

0 Answers0