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.Fri, 17 Apr 2020 23:32:38 +0200how to check if a polynom is a squarehttps://ask.sagemath.org/question/50825/how-to-check-if-a-polynom-is-a-square/ I'ld like to put a condition in a programm that looks like:
"if Q is a square, then ..."
Q being a polynom (in GF(p)).
How can I do that ?DasiatysFri, 17 Apr 2020 23:32:38 +0200https://ask.sagemath.org/question/50825/obtaining all numerical roots of a function in an intervalhttps://ask.sagemath.org/question/8886/obtaining-all-numerical-roots-of-a-function-in-an-interval/Hello, thanks for reading.
I'm working on single variable calculus here:
Basically what I need is what "find_root" does, but I need a list of ALL roots in a given interval, not just one.
So I've been playing with "solve". I found this piece of code which works in most cases:
sage: roots = solve(f(x),x,solution_dict=True)
sage: roots = [s[x] for s in roots]
sage: num_roots = map(n, roots)
but it gives an error if the function is periodic and has inifinite roots, becuase the symbolic expression that "solve" gets has infinite solutions too.
Defining a desired interval should solve this issue, but I have no idea how to implement such thing!
Thanks you and have a good day.NilSun, 15 Apr 2012 01:17:01 +0200https://ask.sagemath.org/question/8886/Define the polynomial ring $\Bbb Q[c][x]$.Find the $c$ values where $x^2 + x + c + 1$ has a double root.https://ask.sagemath.org/question/47267/define-the-polynomial-ring-bbb-qcxfind-the-c-values-where-x2-x-c-1-has-a-double-root/ **Sage question:**
Define the polynomial ring $\Bbb Q[c][x]$.Find the $c$ values where $x^2 + x + c + 1$ has a double root.
Sage code I have found.
K.<c>=QQ['c']
R.<x>=K[]
f=x^2+x+c+1
f
How do I find the code for the $c$ values where $x^2 + x + c + 1$ has a double root. Also, can you give some examples so that I can construct some programming code in sage?
ArnabThu, 25 Jul 2019 15:00:01 +0200https://ask.sagemath.org/question/47267/Reliable integer root function?https://ask.sagemath.org/question/30375/reliable-integer-root-function/Does Sage have an integer_root(x, n) function which reliable (!) returns floor(root(x,n)) for n-th roots? I think that
it should be offered as a Sage function if not.
This seems to work:
def integer_root(x, n): return gp('sqrtnint(%d,%d)' %(x,n))
Integer n-th root of x, where x is non-negative integer.
// Related: question 10730.
**Edit:** The answer of castor below shows a second way to define such a function:
def integer_root(x, n): return ZZ(x).nth_root(n, truncate_mode=1)[0]
Which version will be faster?Peter LuschnySat, 31 Oct 2015 19:42:58 +0100https://ask.sagemath.org/question/30375/comparing sets of roots of charpolyhttps://ask.sagemath.org/question/35729/comparing-sets-of-roots-of-charpoly/ I am missing something about how to compare list of roots.
During a small algorithm I need to know wether a matrix has or not complex eigenvalues. I did the following
A=matrix(QQ,[[1,2,1],[6,-1,0],[-1,-2,-1]])
a=(B.charpoly()).roots(ring= QQ, multiplicities=False)
b=(B.charpoly()).roots(ring= QQbar, multiplicities=False)
then a is the list [-4,0,3] and b is the list [3,0,-4].
I don't get the following :
set(a)==set(b)
return false while
set([-4,0,3])==set([3,0,-4])
return true.
Any help, either on the first pb (knowing that a QQ matrix has complex eigenvalues) or on the second would be greatly appreciated.
Cheers.Laurent BThu, 24 Nov 2016 21:15:42 +0100https://ask.sagemath.org/question/35729/Newton method for one variablehttps://ask.sagemath.org/question/34554/newton-method-for-one-variable/ I try to use 'solve' for nonlinear eauqtions in one variable, but the answer is tautological or "cannot evaluate symbolic expression numerically" if I add "explicit_solutions=True". Is Newton method (or any other, like secant method) implemented in Sage?
Ex:
sage: x=var('x')
sage: (x-cos(x)).solve(x)
[x == cos(x)]
while I would expect x= 0.739085logomathMon, 22 Aug 2016 09:53:18 +0200https://ask.sagemath.org/question/34554/fractional exponents error: "negative number to a fractional power not real"https://ask.sagemath.org/question/32385/fractional-exponents-error-negative-number-to-a-fractional-power-not-real/ Hi. I'm having a problem with fractional exponents and higher order roots in sage.
If I put `(-2)** (6/2), sqrt((-2)** 6)`, the result is `(-8, 8)`. That's wrong, since `sqrt[ (-2)**6 ] = (-2) * (-2) * (-2) = -8`. Does anyone know why this is happening, please?
I need to plot a function like `V(x) = x^[ (2n+1)/n ]`, where n is interger. However, sage returns the error 'negative number to a fractional power not real' and plot only the positive branch.DiegoQuanticoSat, 30 Jan 2016 17:43:43 +0100https://ask.sagemath.org/question/32385/About roots of a certain polynomial equationhttps://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/Why is Sage hanging up trying to find roots of this equation?
0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
phoenixTue, 20 Jan 2015 21:55:47 +0100https://ask.sagemath.org/question/25579/Get variants of complex cube-roothttps://ask.sagemath.org/question/10063/get-variants-of-complex-cube-root/I found-out that complex cube-root can have 3 variants (see http://en.wikipedia.org/wiki/Cube_root)
But if I try in SageMath to do
(-1)^(1/3)
SageMath return (-1)^(1/3). When I try
(-1)^(1/3).n()
SageMath gives me numerical approximation of the one root (not real)...
How I can get all variants of complex cube-root without numerical approximation?
Thanks! P.S. Sorry for poor English...avi9526Thu, 25 Apr 2013 15:31:30 +0200https://ask.sagemath.org/question/10063/Does Sage accept the nth root with letters a and b?https://ask.sagemath.org/question/25771/does-sage-accept-the-nth-root-with-letters-a-and-b/ Hello!
Before installing Sage, I would like to know it accepts the **nth** root with letters *a* and *b*. For example:
sqrt(a+sqrt(b))*sqrt(a-sqrt(b))*sqrt(a^2-b)
LaTeX: `\[\sqrt {a + \sqrt b } *\sqrt {a - \sqrt b } *\sqrt {{a^2} - b} \]`
Wolfram Alpha: `Sqrt[a+Sqrt[b]]*Sqrt[a-Sqrt[b]]*Sqrt[a^(2)-b]`
Does it accept this formula with letters?
Thank you for your attention, understanding and helping!
gusbemacbeMon, 09 Feb 2015 00:40:48 +0100https://ask.sagemath.org/question/25771/Is there a simple way to deal with computing real nth roots for n a natural number?https://ask.sagemath.org/question/10730/is-there-a-simple-way-to-deal-with-computing-real-nth-roots-for-n-a-natural-number/I am trying to use the nth root for natural numbers in computations and display the result as a decimal to four places.
I can't find a simple reference for these functions. Is there an nroot(x,n) function?Martin FlashmanTue, 12 Nov 2013 19:07:58 +0100https://ask.sagemath.org/question/10730/Ignoring the very small imaginary parthttps://ask.sagemath.org/question/10024/ignoring-the-very-small-imaginary-part/I am generating a matrix that its entries come from roots of a polynomial which are all real. Due to calculation errors sage returns entries such as: `-2.8 + 2.2e-16*I`
How can I ask sage to ignore the small imaginary part and return -2.8?k1Wed, 01 May 2013 16:03:09 +0200https://ask.sagemath.org/question/10024/solving a simple equationhttps://ask.sagemath.org/question/9868/solving-a-simple-equation/Is there a method to solve the equation
x + x^(1/3) == -2 ?
czsanFri, 01 Mar 2013 15:13:46 +0100https://ask.sagemath.org/question/9868/Roots in a solutionhttps://ask.sagemath.org/question/9402/roots-in-a-solution/When I solve the equations I obtained from the code in [this question](http://ask.sagemath.org/question/1848/eliminating-fractions-and-roots-from-equations), I get a number of solutions. Most of them complex numbers, whereas the single real solution simply prints as `r1` when first executing the code, as `r2` next, and so on. So I gather that this is some root which Maxima or whoever is doing the solving cannot reduce to radicals.
So far, so good, but I'd still like to be able to get an idea of what that thing represents. Saving my solutions to a list of dictionaries, I've been able to isolate that value, but I can't seem to find any reasonable methods to obtain further details. In particular, `r.n()` tells me that it
TypeError: cannot evaluate symbolic expression numerically
So what can I do? how can I figure out what this thing actually represents? I believe that it might be some root of a polynomial which still contains one variable from my equation. But how can I obtain that polynomial?MvGMon, 08 Oct 2012 13:19:15 +0200https://ask.sagemath.org/question/9402/scipy.optimize.roothttps://ask.sagemath.org/question/9334/scipyoptimizeroot/Hello,
I'm trying to use scipy.optimize.root without any luck (http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root.html#scipy.optimize.root). An import attempt returns: "'module' object has no attribute 'root'"
Any suggestions on how I can get this module?
Thanks,
jv
Methods tried:
"import scipy
from scipy import optimize
from scipy.optimize import root"
"import scipy
from scipy import optimize
sol = optimize.root(q, [0., 0.])"mattiasFri, 21 Sep 2012 06:26:30 +0200https://ask.sagemath.org/question/9334/solving sqrt(-1) to a real numberhttps://ask.sagemath.org/question/8762/solving-sqrt-1-to-a-real-number/Here is what I am trying to do:
var('x')
A(x)=x/2+(4-x*x)^(1/2)
assume(0<x<2)
maximum = (derivative(A)==0).maxima_methods().rootscontract().simplify()
view(maximum)
view(solve(maximum,x))
A.plot(A,0,2)
and get i multiplied by the root of x^2... if I put the same equation into wolfram, it gives me a real number 2/sqrt(5) (which is correct and makes sense).
How can I make SageMath solve those? I tried simplify() and full_simplify(), maxima_methods() and rootscontract() gives an error in combination with solve().
I guess it's just some syntax error, sorry for that :(
For now I do most in the Sage - Cell Server, which is great.disiThu, 01 Mar 2012 09:26:06 +0100https://ask.sagemath.org/question/8762/What is password for sage?https://ask.sagemath.org/question/8404/what-is-password-for-sage/I am trying to get ready to ready to install guest additions so that I can arrange for shared folders. I have Sage running in virtual machine in an Oracle VM VirtualBox. When the VM containing Sage comes up it shows Fedora being loaded.
According to Chapter 4 Guest Additions in the Oracle VM VirtualBox User Manual, I'm told to enter **yum install dkms** In response I'm told "You need to be root to perform this command."
**[sage@sage sage]$ sudo yum install dkms** asks for a password for sage.
I have no idea what the root password is. I don't think I was asked to establish a password for root (admin) David JonahSat, 22 Oct 2011 12:40:16 +0200https://ask.sagemath.org/question/8404/Finding all the roots at once numericallyhttps://ask.sagemath.org/question/8105/finding-all-the-roots-at-once-numerically/I want to calculate the roots of equations like
tanh(ax) = x
numerically.
But the problem is sage gives option of finding just one root provided I give it the interval where the root may be found.
(tanh(1.5*x)==x).find_root(0.5,2)
But sometimes the interval is not so obvious and I need to know all the numerical roots at once
(If the number of roots are finite that is). Is There a way to do that?
ebsThu, 05 May 2011 07:17:27 +0200https://ask.sagemath.org/question/8105/SAGE digits!!!https://ask.sagemath.org/question/8058/sage-digits/How can I make p.real_roots() in 6 digits??<br> .n(digits=6) DONT work!!!SagudTue, 05 Apr 2011 12:29:16 +0200https://ask.sagemath.org/question/8058/Need correct root finding over the p-adicshttps://ask.sagemath.org/question/8015/need-correct-root-finding-over-the-p-adics/I have a restricted power series $f(t)$ defined over the p-adic integers (*restricted* means that the coefficients converge to 0). In practice when one sets a precision for the p-adics this power series turns into a polynomial. I want to be able to compute the p-adic integer roots of $f(t)$. More precisely I want an algorithm whose output is a set of disjoint p-adic balls $B_i$ with associated multiplicities $m_i$ subject to the following conditions:
1. The power series f has no zeros outside the union of the balls;
2. If a ball $B$ has multiplicity 1, then there exists a single root of f in $B$;
3. If a ball $B$ has multiplicity m>1, then there can be at most m roots of f in $B$;
4. The total area covered by the balls goes to zero as the precision that we choose goes to infinity.
My attempt to solve this problem using Sage was to use the roots() function, however this function does not satisfy condition 2. For example consider:
R = Zp(3)
P.<x> = R['x']
zero = R.zero().add_bigoh(2)
poly = (1+zero)*x**2+(3+zero)*x + zero
poly.roots()
The output is `[(2*3 + O(3^2), 1), (O(3^2), 1)]` and it should have been `[(O(3),2)]`. My question is, is there an easy way to get the described functionality in Sage, or do I have to write everything from scratch?
Thank you for the responses,Tzanko MatevMon, 21 Mar 2011 09:34:32 +0100https://ask.sagemath.org/question/8015/sage server in other than apache document roothttps://ask.sagemath.org/question/8012/sage-server-in-other-than-apache-document-root/Dear sage community---
I want to set up a local sage server for my freshman physics students
to use. I am using Ubuntu 10.10 and followed the directions at the
SageServer wiki and it worked just fine. Assuming my server is at
http://server.whatever, going to this URL would fire up sage just
fine, with apache proxies rerouting / to localhost:8000.
This installation, however, assumes that the document root of the web
server is where the installation should occur. The associated proxy
redirects essentially take over the whole web server--that is,
accessing other web services, like a wiki or some other php codes
becomes impossible. I tried changing the proxies to reference
something like http://server.whatever/sage (that is, proxy redirect
/sage/ requests to localhost:8000). This works initially, but the css,
etc. was all missing. I fixed this with URL rewrites in
/sage/.htaccess, which edits the absolute references in the sage html
files. Things looked perfect now at http://server.whatever/sage, and
my other web services were available too.
The problem now is that all sage worksheets contain a red "Searching
for sage server..." and the worksheets become useless (i.e.
disconnected from the sage server). Likewise the javascript action of
deleting, etc. a worksheet are broken. I am stuck here and cannot
find a solution to this problem. Has anyone tried installing a sage
server into any web directory other that the root one? Any luck?
Thanks for any help.
Tom B.tbenskyFri, 18 Mar 2011 18:17:03 +0100https://ask.sagemath.org/question/8012/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/Inaccurate numerical result for roots of square equationhttps://ask.sagemath.org/question/7988/inaccurate-numerical-result-for-roots-of-square-equation/Hi,I have 'Sage Version 4.6.1, Release Date: 2011-01-11' and I using next code to get roots of square equation:
reset()
var('a b c p pz pz2')
a = 0.0000148294611962432
b = 9.90113840830450
c = 1.00000000000000
A = a*p^2 + b*p + c
pz = solve(A == 0, p, solution_dict = True)
pz = [s[p].n() for s in pz];
Result1 = A(p=pz[0])
This way give very bad accuracy of the 1st root (Result1=-0.00138422288000584). What i do wrong? And How to get precision result with Sage? Thanks!avi9526Tue, 08 Mar 2011 12:18:44 +0100https://ask.sagemath.org/question/7988/Numerically find all roots in an intervalhttps://ask.sagemath.org/question/7823/numerically-find-all-roots-in-an-interval/Is there a function to find all the roots of a function on a given interval? I'm thinking of something like this:
<pre>
sage: find_all_roots(lambda z: tan(z)+z/sqrt(9*pi^2-z^2), 0, 10)
[0, 2.835952326711582867481259929, 5.64146101037285257526886564, 8.338774576412169721334841011]
</pre>
Thanks!Just a nobodySat, 18 Dec 2010 17:42:56 +0100https://ask.sagemath.org/question/7823/