Message Boards Message Boards

0
|
913 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Wolfram Engine taking long to evaluate eigenvalues and vectors

Posted 5 months ago

Hi Guys

My code is pretty long and I am not going to show it here in it's entirety. I essentially have developed Python code which takes an excel file developed from a structural engineering package which cannot perform dynamic analysis. The excel file is read and an equivalent model developed in Python. I intend to use the Wolfram engine to calculate the eigenvalues and vectors and furthermore perform a dynamic analysis. the below is the Python code to evaluate the eigenvectors and values. It works well for small structures. I have tried a structure which has matrices that are 234x234 and the solution takes forever. Is there anyway to speed up the solution?

from wolframclient.language import wl, wlexpr
from wolframclient.evaluation import WolframLanguageSession

stiffness_matrix = K
mass_matrix = M
# Convert NumPy arrays to Mathematica strings
def numpy_to_mathematica(matrix):
    return "{" + ", ".join("{" + ", ".join(map(str, row)) + "}" for row in matrix) + "}"

stiffness_matrix_str = numpy_to_mathematica(stiffness_matrix)
mass_matrix_str = numpy_to_mathematica(mass_matrix)

# Start a Wolfram Language session
session = WolframLanguageSession()

# Wolfram code to calculate eigenvalues and eigenvectors
wolfram_code = f"""
stiffnessMatrix = {stiffness_matrix_str};
massMatrix = {mass_matrix_str};
{{eigenvalues, eigenvectors}} = Eigensystem[{{stiffnessMatrix, massMatrix}}];
{{eigenvalues, eigenvectors}}
"""

# Evaluate the Wolfram code
result = session.evaluate(wlexpr(wolfram_code))

# Print the results
print("Eigenvalues:")
print(result[0])
print("\nEigenvectors:")
print(result[1])

# End the Wolfram Language session
session.terminate()
POSTED BY: Mishal Mohanlal
4 Replies
Posted 5 months ago

Sorry to flood this post, but changing the values to float32 and rounding the numbers off reduced the solve time to a few seconds for matrices in the order of 200x200.

POSTED BY: Mishal Mohanlal
Posted 5 months ago

I may have misunderstood your comment regarding machine numbers. No they are not machine numbers

POSTED BY: Mishal Mohanlal
Posted 5 months ago

Hi Daniel

Please refer to the images, I have plotted a heat map of the matrices which presents the type of numbers being used. Note that this is for a small 24x24 matrix since this is easier to view.

Heat map

POSTED BY: Mishal Mohanlal

Are these matrices comprised of machine real numbers? Or something else?

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract