ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 17 Mar 2024 07:51:32 +0100running code twice generate errorhttps://ask.sagemath.org/question/76545/running-code-twice-generate-error/Hi
W11 ,WSL ,Ubuntu 22.04.4 LTS,SageMath 10.2 (same PB with 10.0) In Jupyter notebook
When I run this code twice (first time is ok) , I get the error about the matrix :
**TypeError: no canonical coercion from Polyhedra in QQ^3 to Symbolic Ring**
(I need to reset SageMath kernel to run again without error)
But on sageCell I can run this code many times without getting error.
So 3 questions :
Q1 : is there a SageMath kernel reset every time before SageCell code is executed ?
Q2 : Do you see something wrong I do in this code ?
Q3 : If no Q2 , is this the same problem for you ?
# functions
def polyhedronCentroid(vertices):
# vertices: List of tuples (x, y, z,...) representing the polyhedron vertices dim could be >3
num_vertices = len(vertices)
centroid = [sum(coord[i] for coord in vertices) / num_vertices for i in range(len(vertices[0]))]
return centroid
def translateStructure(structDic,pt):
newDic={}
for k in structDic.keys() :
newDic[k]=list( vector(structDic.get(k))+vector(pt) )
return newDic
def rotateStructure(structDic,angleRot,axisRot,sameCenter) :
global rotX,rotY,rotZ
if axisRot=='x' : # rotation around x axis
rotM=matrix( QQ,rotX.subs(t_x=angleRot ) )
elif axisRot=='y' : # rotation around y axis
rotM=matrix( QQ,rotY.subs(t_y=angleRot ) )
elif axisRot=='z' : # rotation around z axis
rotM=matrix( QQ, rotZ.subs(t_z=angleRot ) )
else :
print('something wrong for axis rotation')
return cubeDic
show('rotM : ',rotM)
newTDic={}
for k in structDic.keys() :
newTDic[k]=list(rotM*vector(list(structDic.get(k))))
if sameCenter :
centerV=vector(polyhedronCentroid(list(structDic.values())))
translatePt=list(vector(centerV-(rotM*centerV)))# reset center at old structure location
newTDic=translateStructure(newTDic,translatePt)
else :
return(newTDic)
#show('newDic : ' ,newDic)
#show('newTDic : ',newTDic)
return newTDic
def addAxis(plt,textToPlt,xBound,yBound,zBound,wA,rA) :
# add axis for real part
plt += arrow3d((0, 0, 0), (xBound, 0, 0), color='violet',width=wA,radius=rA)
plt += text3d("ex", (xBound, 0, 0), fontsize='200%', color='violet')
plt += arrow3d((0, 0, 0), (0, yBound, 0), color='gray',width=wA,radius=rA)
plt += text3d("ey", (0, yBound, 0), fontsize='200%', color='gray')
plt += arrow3d((0, 0, 0), (0, 0, zBound), color='pink',width=wA,radius=rA)
plt += text3d("ez", (0,0, zBound), fontsize='200%', color='pink')
plt+=textToPlt
return plt
###################################################################################
##################### end functions area ##########################################
var('t_x',latex_name=r"\\teta_{x}")
var('t_y',latex_name=r"\\teta_{y}")
var('t_z',latex_name=r"\\teta_{z}")
rotX=matrix(SR,[[1,0,0],[0,cos(t_x),-sin(t_x)],[0,sin(t_x),cos(t_x)]])
rotY=matrix(SR,[[cos(t_y),0,sin(t_y)],[0,1,0],[-sin(t_y),0,cos(t_y)]])
rotZ=matrix(SR,[[cos(t_z),-sin(t_z),0],[sin(t_z),cos(t_z),0],[0,0,1]])
xBound=1.5 ;yBound=1.5 ;zBound=1.5
shiftV=vector([1/10,1/10,1/10])
width=0.2 ;radius=0.02
cubeAdic={0: [0, 0, 0], 1: [1, 0, 0], 2: [1, 1, 0], 3: [0, 1, 0] , \
4: [0, 0, 1], 5: [1, 0, 1], 6: [1, 1, 1], 7: [0, 1, 1]}
cubeArevDic=dict(zip([str(cubeAdic.get(k)) for k in cubeAdic.keys()],[k for k in cubeAdic.keys()]))
cubeAsimplex3=[[0, 4, 5, 7], [0, 1, 2, 6], [0, 1, 5, 6], [0, 2, 3, 7], [0, 5, 6, 7], [0, 2, 6, 7]]
tetraHedron=cubeAsimplex3[0]
tetraHedronDic={}
for vertice in tetraHedron :
tetraHedronDic[vertice]=cubeAdic.get(vertice)
axisRot='z'
locationXYZ=[0,0,1]
angleRot=pi/2
structureDic=rotateStructure(tetraHedronDic,angleRot,axisRot,False)
textToPlt = text3d("AB",vector( (xBound, yBound, 1.5*zBound))+shiftV, fontsize='300%', fontweight=800)
print( 'tetraHedronDic.values : ',list(tetraHedronDic.values()) )
pi=Polyhedron(list(tetraHedronDic.values()) , base_ring=QQ)
print( 'structureDic.values : ',list(structureDic.values()) )
po=Polyhedron(list(structureDic.values()), base_ring=QQ)
plt=addAxis(Graphics(),textToPlt,xBound,yBound,zBound+1,width,radius)
plt+=pi.plot(color='black',opacity=0.5)
plt+=po.plot(color='red',opacity=0.5)
plt.show()ortolljSun, 17 Mar 2024 07:51:32 +0100https://ask.sagemath.org/question/76545/Cell label resethttps://ask.sagemath.org/question/40336/cell-label-reset/What is the proper way to reset the cell number in a notebook cell?
When I evaluate all the cells of a notebook I want to always start with the number In[1] as the first cell label of the notebook in order to have a predictable number of all the subsequent cells, something like kill(labels) in Maxima.
danielvolinskiThu, 28 Dec 2017 11:59:31 +0100https://ask.sagemath.org/question/40336/remove values from variables but keep variableshttps://ask.sagemath.org/question/37534/remove-values-from-variables-but-keep-variables/ How do I remove the values from variables but keep the variables. i.e. if x is defined and equal to 5, and I reset() I just get x as undefined if I try to use it in a symbolic equation. I just want to remove the 5 but keep the x.cybervigilanteSun, 07 May 2017 16:27:33 +0200https://ask.sagemath.org/question/37534/How to re-initialise the admin & user account, especially for password?https://ask.sagemath.org/question/23523/how-to-re-initialise-the-admin-user-account-especially-for-password/ Hi all, nice to see you.
This is my 1st. time question after joining here.
I'm a beginner for Sage Math (for Mac OS X by .dmg), and tried to use it for a while.
But yesterday, it hanged, and it went wrong.
I have already re-installed the .dmg and deleted (moved) the ~/.sage.
However I cannot login to the Sage notebook (from Launcher) since it seems I lost login information for my private account.
But when I execute the sage from command line, and also execute the notebook(), I succeeded to login as admin.
What should I do to recover the previous, comfortable use of Sage?
What should I do to reset those accounts' info. from Sage command line or else.
Thanks in advance,renpooTue, 22 Jul 2014 03:59:02 +0200https://ask.sagemath.org/question/23523/Use 'reset()' in a scripthttps://ask.sagemath.org/question/10448/use-reset-in-a-script/Hi experts!!
Can I use `reset()` in a script?
For example, if numpy arrays A, B and C are creted and i wanna free thre RAM used. Can I use reset(A,B,C) for that?
Waiting for your answers.
Thanks a lot
mresimulatorTue, 24 Sep 2013 08:08:32 +0200https://ask.sagemath.org/question/10448/Cannot reset password as a userhttps://ask.sagemath.org/question/10501/cannot-reset-password-as-a-user/Using MaxOSX 10.8.4, with Sage 5.31
I've been using Sage as admin for several days, running it by clicking on the executable in /Applications to run it. Overall, it runs reasonably OK.
The problem is when I try to create a new user (me). I create the user account (which, by the way has a bad interface because you are put into an infinite loop of creating users with no escape).
So I create the user, save the password and login as the new user. That works. I then try to change the password, typing in the old one and new one (twice). Then I sign out and login again as the user. **Sage does not accept the new password.** Now neither the old or new passwords works, so the account is unusable. I then login again as admin and delete the account. I repeated the account creation/change password process 3 more times, being very careful to type in the password very carefully. It fails the same way every time! What is going on?paulavery1951Tue, 03 Sep 2013 20:15:56 +0200https://ask.sagemath.org/question/10501/reset user passwordhttps://ask.sagemath.org/question/9508/reset-user-password/How do I - as an admin - reset another users password?
I added all students in my class by defining 'um' as a user_manager object, usr as a string and then executing
um.add_user(usr,usr,'',"user")
I expected the same string would act both as user-ID and password, but that is not the case: the users are added, with correct user-id, but unknown password.
I then tried to change the password, e.g. for user ac0101, from the sage-prompt like this:
um.user('ac0101').set_password('abcd')
I expected that this would set the password to 'abcd', but that is not the case. No errormessage appears, but I still cannot login with password 'abcd'.Dirk DanckaertWed, 07 Nov 2012 05:08:26 +0100https://ask.sagemath.org/question/9508/