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.Fri, 26 Oct 2018 13:24:48 -0500How to read and run commands from a text file?http://ask.sagemath.org/question/44086/how-to-read-and-run-commands-from-a-text-file/I have all my commands in a text file, and I would just like to run them in Sage. What is the easiest way to do this?
For example, in sage.txt, I have written:
d0=matrix(ZZ,4,4,{(0,0):1,(2,0):1,(1,1):1,(3,1):1,(1,2):1,(3,2):1});
d1=matrix(ZZ,4,4,{(1,0):-1,(2,0):-1,(3,1):-1,(1,2):1,(2,2):1,(3,3):1});
The command `with open('/home/sage.txt','r') as ll: bdrs=[sage_eval(l.strip()) for l in ll];` returns
File "<string>", line 1
d0=matrix(ZZ,Integer(4),Integer(4),{(Integer(0),Integer(0)):Integer(1),(Integer(2),Integer(0)):Integer(1),(Integer(1),Integer(1)):Integer(1),(Integer(3),Integer(1)):Integer(1),(Integer(1),Integer(2)):Integer(1),(Integer(3),Integer(2)):Integer(1)});
^
SyntaxError: invalid syntax
Also, does Sage have a limit on how much RAM it can use? If yes, how can I increase the available memory?LeonFri, 26 Oct 2018 13:24:48 -0500http://ask.sagemath.org/question/44086/Read from csv-file, write results in new columns in the same csv-filehttp://ask.sagemath.org/question/39845/read-from-csv-file-write-results-in-new-columns-in-the-same-csv-file/Hi,
I am currently trying to achieve the following:
given a csv-file e.g. like
x,y,sinx,siny
30,45,,
60,90,,
Values for x and y are given in degree.
What I want to do: take the data from the csv-file, calculate sin(x) and sin(y) for the values given in each row and then print the result in the corresponding cell. If possible, do not round the result, so the output should look something like this:
x,y,sinx,siny
30,45,1/2,sqrt(2)/2
60,90,sqrt(3)/2,1
Taking this one step further, if possible the output should be printed in complete LaTeX-code because the date from the csv-file will be used in a LaTeX-document, so the best possible result would be:
x,y,sinx,siny
30,45,\frac{1}{2},\frac{\sqrt{2}}{2}
60,90,\frac{\sqrt{3}}{2},1
I do know about sageTex which is able to do this, but for other reasons I can't use sageTex for my problem.
I am completely new to sage, so I don't know if there is a standard procedure for this or if it is possible at all. Any input is appreciated!
HirshyThu, 30 Nov 2017 06:43:11 -0600http://ask.sagemath.org/question/39845/Export Answer To Text Filehttp://ask.sagemath.org/question/37745/export-answer-to-text-file/Hello,
I have read the available suggestions and they did not work.
I would like to output the number generated by 2^1000 to a text file so that I can import to my C++ program.
Please help me along. happys5Tue, 30 May 2017 19:18:16 -0500http://ask.sagemath.org/question/37745/write output of for loop in pari to filehttp://ask.sagemath.org/question/32491/write-output-of-for-loop-in-pari-to-file/Hi all,
I would like to write the output of a for loop in Pari to a file named 'foo', However the output of a for loop has no numbering contrast with other output. If I look at the numbers labeling the outputs before and after the for loop and use that number in the following command
\w n foo
Then what I get in foo is 0. What happened and how can this be fixed?
Dianbin BaoSun, 07 Feb 2016 20:36:16 -0600http://ask.sagemath.org/question/32491/