ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 23 Sep 2017 15:17:13 -0500Output too long in SAGEhttp://ask.sagemath.org/question/38959/output-too-long-in-sage/I have a program whos output is too long to be displayed in the terminal where I run sage. Is there a possiblity that the output of SAGE is automatically "copied" (as if I mark it and use ctrl+c) and then I can paste it into a text file?
Or is there another way that the result can be automatically be saved into a text file or a way to make the terminal allow larger text before the text gets cut off?
Here the code Im talking about:
le_relations = lambda P: [(a,b) if P.le(a,b) else (b,a) for a,b in P.comparability_graph().edges(labels=None)]
cover_relations = lambda P: [(a,b) if P.le(a,b) else (b,a) for a,b in P.hasse_diagram().edges(labels=None)]
format_pt = lambda k: "'x{0}'".format(k+1)
format_relations = lambda relations: [[format_pt(a),format_pt(b)] for a,b in relations]
format_pts = lambda P: [format_pt(a) for a in P]
format_poset = lambda P: [format_pts(P), format_relations(cover_relations(P)), format_relations(le_relations(P))]
what_you_want = lambda n: [format_poset(P) for P in posets(n) if P.is_lattice]
print(what_you_want(8))
It takes about 20 minits for my computer to finish the calculation while the calculation seems to never finish in the online sage cell https://sagecell.sagemath.org/.
The code is from the thread https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/ )
edit: Another option would be to divide the set [format_poset(P) for P in posets(n) if P.is_lattice] into smaller pieces (lets say 5 pieces) and apply the code to those smaller pieces. The set contains 222 elements. Is there a way to apply the cod to the first 40 of those elements first and then I do it seperately for the next 40 and so on till I have all. Maybe it is possible to filter instead of posets(n) (for n=8) over just the first 40 posets of posets(n) and then the next 40 and so on.maresageSat, 23 Sep 2017 15:17:13 -0500http://ask.sagemath.org/question/38959/Show a multivariable function is nonvanishing when it is subject to constraintshttp://ask.sagemath.org/question/38950/show-a-multivariable-function-is-nonvanishing-when-it-is-subject-to-constraints/say we have a function $f:\mathbb R^3 \to \mathbb R$ given by
$f(x,y,z)=\sin(x)\sin(y)\sin(z)$
suppose further that there constraints $x,y,z \in (0, \pi/2)$ and $z>x+y$.
Clearly this function is nonvanishing with these constraints. Is there a way to get sage to show this? I've tried fiddling around, but I'm not sure how to do it.
I've tried
var('x,y,z')
assume(pi/2>x>0)
assume(pi/2>y>0)
assume(pi/2>z>x+y)
f=sin(x)*sin(y)*sin(z)
solve(f=0,x,y,z)
but this does not work ( I don't think I understand the solve function)Andres MejiaSat, 23 Sep 2017 09:56:19 -0500http://ask.sagemath.org/question/38950/Finding certain posets in SAGEhttp://ask.sagemath.org/question/38938/finding-certain-posets-in-sage/ Distributive lattices can be characterised as lattices having no sublattice isomorphic to the diamond or the pentagon (see for example https://en.wikipedia.org/wiki/Distributive_lattice ). Now I try to obtain in SAGE all connected posets with a global maximum and a global minimum that do not contain the diamond or the pentagon as a subposet. How to do that in SAGE in the quickest possible way?
And do such (maybe not necessarily connected) posets have a name or are enumerated in the OEIS?maresageThu, 21 Sep 2017 18:33:51 -0500http://ask.sagemath.org/question/38938/Finding all admissible ideals with SAGEhttp://ask.sagemath.org/question/38952/finding-all-admissible-ideals-with-sage/Let A=k[x,y,z] for a finite field k and let J=(x,y,z) be the ideal generated by x,y and z. Call an Ideal I of A r-admissible in case $J^r$ is contained in I and I is contained in $J^2$.
Can SAGE find all 4-admissible ideals for a given finite field (lets say with 2,3 or 5 elements for a start)? This is one of the easiest special cases of a more general problem, which is probably too hard and too slow for todays computer. But maybe SAGE can do it in principle? Note that this is a finite problem as it is equivalent to finding all ideals in $A/J^4$ that are contained in $J^2/J^4$, which are all finite rings. (More general it would be more interesting to do the same with A replaced by the non-commutative polynomial ring in x,y,z, which is the quiver algebra with 1 point and 3 loops)maresageSat, 23 Sep 2017 11:29:43 -0500http://ask.sagemath.org/question/38952/Weird resulting values with an exponential regressionhttp://ask.sagemath.org/question/34680/weird-resulting-values-with-an-exponential-regression/I have this model:
var('a,b')
R = [[100, 0.0489], [110, 0.0633], [120, 0.1213],[130, 0.1244], [140, 0.1569], [150, 0.1693], [160, 0.3154], [170, 0.6146], [180, 0.9118], [190, 01.7478], [200, 2.4523], [210, 4.7945], [230, 17.9766], [240, 29.3237], [250, 52.4374], [260, 94.6463], [270, 173.3447], [280, 396.0443], [290, 538.6976], [300, 1118.9984], [310, 1442.3694], [320, 4151.9089], [330, 6940.7322]]
model(x) = a*exp(b*x)
find_fit(R,model)
(which is the results of factorization time of an algorithm for people interested)
But I get weird values, obviously not in accordance with the points, when plotting all this. I was extremely surprised.
That's what I get:
[a=(2.3863359829×10^−15),b=1.0000000003]
Then I had the idea to try to get a formula with LibreOffice calc, just to have something to compare (I wasn't about to do this work on libreoffice initially), the result is different, but still so weird. In both cases, if I apply the formula given, it returns unthinkable values (very high).
Seems to be a problem with these values, no? Impossible to compute? Does sb have a solution? Thank you.Romuald_314Thu, 01 Sep 2016 09:50:40 -0500http://ask.sagemath.org/question/34680/Call error for integers (when I haven't declared any.)http://ask.sagemath.org/question/38945/call-error-for-integers-when-i-havent-declared-any/ I'm trying to define a pretty atrocious function (that I eventually want to solve for zeroes) in three variables, k,j,N.
I tried to just use
f=sin(2*k*2*pi/N)*sin((k+1)*2*pi/N)*sin((k-1)*2*pi/N)*sin((2*j+2)*2*pi/N)*sin^2(j*2*pi/N)*sin(6*pi/N)*sin(4*pi/N)*sin(2*pi/N)+sin(2*j*2*pi/N)*sin((j+1)*2*pi/N)*sin((j-1)*2*pi/N)*sin((2*k+2)*2*pi/N)*sin(k*2*pi/N)*sin(k*2*pi/N)*sin(6*pi/N)*sin(4*pi/N)*sin(2*pi/N)+sin((k-1)*2*pi/N)*sin((2*k+2)*2*pi/N)*sin(k*2*pi/N)*sin((2*j+2)*2*pi/N)*sin(j*2*pi/N)*sin(j*2*pi/N)*sin(12*pi/N)*sin(4*pi/N)*sin(2*pi/N)+sin((j-1)*2*pi/N)*sin((2*j+2)*2*pi/N)*sin(j*2*pi/N)*sin((2*k+2)*2*pi/N)*sin(k*2*pi/N)*sin(k*2*pi/N)*sin(12*pi/N)*sin(4*pi/N)*sin(2*pi/N)-sin((k-1)*2*pi/N)*sin((j-1)*2*pi/N)*sin((2*k+2)*2*pi/N)*sin((2*j+2)*2*pi/N)*sin(k*2*pi/N)*sin(j*2*pi/N)*sin(6*pi/N)*sin(2*pi/N)* sin(8*pi/N)-sin(12*pi/N)*sin(4*(pi/N))*sin(4*(pi/N))*sin((2*k+2)*2*pi/N)*sin((2*j+2)*2*pi/N)*sin(j*2*pi/N)*sin(j*2*pi/N)*sin(k*2*pi/N)*sin(k*2*pi/N)
but I'm getting:
TypeError: 'sage.rings.integer.Integer' object is not callable
why is this, I already had that
assume(k,'real')
assume(pi/2>k>0)
assume(j,'real')
assume(pi/2>j>0)
assume(N,'real')
assume(N>0)
so what can I do to fix this error?Andres MejiaFri, 22 Sep 2017 20:17:11 -0500http://ask.sagemath.org/question/38945/Stochastic block modelhttp://ask.sagemath.org/question/38929/stochastic-block-model/Hi all,
I would like to draw a random graph by Sage. The general stochastic model is the following: The graph contains $n$ vertices and the n vertices are divided into $r$ communities $C_1\cdots,C_r$. For two vertices within the same community, there is a probability $P_r$ that they are connected directly by an edge. How do I plot such a graph in Sage? References appreciated.Dianbin BaoThu, 21 Sep 2017 13:19:26 -0500http://ask.sagemath.org/question/38929/Obtaining lattices quickly in SAGEhttp://ask.sagemath.org/question/38936/obtaining-lattices-quickly-in-sage/At the moment I use
posets = [p for p in Posets(n) if p.is_connected() and p.is_lattice()]
to obtain all connected lattices via SAGE.
But this takes terrible long for n>=8. Is there a quicker way? It would somehow be natural when the connected lattices (or just connected posets) are saved in SAGE for some small n so that one does not have to filter trough the very large set of all posets. For example there are 53 connected lattices with 7 points , while there are 2045 posets on 7 points.maresageThu, 21 Sep 2017 15:52:33 -0500http://ask.sagemath.org/question/38936/Incidence algebras in QPA via SAGEhttp://ask.sagemath.org/question/38895/incidence-algebras-in-qpa-via-sage/This problem needs a little algebraic background. The input is a connected poset and the output should be the data needed to define the incidence algebra of the poset in QPA (a GAP package).
Here the algebraic background:
Given a connected poset P, the incidence algebra (over a feld $K$) is isomorphic to the quiver algebra $KQ/I$ (see https://en.wikipedia.org/wiki/Quiver_(mathematics) for background), where $Q$ is the Hasse quiver of the poset $P$ and $I$ an admissible ideal defined generated by the following relations: $w_1 - w_2$ where $w_1$ and $w_2$ are two paths in the path algebra $KQ$ starting and ending at the same points. The relation more or less mean that we have a commutativity relation at each small "rectangle" (or pentagon etc.) of the Hasse quiver of the algebra. So I is generated by those commutativity relations (of course each "bigger" rectangle then commutes automatically when each smaller rectangle commutes)
How the input should look like so that QPA can understand it and define the incidence algebra:
Q:=Quiver(5,[[1,2,"x12"],[2,4,"x24"],[2,3,"x23"],[4,5,"x45"],[3,5,"x35"]]);kQ:=PathAlgebra(Rationals,Q);AssignGeneratorVariables(kQ);rel:=[x24 * x45-x23 * x35];A:=kQ/rel; (*)
(More than one relation would look like this: rel:=[x24 * x45-x23 * x35, x24 * x45-x23 * x35]; so two relations are separeted by a comma , )
In this example the ouput is the incidence algebra of the poset 7 from the list http://math.chapman.edu/~jipsen/tikzsvg/planar-distributive-lattices15.html (with 1 the lowest element).
I failed to program this in GAP but maybe there is an easy way doing this using SAGE? The advantage could also be to use SAGE to generate all posets on n elements (a thing which GAP can not do) and then calculate the above forms (*) of those posets. Then I would use the data to put it in to GAP and obtain the incidence algebras. (GAP can do things which SAGE probably can not do, like calculate the indecomposable modules in case the algebra has finite representation type)
So to make it clear: The problem is only about getting a poset in SAGE into the form in (*) and then I want to copy this form into GAP (more precisly the GAP package QPA) and continue working there with incidence algebra. While the algebras are isomorphic and just in another form , it is essential to work with QPA and view the indicence algebra as a quiver algebra.
Since this a somewhat harder program probably, I offer a twenty Euro prize money for a quick programm that works to give incidence algebras in SAGE. First quick program wins. Payment via paypal or Ama zon gift card. My motivation is to test some theoretical obtained results.
See page 8 of https://folk.ntnu.no/oyvinso/QPA/manual.pdf for the definition of quiver algebras in QPA for more details.
edit: The code should be able to do two things (the first is more or less a special case of the second):
1. Given a specific poset, the code should give the output in the form (*).
2. Given a set of posets (for example all connected posets on 5 points or similar things), the code should put them in the form (*) but if the set contains n elements the output should enumerate them. For example the output should be in the form (in case the set contains the 2 posets as defined below)
L:=[];
Q1:=Quiver(5,[[1,2,"x12"],[2,4,"x24"],[2,3,"x23"],[4,5,"x45"],[3,5,"x35"]]);kQ1:=PathAlgebra(Rationals,Q1);AssignGeneratorVariables(kQ1);rel1:=[x24 * x45-x23 * x35];L[1]:=[Q1,kQ1/rel1];
Q2:=Quiver(4,[[1,2,"x12"],[2,4,"x24"],[1,3,"x13"],[3,4,"x34"]]);kQ2:=PathAlgebra(Rationals,Q2);AssignGeneratorVariables(kQ2);rel2:=[x12 * x24-x13 * x34];L[2]:=[Q2,kQ2/rel2];
so the empty list L gets filled with entries L[1] and L[2] so at the end we have a list L with the two incidence algebras (together with the underlying Hasse quivers Q1 and Q2)L[1] and L[2] in QPA after having copied the SAGE output into QPA.maresageWed, 20 Sep 2017 16:49:28 -0500http://ask.sagemath.org/question/38895/how to plot a circle (without circle())http://ask.sagemath.org/question/38889/how-to-plot-a-circle-without-circle/ Hello,
I know you can plot a circle with circle(x,y,radius), but how do you do it with plot()?germacWed, 20 Sep 2017 15:43:54 -0500http://ask.sagemath.org/question/38889/eigenvector corresponding to largest eigenvaluehttp://ask.sagemath.org/question/38913/eigenvector-corresponding-to-largest-eigenvalue/I have tried this code to find the eigenvector corresponding to eigenvalue 3.732050807568878. But it is not giving the result.
A = matrix( AA, 6,6, [2,1,0,0,1,0, 1,2,1,0,0,0, 0,1,2,1,0,0, 0,0,1,1,0,0, 1,0,0,0,2,1, 0,0,0,0,1,1] )
E = matrix.identity( A.nrows() )
n=A.eigenvalues()
n.sort()
print n
k=( A -3.732050807568878*E ).kernel().basis()
print k
AThu, 21 Sep 2017 09:51:55 -0500http://ask.sagemath.org/question/38913/Is it possible to implement ENDOHECKE IN SAGEhttp://ask.sagemath.org/question/38912/is-it-possible-to-implement-endohecke-in-sage/ Alex Brown and Eknath Ghate implemented Endohecke. The links are here:
Is it possible to implement the programme in SAGE?
Many thanks for your kind help. debarghaThu, 21 Sep 2017 05:25:47 -0500http://ask.sagemath.org/question/38912/Obtaining all posets in a certain form with SAGEhttp://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/I want to do certain calculation with posets using GAP. But GAP has no package for posets so I want to use SAGE first to generate all connected posets with a certain number of points and then use the data in GAP.
The output of posets in SAGE should have the form ["x1","x2","x3","x4"],[["x1","x2"],["x1","x3"],["x3","x4"],["x2","x4"]] so that I can use them in GAP. Here the poset has 4 elements x1,x2,x3 and x4 and ["x1","x2"] means that x1 is smaller than x2 etc.
So I want the following with SAGE:
Input: A number $n \geq 2$.
Output: The list of all connected posets with $n$ elements displayed in the form (this is an example) ["x1","x2","x3","x4"],[["x1","x2"],["x1","x3"],["x3","x4"],["x2","x4"]].
edit: Thank you very much for the two answers. Sadly I cannot comment at the moment directly without approvial of a moderator. Your codes solve my problem in a perfect way expect that the outputs have a ' where there should be a " so that GAP can understand it. (example: instead of ['x1', 'x2', 'x3', 'x4'], [['x1', 'x2'], ['x1', 'x3'], ['x1', 'x4'] the first element should look like ["x1", "x2", "x3"], [["x1", "x2"], ["x1", "x3"]]).maresageWed, 20 Sep 2017 03:02:17 -0500http://ask.sagemath.org/question/38865/How to obtain all finite connected distributive lattices with SAGEhttp://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/In https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/ I asked for a programm that translates all finite posets into a given form.
Now I want to do the same with all finite connected distributive lattices instead of all connected posets.
First I wanted it with all lattices, I changed the code
posets = [ p for p in Posets(n) if p.is_connected() ]
into posets = [ p for p in Posets(n) if p.is_connected() and p.is_lattice]
This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html#) I get an error when I try
into posets = [ p for p in Posets(n) if p.is_connected() and p.is_lattice() and p.is_distributive()]. How to fix that?
And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?
Another question: I want to use the SAGE output of this to define a list in GAP. The problem is that I cannot directly copy paste since GAP allows me to define a list only in case the list occupies only one line.
(for example
[ [["x1", "x2", "x3"], [["x1", "x2"], ["x1", "x3"]] ],
[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],
[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]
is not ok for GAP but [ [["x1", "x2", "x3"], [["x1", "x2"], ["x1", "x3"]] ], [["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]], [["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]] is ok when it is in one line).
Is there a way to obtain the SAGE output in one line or is there a textmanager that can do such a thing? (this is a problem in case the SAGE output is very long)
edit: For my second problem I found the website https://www.textfixer.com/tools/remove-line-breaks.php to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.maresageWed, 20 Sep 2017 12:59:36 -0500http://ask.sagemath.org/question/38878/connecting plots by lineshttp://ask.sagemath.org/question/38845/connecting-plots-by-lines/There are 2 plots in a graphics_array (e.g. sin and cos). How do I "connect" these plots with connecting lines (e.g. a dashed line at angle=pi)?Chris_Mon, 18 Sep 2017 08:21:55 -0500http://ask.sagemath.org/question/38845// acting like // ?http://ask.sagemath.org/question/38853/acting-like/ This script is meant to simulate rolling a fair die until a 6 occurs. I don't understand why at the very end my division of the sum of the rolls by the number of rolls is coming out the way it does. Thanks for your attention.
a=0;l=[];count=0;b=[]
while count < 11:
while a<6:
a=choice([1..6])
l.append(a)
print l
count+=1
b.append(len(l))
a=0;l=[]
s=sum(b);t=len(b)
print "b= ",b,"Sum=",sum(b),"Throws=",len(b),"Sum/Throws=",s,"/",t,"=",s/t,N(s/t)
print "Average over",len(b),"trials is",(sum(b)/len(b))
print "The type of sum(b) is",type(sum(b)),"The type of len(b) is",type(len(b))Ducky47Tue, 19 Sep 2017 06:35:50 -0500http://ask.sagemath.org/question/38853/Jupiter and notebook start problemhttp://ask.sagemath.org/question/38844/jupiter-and-notebook-start-problem/ I am running MacOSX 10.11.6.
After update to Sage 8.0 there is a problem to start Jupiter or the notebook server. Here some terminal output:
Benutzers-Air:~ Benutzer$ '/Applications/SageMath-8.0.app/Contents/Resources/sage/sage' --notebook=sagenb
/Applications/SageMath-8.0.app/Contents/Resources/sage/src/bin/sage-env: line 428: 17594 Trace/BPT trap: 5 "$SAGE_LOCAL/bin/python" -c 'import pkg_resources; pkg_resources.get_distribution("matplotlib").version' 2> /dev/null
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.0, Release Date: 2017-07-21 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
Please wait while the old SageNB Notebook server starts...
dyld: lazy symbol binding failed: Symbol not found: _getentropy
Referenced from: /Applications/SageMath-8.0.app/Contents/Resources/sage/local/lib/libpython2.7.dylib
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _getentropy
Referenced from: /Applications/SageMath-8.0.app/Contents/Resources/sage/local/lib/libpython2.7.dylib
Expected in: /usr/lib/libSystem.B.dylib
wbelauMon, 18 Sep 2017 08:16:35 -0500http://ask.sagemath.org/question/38844/Rewrite equilibrium variables in terms of another variablehttp://ask.sagemath.org/question/38835/rewrite-equilibrium-variables-in-terms-of-another-variable/I'm wondering how to replace the equilibrium variables in terms of another one. I want the equilibrium to be in terms of a new varible called R = beta*o/(u+y)(u+o) and I can't seem to find the right function that would allow me to do this.
Equilibrium point: S= (u+y)(u+o)/beta*o
Want: S = 1/R
kaylavb23Sun, 17 Sep 2017 17:05:33 -0500http://ask.sagemath.org/question/38835/sage LD_LIBRARY_PATHhttp://ask.sagemath.org/question/38842/sage-ld_library_path/ I wrote a C++ library and the related python bindings, and I would like to make use of them from sage. But whatever I try, I cannot get sage to load the library. Here is what I tried:
1) FIRST ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"
However, when I try to import from a jupyter notebook:
import mylib.mymodule.mysubmodule
I get the error:
ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n
I only could find one reference (ticket 22006 on trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install `libopenblas-dev` did not work for me). Note that `mylib` does not depend in any way on BLAS.
2) SECOND ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
But the library cannot be found this way:
ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
3) THIRD ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
This results in the same import error as in SECOND ATTEMPT.
4) FOURTH ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
Now the library finally got loaded, but it cannot find its dependencies.
ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
THE QUESTION
What is the proper way to make sage resolve a custom library and its dependencies? I understand that sage tries to isolate itself as much as possible from the system, and I have also read that there is some "magic" going on to adjust environment variables: this seems to cause the problem (1).
ADDITIONAL INFO
Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:
apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary
Note that everything works as expected when using the library from the system python console.matpenMon, 18 Sep 2017 03:15:57 -0500http://ask.sagemath.org/question/38842/Generating Tikz codes from Sage for drawing scattering points in 3Dhttp://ask.sagemath.org/question/38837/generating-tikz-codes-from-sage-for-drawing-scattering-points-in-3d/I am a beginner in Sage and Tikz, and have written the following snippet of Sage code:
P = Polyhedron(ieqs=[(30, -2, -2, -1), (25, -1.5, -2, -3),(20,-2,-1,-1), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)])
pts = P.integral_points()
point3d(pts,rgbcolor=(1,0, 0), size=10) + P.plot(rgbcolor = 'yellow', opacity = 0.5)
The purpose of the codes is to generate the integral points interior to the polytopes bound by 6 inequalities as given in the codes. The output is in the following link:
www.cse.cuhk.edu.hk/~jlee/dots.png
I tried to follow the following reference:
doc.sagemath.org/html/en/thematic_tutorials/polytope_tikz.html
to generate Tikz codes for LaTeX and failed. Unlike Polyhedron which is a kind of object that can respond to "projection", point3d generates only a Graphics3D object which doesn't understand "projection".
Is there any way to output these points to Tikz?
Also, is it possible to ask Sage to color each of the facets of the polytope in different colors (just like Tikz can)?
Many thanx in advance!jimSun, 17 Sep 2017 19:20:01 -0500http://ask.sagemath.org/question/38837/How to get Polynomial Coefficientshttp://ask.sagemath.org/question/38824/how-to-get-polynomial-coefficients/ Hi
I would like to get the value of coeffs of x^5 + p*x^3 + q*x^2 + r*x + s
something like [1,0, b - 2/5*a^2,...]
I do not understand what means the coefficients() outputs in the code below ??
forget()
import math
for v in var( 'a,b,c,d,e' ): assume( v, 'rational' )
for v in var( 'p,q,r,s' ): assume( v, 'rational' )
x = PolynomialRing(RationalField(), 'x').gen()
t = PolynomialRing(RationalField(), 't').gen()
Pt= t^5 + a*t^4 + b*t^3 + c*t^2 + d*t + e
vChgt=t==x-a/5
P=Pt.substitute(vChgt)
#Px= x^5 + p*x^3 + q*x^2 + r*x + s
show(P.factor())
show(P.factor().coefficients(sparse=False))
show(P.factor().list())
P.factor()
ortolljSun, 17 Sep 2017 10:52:54 -0500http://ask.sagemath.org/question/38824/Sage Range functionhttp://ask.sagemath.org/question/38825/sage-range-function/ I use sage range function to print numbers form 1 to say 10 using print [1..10]. How to print only even numbers using this?ManojSun, 17 Sep 2017 12:49:48 -0500http://ask.sagemath.org/question/38825/solution to logistic differential y'=r*y*(1-y)/bhttp://ask.sagemath.org/question/38822/solution-to-logistic-differential-yry1-yb/How to solve this logistic differential in sage?
y=function('y')(x)
(b,r,y0)=(30,0.8,1.5)
de=diff(y,x)==r*y*((1-y)/b) # logistic equation
soln=desolve(de,y,ics=[0,y0])
mathematica solution is: `y(x)=(b*exp(r*x)*y0)/(exp(r*x)*y0-y0+b)`
Other questions/answers found on the logistic topic were not helpful for this problemmeirsamelFri, 15 Sep 2017 14:37:47 -0500http://ask.sagemath.org/question/38822/Why does underscore for last output not work in worksheets uploaded from local SageMath to Cocalc?http://ask.sagemath.org/question/38820/why-does-underscore-for-last-output-not-work-in-worksheets-uploaded-from-local-sagemath-to-cocalc/My commands are like this:
vector([x1,y1,z1])
r1 = _
And I get this message:
Error in lines 1-1
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
NameError: name '_' is not defined
However, copying and pasting commands into a new worksheet make that feature work again. Why?
I have links to illustrate it, but my karma is insufficient to post them here.
Leo Luiz CastroFri, 15 Sep 2017 07:24:23 -0500http://ask.sagemath.org/question/38820/Line graph of a given graphhttp://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/I tried this code in sage. But in the output the vertex labelling of the desired line graph gets overlapped and hece the graph is not clearly visible. Can I improve the code so that the line graph is clearly visible without overlapping.
G=graphs.EmptyGraph()
G.add_edges([(2,3),(2,4),(2,1),(1,5),(5,6),(1,0),(0,12),(0,13),(14,0),(15,0),(7,0),(7,10),(11,7),(7,9),(7,8)])
G.show()
h = G.line_graph()
h.show()AThu, 14 Sep 2017 05:38:12 -0500http://ask.sagemath.org/question/38814/Symbolic to numerical arrayhttp://ask.sagemath.org/question/38811/symbolic-to-numerical-array/ I would like to get a number-valued array from a symbolic-valued array, for example:
( sin(1), cos(1), pi/4) to ( sin(1).n() , cos(1).n() , pi/4.n() )
WITHOUT having to convert one component at a time, but directly transforming the array. When I write
( sin(1), cos(1), pi/4 ).n()
I get 'Error'. I would greatly appreciate any help :)daniel-Ri-1011101Wed, 13 Sep 2017 09:56:12 -0500http://ask.sagemath.org/question/38811/How to color a 3d plot by z-level?http://ask.sagemath.org/question/8964/how-to-color-a-3d-plot-by-z-level/I'd like to color a 3d plot based on z-level. I think this is easy to do in Maple or Mathematica, but I've been searching the web for help on doing this in Sage and can't find anything to help with plot3d or implicit_plot3d.
Here's the implicit_plot3d I'm using.
var('x,y,z')
implicit_plot3d(x^2-y^2*z == 0,(x,-4,4),(y,-4,4),(z,-4,4)).show(mesh=True)
Also, are there color maps in Sage that produce plots with colors and lighting similar to the default in Mathematica?
calc314Wed, 09 May 2012 16:27:40 -0500http://ask.sagemath.org/question/8964/use a colormap for implicit_plot3dhttp://ask.sagemath.org/question/7581/use-a-colormap-for-implicit_plot3d/Here's a question I asked a while ago on sage-support, but never got answered, so I'll try it again here:
I've been trying to figure out how to plot a surface using
`implicit_plot3d`, and color it according to a particular color map. I
see that `implicit_plot3d` passes its arguments to
`sage.plot.plot3d.implicit_plot3d.ImplicitSurface`
but I can't figure out more than this . . . when I try
`sage: sage.plot.plot3d.implicit_plot3d.ImplicitSurface??`
I get
`Error getting source: could not find class definition`
and then a few more unhelpful details.
It seems like the two possible viewers are jMol and Tachyon, but I
can't tell whether either of these support color maps.
Any ideas where else I should be looking?
Update: This is now Trac ticket 12212nilesThu, 19 Aug 2010 00:26:08 -0500http://ask.sagemath.org/question/7581/Python 3 print in Sagehttp://ask.sagemath.org/question/38805/python-3-print-in-sage/ This is a minor issue, but I've long migrated all my Python scripts to Py3, so I'm trying to write in Sage in the most Py3-compliant way possible, since we'll have Py3 support in a not-so-distant future according to the FAQs (frankly I'm a bit surprised that Py3 support haven't already happened, but, oh well).
Anyway, because of that I put `from __future__ import print_function, division` in the very first line of my `init.sage`.
If I type things interactively in the prompt, it works as it's supposed to:
sage: print('C_r' ,6)
C_r 6
However, if I run a script with `load('my_script.sage')` it prints things as if I was using Py2.
('C_r', 6)
Am I loading my scripts wrong? How can I get it to work for scripts too?
Cheers.tomchoTue, 12 Sep 2017 11:40:04 -0500http://ask.sagemath.org/question/38805/plot sage Graphics() from jupyter notebok in CoCalchttp://ask.sagemath.org/question/38759/plot-sage-graphics-from-jupyter-notebok-in-cocalc/I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:
from sage.all import *
var('x')
plot(sin(x)).show()
This code outputs "Graphics object consisting of 1 graphics primitive".
Pyplot plotting works fine.
There are a number of old posts with the similar problem ( ex. https://ask.sagemath.org/question/10988/in-line-graphics-for-sage-in-ipython-notebook/), some of them recommend changing matplotlib backend with %matplotlib inline which does not help.
Is there a way to output sage Graphics() inline without using pyplot?ADuC812Fri, 08 Sep 2017 07:24:35 -0500http://ask.sagemath.org/question/38759/