Python Forum
nsimplify, make zero the really small numbers in the matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nsimplify, make zero the really small numbers in the matrix
#1
I created a symbolic matrix with sympy:

states = [1,2,3,4,5,6,7,8]
rho = np.array([[sympy.Symbol("rho{}{}".format(i,j)) for j in range(len(states))] for i in range(len(states))])
Here is my matrix
[[rho00 rho01 rho02 rho03 rho04 rho05 rho06 rho07] [rho10 rho11 rho12 rho13 rho14 rho15 rho16 rho17] [rho20 rho21 rho22 rho23 rho24 rho25 rho26 rho27] [rho30 rho31 rho32 rho33 rho34 rho35 rho36 rho37] [rho40 rho41 rho42 rho43 rho44 rho45 rho46 rho47] [rho50 rho51 rho52 rho53 rho54 rho55 rho56 rho57] [rho60 rho61 rho62 rho63 rho64 rho65 rho66 rho67] [rho70 rho71 rho72 rho73 rho74 rho75 rho76 rho77]]
Now, I am multiplying my symbolic matrix and real matrix like that;

p_final=np.matmul(realmat,rho)
#print(p_final)
sympy.nsimplify(p_final,tolerance=1e-10,rational=True)
ALthough, I use nsimplyfy, I am getting this result which is quite annoying

[1.0*rho00 - 1.79380389039135e-16*rho01 - 1.79380389039135e-16*rho10 + 3.21773239718314e-32*rho11
-1.79380389039135e-16*rho00 + 1.0*rho01 + 3.21773239718314e-32*rho10 - 1.79380389039135e-16*rho11
1.0*rho02 - 3.25176795283269e-17*rho03 - 1.79380389039135e-16*rho12 + 5.83303400444119e-33*rho13
-3.25176795283269e-17*rho02 + 1.0*rho03 + 5.83303400444119e-33*rho12 - 1.79380389039135e-16*rho13
1.0*rho04 + 1.01465363575695e-17*rho05 - 1.79380389039135e-16*rho14 - 1.82008963922055e-33*rho15
1.01465363575695e-17*rho04 + 1.0*rho05 - 1.82008963922055e-33*rho14 - 1.79380389039135e-16*rho15
-3.25176795283269e-17*rho06 + 1.0*rho07 + 5.83303400444119e-33*rho16 - 1.79380389039135e-16*rho17
1.0*rho06 - 3.25176795283269e-17*rho07 - 1.79380389039135e-16*rho16 + 5.83303400444119e-33*rho17]
.....

I did not paste whole result but I do not want to see e-17*rho because it is already small or really small. I want to make them 0
Ideally nsimplfy should do that but it did not change the result

btw, my real matrix is here:

[[ 1. -0. 0. 0. 0. 0. 0. 0.]
[-0. 1. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 1. -0. 0. 0. 0. 0.]
[ 0. 0. -0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1. 0. 0.]
[ 0. 0. 0. 0. 0. 0. -0. 1.]
[ 0. 0. 0. 0. 0. 0. 1. -0.]]
How to do that?
Reply


Messages In This Thread
nsimplify, make zero the really small numbers in the matrix - by quest - Jan-19-2022, 09:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 843 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,391 May-03-2021, 06:30 AM
Last Post: Gribouillis
  How do I make a symmetric matrix from a column vector? leocsmith 3 3,691 Mar-30-2021, 10:17 AM
Last Post: leocsmith
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,451 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,758 May-09-2019, 12:19 PM
Last Post: Pleiades
  How to extract specific numbers from a matrix? Alberto 0 3,359 Mar-06-2018, 02:52 PM
Last Post: Alberto
  How to make a subtraction within a range of numbers? Alberto 3 10,123 May-08-2017, 09:13 PM
Last Post: ichabod801
  matrix from matrix python numpy array shei7141 1 3,724 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020