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, 21 Jul 2021 21:56:59 +0200Only the most basic stuff neededhttps://ask.sagemath.org/question/58075/only-the-most-basic-stuff-needed/I installed sage years ago, and it worked with simple computations like sum from to .. combinations of well known functions.
Now I seem to have forgotten totally how to use it.
As I remember I only used comand line, not sure if inside sage, or the usual terminal of this linux system.
So I need to get the most basic info.
1. How to Sage install on linux (maybe not needed, because it was installed)
2. How to run it.
3. How to type a command to make a basic computation.
I can't see anything anywhere which resembles math.
I only see computer instructions which seem to be written for CS experts.
basicWed, 21 Jul 2021 21:56:59 +0200https://ask.sagemath.org/question/58075/How to solve an equation over finite field?https://ask.sagemath.org/question/48835/how-to-solve-an-equation-over-finite-field/ I would like to solve an equation like
solve( ((k^2)%17)==8,k)
or
R = GF(17)
solve(R(k)^2==8,k)
or as math equation: $k^2 \equiv 8 \mod 17$
This would be true for e.g. $k=5$
If I use the solve function above in sagemath I get an empty result $[]$ for first and 'self must be a numeric expression' for second.
How can I solve such equation?maanThu, 21 Nov 2019 13:41:43 +0100https://ask.sagemath.org/question/48835/How to find a short form of recursive defined sequences?https://ask.sagemath.org/question/48820/how-to-find-a-short-form-of-recursive-defined-sequences/Hi, I'm new to sagemath.
Is there any way to so calculate/solve/find a short version of a recursive defined sequence?
E.g. I have a sequence like: (Fibonacci)
def f(n):
if n == 0:
return 0
if n == 1:
return 1
if n == 2:
return 1
else:
return f(n-1)+f(n-2)
How can I compute a short form of $f_n$?
-----
In this example case $f_n$ would be:
$f_n=\frac{1}{\sqrt{5}} (\frac{1+\sqrt{5}}{2})^n - \frac{1}{\sqrt{5}} (\frac{1-\sqrt{5}}{2})^n$
-----
Edit:
Thanks to Emmanuel I found how to solve those equations in pdf:
from sympy import Function,rsolve
from sympy.abc import n
u = Function('u')
f = u(n-1)+u(n-2)-u(n)
rsolve(f, u(n), {u(0):0,u(1):1})
-sqrt(5)*(1/2 - sqrt(5)/2)**n/5 + sqrt(5)*(1/2 + sqrt(5)/2)**n/5maanWed, 20 Nov 2019 17:33:55 +0100https://ask.sagemath.org/question/48820/How to create a "sage program" with command line inputhttps://ask.sagemath.org/question/44708/how-to-create-a-sage-program-with-command-line-input/I am completely new to Sage and Pyhton, so this is probably a very trivial question, but I am not able to find any answer. I have a file script.sage
N=10
sage_command1
sage_command2
sage_command3
print(result)
I use this script via `sage script.sage` and it does what I want. How can I modify this so that I can pass the variable `N` in the command line? Something like `sage script.sage 10` and then it prints the result.
Thank you!RiccardoTue, 18 Dec 2018 23:35:35 +0100https://ask.sagemath.org/question/44708/Sage % symbolhttps://ask.sagemath.org/question/37243/sage-symbol/I am a beginner to Sage. During learning Sage I found a code snippet here
for i in range(5):
print('%6s %6s %6s' % (i, i^2, i^3))
Can anybody explain why `%()` is used here ?lalthomasMon, 10 Apr 2017 06:17:36 +0200https://ask.sagemath.org/question/37243/line numbers in web notebookhttps://ask.sagemath.org/question/31926/line-numbers-in-web-notebook/I use Sage in my Mozilla Firefox browser as notebook and wanted to know how i get line numbers in my computing cells.bruno171092Thu, 31 Dec 2015 00:24:48 +0100https://ask.sagemath.org/question/31926/Multiplicities of solutions not showing up correctlyhttps://ask.sagemath.org/question/31420/multiplicities-of-solutions-not-showing-up-correctly/I am trying to find the roots of the following
f = -54.0*I*x**27 + (-202.5 - 584.567147554496*I)*x**15 + (1.62379763209582 + 2.0625*I)*x**3
using the command
sols, mults = solve(f ,x, multiplicities=True)
but the answer I get is wrong, because there should be 27 roots, of which x=0.0 should have multiplicity 3 and all the other should have multiplicity 1. This is what I get instead:
([x == 1/4*2^(3/4)*(sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + I*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(I*sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + (-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/2*I*2^(3/4)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 1/4*2^(3/4)*(I*sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - (-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/4*2^(3/4)*(sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - I*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/2*2^(3/4)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == -1/4*2^(3/4)*(sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + I*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(-I*sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - (-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/2*I*2^(3/4)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 1/4*2^(3/4)*(-I*sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + (-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(sqrt(3)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - I*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/2*2^(3/4)*(-1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 1/4*2^(3/4)*(sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + I*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(I*sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + (1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/2*I*2^(3/4)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 1/4*2^(3/4)*(I*sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - (1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/4*2^(3/4)*(sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - I*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/2*2^(3/4)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == -1/4*2^(3/4)*(sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + I*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(-I*sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - (1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == -1/2*I*2^(3/4)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 1/4*2^(3/4)*(-I*sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) + (1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/4*2^(3/4)*(sqrt(3)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12) - I*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12)), x == 1/2*2^(3/4)*(1/30773305171191*I*sqrt(1232006789381660639610346922212*I - 1564858793284486386236895596057) + 15*I - 189750626/4382103)^(1/12), x == 0], [1, 1])
Is this a bug? Or am I doing something wrong?
physicistTue, 08 Dec 2015 23:49:34 +0100https://ask.sagemath.org/question/31420/A basic questionhttps://ask.sagemath.org/question/10075/a-basic-question/Hi,
I have a basic question. I don't know how to get the desired result. I am solving following problem.
var('x1','x2')
f1 = exp((2*x1+1))^2/997383793764
f2 = exp((2*x2+2)^2/8726621367521)
f = f1*f2
d = f.substitute(x1=0,x2=0)
I get an answer in the form d = e^(89324832445632473/89327467832433434646786)
How can I convert my answer (e^(89324832445632473/89327467832433434646786)) to a rational number (P/Q) that don't involve any 'e'? assadabbasiMon, 29 Apr 2013 04:17:01 +0200https://ask.sagemath.org/question/10075/sage version of python's execfilehttps://ask.sagemath.org/question/9894/sage-version-of-pythons-execfile/What is the sage analogue of python's "execfile()"? How do I ask sage to preprocess and execute a text file full of sage commands?
Up till now I've just been using execfile() on the sage command line prompt, because that's what I do in python sometimes. However I just learned the hard way that this is the wrong thing to do; it misses a vital preprocessing step. For example, if I ask for the type of 1/2 on the sage command line, the following happens:
sage: print type(1/2)
<type 'sage.rings.rational.Rational'>
Great! that's what I want. However if I put the following into the file "uhoh.py":
print type(1/2)
and then I issue the following command on the sage command line:
execfile("uhoh.py")
then I get the output
<type 'int'>
Yes, the integer 1/2. I want the last hour of debugging time back.
Of course what's happening is that the text file is being interpreted in pure python, in which 1/2 really does represent an integer division. What is the right thing to do here, rather than execfile()?Benjamin YoungThu, 07 Mar 2013 20:24:57 +0100https://ask.sagemath.org/question/9894/Using the solution of a linear system, and splitting a matrixhttps://ask.sagemath.org/question/8925/using-the-solution-of-a-linear-system-and-splitting-a-matrix/Hi there,
I'm fairly new to Sage and Python, so I'm getting into basic problems here that I'd be happy if you could help me out.<br>
Here it is, actually, here they are:
I'm generating a set of equalities and solving them with solve. A simple example:
<blockquote> import numpy as n;<br>m=4;<br>
s = list(var('s_%d' % int(i)) for i in range(m));<br>
eqns=[s_0+s_1==1,s_2-s_3==0];<br>
sol=solve(eqns,s,solution_dict=True)[0]
</blockquote>
This gives the solutions:
<blockquote>
{s_1: -r2 + 1, s_0: r2, s_3: r1, s_2: r1}
</blockquote>
My first question is, how do I create a matrix with the solutions? Say, something like:
<blockquote>M=m.zeros((2,2));<br>
for i in range(2):<br>
for j in range(2):<br>
M[int(i),int(j)] = sol[s[i]]+ sol[s[j+2]]
</blockquote>
This is giving me the error: "TypeError: unable to simplify to float approximation"
My second question, would be, given the array M, how do I split it as r1 times a matrix, plus r2 times another matrix, plus a constant matrix? In the above example,
<blockquote> M= [[1,r1+r2],[r1-r2+1,r1-r2+1]]= r1 [[0,1],[1,1]] + r2 [[0,1],[-1,-1]]+ [[1,0],[0,0]]
</blockquote>
I'm interested in the matrices multiplying the still unknown coefficients. Maybe I should add that the number of equations in the problem I'm solving is much bigger than in this simple example, and therefore I cannot find this matrix decomposition by simply looking at it.<br>
Thanks for the help!
fmeloWed, 25 Apr 2012 09:56:14 +0200https://ask.sagemath.org/question/8925/exponent of a primehttps://ask.sagemath.org/question/8685/exponent-of-a-prime/I am newbie in SAGE and here. My apologies for any mistake. This is an easy question.
Is there a command that for an integer $m$ and a prime number $p$ returns the exponent of $p$ in $m$?
If not, I would like if the following definition can be improved.
def exponent(p,m):
v=m
sol=0
while v%p==0:
v=v/p
sol=sol+1
return sol
Thanks.emiliocbaTue, 31 Jan 2012 17:00:19 +0100https://ask.sagemath.org/question/8685/where is basic tutorial for sagehttps://ask.sagemath.org/question/8660/where-is-basic-tutorial-for-sage/Where is basic tutorial for sage showing basics like how to define set, variable, map, binary operations and such.run88Sun, 22 Jan 2012 20:28:18 +0100https://ask.sagemath.org/question/8660/basic algebra with several variables-why won't it work?https://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/Hi,
I'm trying to use Sage-Notebook as a basic calculator and want to do some basic algebra for two variables. However, it keeps giving me syntax error messages when I type in the below. What am I doing wrong?
x, y = var('x, y')
solve([20*(6400-x-2y)==0, 80*(3200-x-y)==0], x, y)
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Thank you!HunMon, 26 Sep 2011 19:12:19 +0200https://ask.sagemath.org/question/8317/How to get more uniform output from full_simplifyhttps://ask.sagemath.org/question/8169/how-to-get-more-uniform-output-from-full_simplify/I do this,
sage: var('x1,t1,x2,t2,u,c',domain=RR);assume(u>0);assume(c>0);assume(c>u);
(x1, t1, x2, t2, u, c)
sage: T1 = (t1-((u*x1)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: T2 = (t2-((u*x2)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: dT = T2-T1
sage: view(dT.full_simplify())
And I get,
$\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{\sqrt{c - u} \sqrt{c + u} {\left(c^{2} t_{1} - c^{2} t_{2} - u x_{1} + u x_{2}\right)}}{c^{3} - c u^{2}}$
I put this expression in which is supposed to be the same,
sage: s = ((t2-t1)-((u/(c^2))*(x2-x1)))/sqrt(1-((u^2)/(c^2)))
sage: view(s.full_simplify())
And get this,
$\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{c^{2} t_{1} - c^{2} t_{2} - u x_{1} + u x_{2}}{\sqrt{c - u} \sqrt{c + u} c}$
It is not immediately apparent to me that dT and s are the same. But they are both equal as can be seen by,
sage: (s-dT).full_simplify()
0
This is something minor, but is there something I can do to get a simplified expression which is more uniform every time I use full_simplify()?
Thanks.omoplataSat, 18 Jun 2011 18:24:03 +0200https://ask.sagemath.org/question/8169/Has anyone looked at nltk in Sage?https://ask.sagemath.org/question/8179/has-anyone-looked-at-nltk-in-sage/The "natural language toolkit", aka nltk, has a home page [here](http://www.nltk.org/) and FAQ [here](http://www.nltk.org/faq). I'm just curious if anyone has spent any time working with it within Sage?jekTue, 21 Jun 2011 20:29:38 +0200https://ask.sagemath.org/question/8179/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/Complex forms and differentialshttps://ask.sagemath.org/question/8060/complex-forms-and-differentials/Can Sage handle complex differential forms and the \partial and \bar\partial operators? I tried naively defining the d-bar operator before as (in Latex) \bar d \bar u, but I got an error saying that conjugation wasn't defined for the differential form class. Is there a way of handling this other than defining the real and imaginary parts of all variables and brutally defining the \partial and \bar\partial operators?GunnarWed, 06 Apr 2011 14:34:59 +0200https://ask.sagemath.org/question/8060/unable to numerically solve an equation (basic question)https://ask.sagemath.org/question/8043/unable-to-numerically-solve-an-equation-basic-question/Hello,<br>
I make my first steps with sage and already run into a problem I was not able to solve. When I enter the following:
reset()
var('x')
eqn=x^2+3*x-9==0
sol=solve(eqn,x,solution_dict=true)
sol[x].n(30)
I get the following error message:
The error message is: ('EOF in multi-line statement', (12, 0))
TypeError Traceback (most recent call last)
/home/.../sage-4.6.2/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
/home/.../sage-4.6.2/local/lib/python2.6/site-packages/sage/misc/preparser.pyc in load(filename, globals, attach) <br>
1594 execfile(fpath, globals)<br>
1595 elif fpath.endswith('.sage'):<br>
-> 1596 exec(preparse_file(open(fpath).read()) + "\n", globals)<br>
1597 elif fpath.endswith('.spyx') or fpath.endswith('.pyx'):<br>
1598 import interpreter<br>
/home/.../sage-4.6.2/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
/home/.../sage-4.6.2/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__index__ (sage/symbolic/expression.cpp:16771)()
/home/.../sage-4.6.2/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:4254)()
TypeError: unable to convert x (=x) to an integer
I added the "..." manually for this post.
Obviously I make a severe problem in getting the numerical solution of this simple equation. Maybe you can help me in getting a numerical solution for an equation.
Btw. I get the same error message when I try the example given in the sage tutorial on page 14 ([[s[p].n(30),.....)
Thanks in advance!
donCSat, 02 Apr 2011 09:42:50 +0200https://ask.sagemath.org/question/8043/block_matrix confusion (matrix constructor rewrite in new versions of Sage)https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/**Solved - My mistake - I was running an older version of Sage**
I'm having trouble making use of the block_matrix function. I can't even recreate simple examples from the [block_matrix documentation](http://www.sagemath.org/doc/reference/sage/matrix/constructor.html#sage.matrix.constructor.block_matrix), for example
sage: A = matrix(QQ, 2, 2, [3,9,6,10])
sage: X=block_matrix([ [A, -A], [~A, 100*A] ])
I receive the error "Must specify rows or cols for non-square block matrix."
When I attempt to set those dimensions I continue to get errors.
(My actual application of this is a bit more complicated, but the dimensions all work out. And I have used block_matrix in another program with symbolic entries. I must have gotten lucky.)
I did not import numpy, I did not believe it was necessary. But there's no difference when I do.
Thanks in advance to this magnificent community of sage-masters.
Edit: I have an old version of Sage (4.4). I should have run `block_matrix?` to read my specific help file rather than the online documentation. It's working fine, I was simply using the wrong syntax for my version.David FerroneSat, 02 Apr 2011 11:56:08 +0200https://ask.sagemath.org/question/8044/Finding roots of complex functionshttps://ask.sagemath.org/question/7997/finding-roots-of-complex-functions/This could be a Maxima question as it relates to find_root, find_minimum_on_interval, etc.
When I try to find the root of a function involving `I` (complex numbers) I get:
`TypeError: float() argument must be a string or a number`
For example, `find_root(abs(1-exp(I*x)),-1,1)`.David FerroneSun, 13 Mar 2011 16:16:00 +0100https://ask.sagemath.org/question/7997/Solve() confusion...https://ask.sagemath.org/question/7927/solve-confusion/I've been experimenting with the `solve` function, as it recently gave me unexpected results. In some instances sage outputs nonsensical solutions, but if I provide it with more information (even a trivial equation like x=x) it suddenly parametrizes and outputs correctly.
Can someone explain what is going on in the following code and output?
s=list(var('s_%d' % i) for i in range(3));
var('x y z');
print solve([],s_0,s_1,s_2)
print solve([z==z],s_0,s_1,s_2)
print solve([z==z,y==y],s_0,s_1,s_2)
print solve([z==z,y==y,x==x],s_0,s_1,s_2)
print solve([s_0==0],s_0,s_1,s_2);
print solve([s_0==0,s_1==s_1],s_0,s_1,s_2);
The result:
[[s_0 == c1, s_1 == c2, s_2 == c3]]
({s_0: r1}, [])
[[s_0 == r6, s_1 == r5, s_2 == r4]]
[[s_0 == r9, s_1 == r8, s_2 == r7]]
([s_0 == 0], [1])
[[s_0 == 0, s_1 == r11, s_2 == r10]]David FerroneSun, 06 Feb 2011 22:10:35 +0100https://ask.sagemath.org/question/7927/A list of symbolic variableshttps://ask.sagemath.org/question/7925/a-list-of-symbolic-variables/Hello,
I'm new to sage so I hope that I'm asking a very basic question.
I'm trying to create a list of symbolic variables. I would like to be able to set the number of variables initially and then let sage create the list.
I was (sort of) able to achieve this when I realized that the input for `var` is a string, so I wrote the following, which produces six symbolic variables for me:
> n=3;<br>
for i in range(2*n):<br>
var('s_'+str(i))
In my context, the variables are actually real, and they satisfy a system of equations that I would also like sage to produce. By playing with strings, and then using `eval` on them so they became expressions, I was able to produce a few of the simpler equations, which sage can `solve`.
But when I run for loops indexed by i I can never seem to actually refer to the variables indexed by i. For example, the following will not make sense to sage:
>for i in range(2*n):<br>
s_i = i
The only way I can think to achieve the above result is to create a string with a for loop that states the command I want, turn it into an expression, save it as an equation, and then include it in a big list of equations. Even so, I can't index the equations by i either, so I can't create the 2*n equations that I would need...
I have to do a lot more with these variables, so I hope someone can tell me what I am doing terribly wrong. The first thing I want to do is create a second list, w, defined as:
$w_k = s_{2n-k}$
David FerroneSat, 05 Feb 2011 19:19:13 +0100https://ask.sagemath.org/question/7925/How to rearrange terms in an expressionhttps://ask.sagemath.org/question/7880/how-to-rearrange-terms-in-an-expression/I'm totally new to Sage. I was hoping I could use it for simple and complex application problems I run into at work. For example the relationship between flow rate, Q, and pressure drop, dP, for flow of a powerlaw fluid (m, n) in a cylindrical tube (L, R) is:
Q = (pi*R^3/((1/n)+3))*(Tau/m)^(1/n)
So I want to rearrange this expression for dP in terms of Q, m, n, L, R so I can then compute a table of results, plot dP versus Q etc. Now of course I can do the rearrangement by hand with pen and paper (or in my head on better days) but I was hoping that using the Sage notebook I could work through the rearrangement and thus have an digital record of the transformation so that others can follow along. However in all the hours of reading and watching tutorials, I have yet to see this simple process in action.
So far in my sage book I have:
Q, L, R, m, n, dP = var("Q, L, R, m, n, dP")
Tau = dP/(2*L/R)
Q = (pi*R**3/((1/n)+3))*(Tau/m)**(1/n)
(Note that the preview doesn't show the power symbol \*\*, hope it appears in the posted question)
Is there a method, say, Q.rearrange(dP) that yields dP = f(Q, L, R, m, n)? If not, how do I write the intermediate steps in sage speak to give this expression?
Sorry if this is such a basic question. mouseSun, 16 Jan 2011 22:35:34 +0100https://ask.sagemath.org/question/7880/Setting Precision in Sagehttps://ask.sagemath.org/question/7653/setting-precision-in-sage/ integral(integral(e^(-0.00260657639223762*(h - 11.1600000000000)^2 - 1.34372480515*(d - 2.85000000000000)^2)/pi, d, 0,Infinity), h, 0, Infinity).n()
I have been working through an error I am receiving with the above command. The error I get when I run it is:
TypeError: Error executing code in Maxima
CODE:
sage297 : integrate(sage293,sage294,sage295,sage296)$
Maxima ERROR:
rat: replaced -0.0026065763922 by -200/76729 = -.00260657639223762
rat: replaced -11.16 by -279/25 = -11.16
rat: replaced -1.343724 by -3233/2406 = -1.34372402327515
rat: replaced -2.85 by -57/20 = -2.85
Maxima encountered a Lisp error:
5883790627 is not of type FIXNUM.
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
However if I shorten the decimals to something like:
integral(integral(e^(-0.0026*(h - 11.1600000000000)^2 - 1.343724*(d - 2.85)^2)/pi, d, 0,Infinity), h, 0, Infinity).n()
Then the command runs fine without any issues. Now perhaps this is a bug, but really I do not need the level of precision that is in these commands. Of course I do not want numbers here but variables and it is evaluating the variables to this level of precision that is causing the issue. For example I say:
sage: f(d,h) = (1/(2*pi*0.61*13.85))*exp(-1/2*((d-2.85)^2/0.61^2+(h-13.85)^2/13.85^2))
sage: f
(h, d) |--> 0.05918210333195241758892111025625850742735*e^(-0.002606576392237615503916381029337017294634*(h - 11.16000000000000000000000000000000000000)^2 - 1.343724805159903251814028486965869389949*(d - 2.850000000000000000000000000000000000000)^2)/pi
Any ideas?
P.S.
I have searched around, but I have not found any that apply to just basic numbers in Sage.willmwadeMon, 30 Aug 2010 16:27:44 +0200https://ask.sagemath.org/question/7653/