Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Something odd is definitely happening here, and I am not the one to help on this situation. But, here is some code that will get the plot you want. It's a bit brute force and not as elegant as your approach, but it does work.

H=matrix([[1+x, 0, x],[0, 2, 2*x],[x, 2*x, 1+x]])
pts0=[]
pts1=[]
pts2=[]
xlist=srange(0,0.5,0.01)
ans=[map(lambda x: n(real_part(x)),H.subs(x=x0).eigenvalues()) for x0 in xlist]
ans=[sorted(a) for a in ans]
for i in range(0,len(xlist)):
    pts0.append([xlist[i],ans[i][0]])
    pts1.append([xlist[i],ans[i][1]])
    pts2.append([xlist[i],ans[i][2]])  
list_plot(pts0,plotjoined=true,color='red')+list_plot(pts1,plotjoined=true,color='blue')+list_plot(pts2,plotjoined=true,color='green')

Something odd is definitely happening here, and I am not the one to help on this situation. But, here is some code that will get the plot you want. It's a bit brute force and not as elegant as your approach, but it does work.

H=matrix([[1+x, 0, x],[0, 2, 2*x],[x, 2*x, 1+x]])
pts0=[]
pts1=[]
pts2=[]
xlist=srange(0,0.5,0.01)
ans=[map(lambda x: n(real_part(x)),H.subs(x=x0).eigenvalues()) for x0 in xlist]
ans=[sorted(a) for a in ans]
for i in range(0,len(xlist)):
    pts0.append([xlist[i],ans[i][0]])
    pts1.append([xlist[i],ans[i][1]])
    pts2.append([xlist[i],ans[i][2]])  
list_plot(pts0,plotjoined=true,color='red')+list_plot(pts1,plotjoined=true,color='blue')+list_plot(pts2,plotjoined=true,color='green')

image description

Using the characteristic polynomial and the implicit_plot command also gives a really nice plot.

var('y') H=matrix([[1+x, 0, x],[0, 2, 2x],[x, 2x, 1+x]]) p(x,y)=H.charpoly('y') implicit_plot(p(x,y),(x,-3,5),(y,0,5))

image description

Something odd is definitely happening here, and I am not the one to help on this situation. But, here is some code that will get the plot you want. It's a bit brute force and not as elegant as your approach, but it does work.

H=matrix([[1+x, 0, x],[0, 2, 2*x],[x, 2*x, 1+x]])
pts0=[]
pts1=[]
pts2=[]
xlist=srange(0,0.5,0.01)
ans=[map(lambda x: n(real_part(x)),H.subs(x=x0).eigenvalues()) for x0 in xlist]
ans=[sorted(a) for a in ans]
for i in range(0,len(xlist)):
    pts0.append([xlist[i],ans[i][0]])
    pts1.append([xlist[i],ans[i][1]])
    pts2.append([xlist[i],ans[i][2]])  
list_plot(pts0,plotjoined=true,color='red')+list_plot(pts1,plotjoined=true,color='blue')+list_plot(pts2,plotjoined=true,color='green')

image description

Using the characteristic polynomial and the implicit_plot command also gives a really nice plot.

var('y')
H=matrix([[1+x, 0, x],[0, 2, 2x],[x, 2x, 2*x],[x, 2*x, 1+x]])
p(x,y)=H.charpoly('y')
implicit_plot(p(x,y),(x,-3,5),(y,0,5))

implicit_plot(p(x,y),(x,-3,5),(y,0,5))

image description

Something odd is definitely happening here, and I am not the one to help on this situation. But, here is some code that will get the plot you want. It's a bit brute force and not as elegant as your approach, but it does work.

H=matrix([[1+x, 0, x],[0, 2, 2*x],[x, 2*x, 1+x]])
pts0=[]
pts1=[]
pts2=[]
xlist=srange(0,0.5,0.01)
ans=[map(lambda x: n(real_part(x)),H.subs(x=x0).eigenvalues()) for x0 in xlist]
ans=[sorted(a) for a in ans]
for i in range(0,len(xlist)):
    pts0.append([xlist[i],ans[i][0]])
    pts1.append([xlist[i],ans[i][1]])
    pts2.append([xlist[i],ans[i][2]])  
list_plot(pts0,plotjoined=true,color='red')+list_plot(pts1,plotjoined=true,color='blue')+list_plot(pts2,plotjoined=true,color='green')

image description

Using the characteristic polynomial and the implicit_plot command also gives a really nice plot.

var('y')
H=matrix([[1+x, 0, x],[0, 2, 2*x],[x, 2*x, 1+x]])
p(x,y)=H.charpoly('y')
implicit_plot(p(x,y),(x,-3,5),(y,0,5))

image description

You can also use contour_plot to color the regions in the plane by sign.

contour_plot(p(x,y),(x,-3,5),(y,0,5),contours=0,cmap=['red','blue'])