Ask Your Question

numerical approximation of complex number

asked 2013-03-16 10:53:03 -0500

Leo_Mullan gravatar image

updated 2015-01-13 14:53:30 -0500

FrédéricC gravatar image

I am attempting to evaluate a matrix multiplication, then extract 4 specific cells from the resultant matrix and create a new 2x2 matrix with these 4 specific cells. I then need to calculate the points at which the determinant of the 2x2 matrix equals zero. This is to solve the resonant frequency of transverse vibration of a beam. My attempt at doing this:

var("w", domain="complex");



Sagemath returns an error since there are complex numbers.

I require numerical solutions.

apologies if the question is unclear, I have zero programming background, this is for my engineering dissertation.

Any help is appreciated.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-03-16 11:18:55 -0500

kcrisman gravatar image

Here is the actual error message. If you are not familiar with such systems, you may have been misled by the traceback (which goes through the code in the order it's executed in the system).

ValueError: too many values to unpack (expected 2)

Let's print C.

sage: C
[w == -1/2*(I*sqrt(3) + 1)*(3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) - 1/1384448*(-11545*I*sqrt(3) + 11545)/(3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) + 131/832, w == -1/2*(-I*sqrt(3) + 1)*(3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) - 1/1384448*(11545*I*sqrt(3) + 11545)/(3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) + 131/832, w == (3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) + 11545/692224/(3/22151168*I*sqrt(2)*sqrt(17080647) + 1153673/575930368)^(1/3) + 131/832]

This isn't a value of an expression, it's a list of solutions. So we use a nifty thing called a list comprehension to get them all approximated.

sage: [numerical_approx(c.rhs()) for c in C]
[0.0573091049586257 - 4.16333634234434e-17*I,
 0.00133665963111623 + 4.16333634234434e-17*I,
 0.413710004641027 + 3.46944695195361e-18*I]

Hope this helps! Learning a little Python will go a LONG way toward getting tons of usefulness out of Sage.

edit flag offensive delete link more

answered 2013-03-16 11:31:05 -0500

Leo_Mullan gravatar image

Thanks a lot for the quick response, that does help. I am attempting to learn python as sagemath is coming in handy for a lot of engineering applications, time is tight though with dissertation looming. Do you know if there is a way of getting sagemath to then return a real number from the solutions rather than complex numbers?

My alternative if I cannot get a real number is to plot the function "B" and individually re-plot the graph to "home in" on the point it intersects the axis. This is time consuming and if I change a variable I start from scratch.

Thanks again for your help.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-16 10:53:03 -0500

Seen: 347 times

Last updated: Mar 16 '13