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.Wed, 14 Aug 2019 09:00:37 +0200var list with only one variable errorhttps://ask.sagemath.org/question/47470/var-list-with-only-one-variable-error/Hi
SageMath 8.8 notebook OS=W10
why does it fail if L has only one variable ? :
L=['sd_1']
#L=['sd_1','sd_2']
varL=var(L)
show(varL)ortolljWed, 14 Aug 2019 09:00:37 +0200https://ask.sagemath.org/question/47470/generate multiple Vars and vectors with these Varshttps://ask.sagemath.org/question/44774/generate-multiple-vars-and-vectors-with-these-vars/Hi
this exercise comes from a MOOC course that has just ended
EDX.org , MITx: 6.431x Probability - The Science of Uncertainty and Data
![image description](/upfiles/15457260593779659.png)
forget()
var('pi_1 pi_2 pi_3 pi_4 pi_5 pi_6 pi_7 pi_8 pi_9')
# matrix of the Markov's Chain
m = matrix([ \
[1/3 , 5/9 , 0 , 0 , 1/9 , 0 , 0 , 0 , 0 ], \
[ 0 , 1/3 , 0 , 0 , 0 , 0 , 0 , 0 , 2/3 ], \
[ 0 , 0 , 1/3 , 1/3 , 0 , 0 , 1/3 , 0 , 0 ], \
[ 0 , 0 , 1/2 , 1/4 , 0 , 0 , 0 , 1/4 , 0 ], \
[ 0 , 0 , 0 , 0 , 3/4 , 1/4 , 0 , 0 , 0 ], \
[ 0 , 0 , 0 , 0 , 2/3 , 1/3 , 0 , 0 , 0 ], \
[ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ], \
[ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ], \
[ 0 , 0 , 2/3 , 0 , 0 , 0 , 0 , 0 , 1/3 ] \
])
v=vector([pi_1,pi_2,pi_3,pi_4,pi_5,pi_6,pi_7,pi_8,pi_9])
#Assuming that the Markov chain is initially in state 2 (i.e., X0=2),
# what is the probability that the chain eventually reaches state 7?
#################################
# brute force
#x_0=2
v_s=vector([0,1,0,0,0,0,0,0,0])
#v_s=vector([0,0,1,0,0,0,0,0,0])
V_r=v_s*m^110
show(V_r[6].n())
#################################
# smart way
eqT=[]
for i in range(0,len(v)):
eqT.append(m[i]*v==v[i])
show(eqT[2])
show(eqT[3])
S=solve([eqT[2],eqT[3],pi_7==1,pi_8==0],pi_3,pi_4,pi_7,pi_8)
show(S)
show("probability that the chain eventually reaches state 7 : ",S[0][0])
I would like to generate the variables, and the vector automaticaly:
kind of:
dimM=m.dimensions()[1]
varStr=''
for i in range(0,dimM):
#varStr=varStr+ ' a_'+str(i+1)
varStr=varStr+ ' a_'+str(i)
show(varStr)
var(varStr)
R = PolynomialRing(QQ, dimM, 'a_')
v= vector(R,dimM, R.gens())
show(m)
show(v)
eqT=[]
for i in range(0,len(v)):
show(m[i]*v==v[i])
eqT.append(m[i]*v==v[i])
#show(eqT)
but unfortunately this code just above for generating variables and vector automaticaly does not work
ortolljTue, 25 Dec 2018 09:26:10 +0100https://ask.sagemath.org/question/44774/Importing Sage functions into Cython?https://ask.sagemath.org/question/42277/importing-sage-functions-into-cython/ I am trying to define variables in Cython part of my code like this
a,b,c = var('a,b,c')
But in this line I cant import var() function from Sage
from sage.calculus.var import var
I got this error:
$ sage -python real_sage.sage
Compiling ./real_sage.spyx...
Traceback (most recent call last):
File "real_sage.sage", line 6, in <module>
from real_sage import foo
File "real_sage.pyx", line 10, in init real_sage
File "sage/calculus/var.pyx", line 6, in init sage.calculus.var
File "/home/tunamustafakemal/sega/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function_factory.py", line 15, in <module>
from sage.symbolic.function import SymbolicFunction, sfunctions_funcs, \
File "sage/rings/integer.pxd", line 7, in init sage.symbolic.function
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer
File "sage/rings/rational.pyx", line 89, in init sage.rings.rational
File "sage/rings/real_mpfr.pyx", line 1, in init sage.rings.real_mpfr
File "sage/rings/complex_number.pxd", line 6, in init sage.libs.mpmath.utils
File "sage/rings/complex_double.pxd", line 10, in init sage.rings.complex_number
File "sage/rings/complex_double.pyx", line 94, in init sage.rings.complex_double
ImportError: cannot import name complex_number
Thanks for any support.tunaMon, 07 May 2018 06:14:53 +0200https://ask.sagemath.org/question/42277/Problems with Var in Cloud.Sagemathhttps://ask.sagemath.org/question/23640/problems-with-var-in-cloudsagemath/Hi,
got a problem defining variables in cloud.sagemath:
http://www.directupload.net/file/d/3699/bs9eya98_png.htm
I just copied the code from
http://www.sagemath.org/doc/reference/calculus/sage/calculus/calculus.html
(the very first line)
but I also tried it myself with different letters and '`ยด". None worked.
ToreroWed, 30 Jul 2014 18:23:23 +0200https://ask.sagemath.org/question/23640/checking left hand side of an equationhttps://ask.sagemath.org/question/10880/checking-left-hand-side-of-an-equation/Hi,
I'd like to check if the operation applied to an equation yields the solution as follow:
a=var('a')
eq= a+7==6
print eq.lhs()
LHS =(eq-7).lhs()
print LHS
LHS==a
a is a
LHS is a
I was waiting that the line *LHS==a* yields **True** or **False**. How can I check that LHS contains the variable **a**?
edit
`LHS is a`
yields **False**jeanpatFri, 03 Jan 2014 10:49:49 +0100https://ask.sagemath.org/question/10880/how to use variables (`var`)https://ask.sagemath.org/question/10209/how-to-use-variables-var/I thought they are complex by default. But even when I try to force the domain to be complex, I always get `x.conjugate().simplify() == x`. Why? See also below:
sage: t1,t2,t4 = var("t1 t2 t4")
sage: t2.conjugate().simplify()
t2
sage: t1,t2,t4 = var("t1 t2 t4", domain="complex")
sage: t2
t2
sage: t2.is_real()
False
sage: t2.conjugate().simplify()
t2
sage: (t2.real()*2 - t2).simplify()
t2
sage: t2.real().simplify()
t2
sage: t2.imag().simplify()
0
Albert ZeyerMon, 10 Jun 2013 09:27:53 +0200https://ask.sagemath.org/question/10209/Difference Between var(), QQ() and PolynomialRing()https://ask.sagemath.org/question/9289/difference-between-var-qq-and-polynomialring/I am rather new to Sage and am trying to understand the internals of Sage better. I encountered some confusion when reading through the reference manual as to the difference between the different ring constructs used in sage. The var() function is of course used to declare a variable for symbolic manipulation but when should one use QQ[] or PolynomialRing()? I ran into this issue with the convolution() function which requires variables within functions to be declared using QQ[] or Polynomial ring and will not work with var(). Why is this? Is QQ the default namespace? How do these namespaces relate to the symbolic ring used with var? Thank you for your help!bpeacockMon, 03 Sep 2012 03:21:54 +0200https://ask.sagemath.org/question/9289/Strange error, possibly related to varhttps://ask.sagemath.org/question/8854/strange-error-possibly-related-to-var/ class CTest(object):
def __init__(self,arg=None):
var('x,y')
if type(arg) is list:
print [x in ZZ for x in arg]
elif arg in PolynomialRing(ZZ,2,(x,y)):
pass
a=CTest()
Traceback (most recent call last):
...
File "", line 6, in __init__
UnboundLocalError: local variable 'x' referenced before assignment
Replacing var('x,y') with x,y=var('x,y') eliminates the error. So does replacing PolynomialRing(ZZ,2,(x,y)) with [1,2,3]. Or changing the x in [x in ZZ for x in arg] to z.chaesloc2Wed, 04 Apr 2012 23:16:44 +0200https://ask.sagemath.org/question/8854/Symbolic variable declarationhttps://ask.sagemath.org/question/8251/symbolic-variable-declaration/what is the difference, when I declare variable like this
a, b, c = var('a, b, c')
or just like this
var('a, b, c')
?OndraSun, 31 Jul 2011 13:57:48 +0200https://ask.sagemath.org/question/8251/Difference between var('x') and x=var('x')?https://ask.sagemath.org/question/8145/difference-between-varx-and-xvarx/In some tutorials, when a variable is declared, it is done like,
var('x')
In some others, it is done like,
x = var('x')
What is the difference between the two, if any?
Also, is it better to ask this kind of basic question in the Asksage forum or the sage-support mailing list?
Thanks for your patience.omoplataFri, 17 Jun 2011 11:53:03 +0200https://ask.sagemath.org/question/8145/