Ask Your Question
0

numerical approximation of complex number

asked 2013-03-16 16:53:03 +0100

Leo_Mullan gravatar image

updated 2015-01-13 21:53:30 +0100

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:

e,f,g,h,i,j,k,l,m,n,o,p,g,r,s,t=var('e,f,g,h,i,j,k,l,m,n,o,p,g,r,s,t');
var("w", domain="complex");
a=4;
b=8;
c=32/3;
d=4;

m1=1;
m2=m1/2;
x=m1*(w);
y=m2*(w);

F=matrix([[1,a,b,c],[0,1,d,b],[0,0,1,a],[0,0,0,1]]);
M1=matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[x,0,0,1]]);
M2=matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[y,0,0,1]]);
([[e,f,g,h],[i,j,k,l],[m,n,o,p],[q,r,s,t]])=F*M1*F*M1*F*M1*F*M2;
A=matrix([[o,p],[s,t]]);
B=A.determinant();
C=solve(B==0,w);
numerical_approx(C)

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
1

answered 2013-03-16 17:18:55 +0100

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
0

answered 2013-03-16 17:31:05 +0100

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

Stats

Asked: 2013-03-16 16:53:03 +0100

Seen: 1,160 times

Last updated: Mar 16 '13