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.Wed, 16 Jan 2019 22:27:41 -0600How can I solve the following (linear) differential equation?http://ask.sagemath.org/question/45075/how-can-i-solve-the-following-linear-differential-equation/I want Sage to solve this equation:
$y'''-3y''+y'-5y=0$.
Both
y=function('y')(x)
desolve(diff(y,3)-3*diff(y,2)+diff(y,1)-5*y,y)
and
giac("desolve([y'''-3y''+y'-5y],y)").sage()
result in errors.ThrashWed, 16 Jan 2019 22:27:41 -0600http://ask.sagemath.org/question/45075/Wrong solution/output for differential equationhttp://ask.sagemath.org/question/45046/wrong-solutionoutput-for-differential-equation/As the user rburing advised in the thread
https://ask.sagemath.org/question/44995/combine-plots-with-built-in-maxima-trajectory-in-sage-available/
I'm opening this one now.
When running the following code, one obtains a wrong output:
y=function('y')(x)
desolve(diff(y)==4*y/x+x*sqrt(y),y,ics=[1,1]).factor()
The output is `1/4*x^4*(log(x) - 2)^2` instead of `1/4*x^4*(log(x) + 2)^2`. Mathematica however outputs both (by running `DSolve[{D[y[x], x] == 4*y[x]/x + x*Sqrt[y[x]], y[1] == 1}, y[x], x]`).ThrashMon, 14 Jan 2019 10:54:14 -0600http://ask.sagemath.org/question/45046/Quadratic equation with complex coefficientshttp://ask.sagemath.org/question/44961/quadratic-equation-with-complex-coefficients/How can I solve `x^2 - (1 + I)*x + 6 + 3*I == 0` to get answers `z = 3*I` and `z = 1 - 2*I` ? When I enter
solve(x^2 - (1 + I)*x + 6 + 3*I == 0, x)
I get
[x == -1/2*sqrt(-10*I - 24) + 1/2*I + 1/2, x == 1/2*sqrt(-10*I - 24) + 1/2*I + 1/2]EvgenyMTue, 08 Jan 2019 15:16:03 -0600http://ask.sagemath.org/question/44961/Using SageMath to solve Simultaneous equations in a Boolean Ringhttp://ask.sagemath.org/question/44856/using-sagemath-to-solve-simultaneous-equations-in-a-boolean-ring/I'm trying to get SageMath to solve a system of equations in a Boolean Ring.
Here is my code.
P.<x,y,z> = BooleanPolynomialRing(3, order= 'lex')
equations = [1+x+y+z, x+y, x*y+1, x+y]
zeros = [0,0,0,0]
I know that there are equation solvers for Sage, but I do not know how to have the answers of the equation be only in the Boolean Ring (ie. only 1 or 0). Obviously I can solve the equation by hand, but that's not the point here. Is there a way to have SageMath only output 0 or 1 as the answer?
Stockfish3709Thu, 03 Jan 2019 02:20:02 -0600http://ask.sagemath.org/question/44856/Solving linear congruencehttp://ask.sagemath.org/question/44618/solving-linear-congruence/ Is there a simple way to solve a linear congruence modulo an integer with large prime factors in Sage? `solve_mod` function cannot handle such large moduli apparently.kdr01Sun, 09 Dec 2018 13:28:31 -0600http://ask.sagemath.org/question/44618/Missing root when solving equation in sageMathhttp://ask.sagemath.org/question/43052/missing-root-when-solving-equation-in-sagemath/When I solve equation using sageMath, it missed one root.
sage: solve([4/5*(x - 1)^2/x^(1/5) + 2*(x - 1)*x^(4/5)==0] ,x)
[x == (2/7), x == 1]
The equation has 3 roots. It misses x==0.
What is the reason?Sam TanTue, 17 Jul 2018 18:58:17 -0500http://ask.sagemath.org/question/43052/How to get all (numerical) solutions of an equation?http://ask.sagemath.org/question/7634/how-to-get-all-numerical-solutions-of-an-equation/Mathematica's NSolve can produce all roots of a polynomial equation, like this:
sage: mathematica('NSolve[9*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0, x]')
{{x -> -1.1030150726298147},
{x -> -0.49110203599909275 - 0.9883314953720708*I},
{x -> -0.49110203599909275 + 0.9883314953720708*I},
{x -> 0.5426095723140001 - 1.0543115206871092*I},
{x -> 0.5426095723140001 + 1.0543115206871092*I}, {x -> 1.}}
OTOH, Sage's solve gives just one real solution:
sage: solve(9*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0, x)
[x == 1, 0 == 9*x^5 + 9*x^4 + 13*x^3 + 16*x^2 + 16*x + 17]
Is there a simple way to get all solutions?kkumerWed, 25 Aug 2010 04:42:23 -0500http://ask.sagemath.org/question/7634/solving matrix over GF(2)http://ask.sagemath.org/question/41575/solving-matrix-over-gf2/ A = matrix(GF(2), 8, 8, [])
b = vector(GF(2), [0, 1, 1, 0, 1, 0, 1, 1])
y = vector(GF(2), [0, 0, 0, 0, 1, 0, 1, 1])
x = vector(GF(2), [1, 0, 0, 0, 0, 0, 0, 0])
If the matrix $A$ is unkown, we have $Ax+b = y$.
How can we solve the matrix $A$?
omggggggThu, 15 Mar 2018 20:06:28 -0500http://ask.sagemath.org/question/41575/Get the constant value of an equationhttp://ask.sagemath.org/question/39060/get-the-constant-value-of-an-equation/I have the following equation :
(x - 1)^2 - (x - 2)^2 - (y - 1)^2 + y^2 + (z - 3)^2 - (z - 4)^2 == 1.75000000000000
which I factorized to :
2*x + 2*y + 2*z - 51/4
And then I would like to extract the `-51/4` but the `.coefficient()` function doesn't work for constant so I have no idea to get the constant value.BariloSat, 07 Oct 2017 04:20:49 -0500http://ask.sagemath.org/question/39060/Get the coefficient of the constanthttp://ask.sagemath.org/question/39058/get-the-coefficient-of-the-constant/ I have the following equation :
(x - 1)^2 - (x - 2)^2 - (y - 1)^2 + y^2 + (z - 3)^2 - (z - 4)^2 == 1.75000000000000
which I factorized to :
2*x + 2*y + 2*z - 51/4
And then I would like to extract the `-51/4` but the `.coefficient()` doesn't work for constant so I have no idea to get the constant value.BariloSat, 07 Oct 2017 04:19:12 -0500http://ask.sagemath.org/question/39058/Sage says equation isn't true while Mathematica says it ishttp://ask.sagemath.org/question/38795/sage-says-equation-isnt-true-while-mathematica-says-it-is/I have the following equation, of which I know that it is true when ```sigma > 0``` and ```mu > 0```.
eq = mu + 0.5*log(2*pi*sigma^2*e) == log(sqrt(2)*sqrt(pi)*sigma*e^(mu + 0.5))
So I set the constraints ```assume(sigma > 0)``` and ```assume(mu > 0)```. When evaluating it with ```bool(eq)```, Sage says ```False``` while Mathematica says that the equation holds. What am I doing wrong?muxamilianTue, 12 Sep 2017 08:22:24 -0500http://ask.sagemath.org/question/38795/Get the nth term of an equation.rhs() sumhttp://ask.sagemath.org/question/38720/get-the-nth-term-of-an-equationrhs-sum/ Hi
equ0 = term_0 == term_1 + term_2 + term_3
I want to extract term_1 + term_2 to work with.
I have been looking for a long time without success,
I read the whole page:
[link text](http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html)
example:
$
{\left| p\left(\rho_{\epsilon} e^{\left(i \, \theta_{\epsilon}\right)} + w\right) \right|}^{2} =
\rho_{0} \rho_{\epsilon}^{m} \rho_{m} e^{\left(i \, m \theta_{\epsilon} - i \, \theta_{0} + i \, \theta_{m}\right)} +
\rho_{0} \rho_{\epsilon}^{m} \rho_{m} e^{\left(-i \, m \theta_{\epsilon} + i \, \theta_{0} - i \, \theta_{m}\right)} + \rho_{\epsilon}^{2 \, m} \rho_{m}^{2} + \rho_{0}^{2}
$ortolljSun, 03 Sep 2017 03:59:01 -0500http://ask.sagemath.org/question/38720/using sage solve for more than 4 variableshttp://ask.sagemath.org/question/38011/using-sage-solve-for-more-than-4-variables/ I just tried to sovle a 82 queation with 82 varibles, and got the following error:
TypeError: solve() takes at most 5 positional arguments (82 given)
I assume that i'm not using it right. I would like an help.
Thanks.SAvaGEMon, 19 Jun 2017 04:01:19 -0500http://ask.sagemath.org/question/38011/Equation with sign functionhttp://ask.sagemath.org/question/37948/equation-with-sign-function/Hi all,
I have the following piece of code
f(x) = 2*unit_step(x)
u = function('u')(x)
eqn = diff(u,x) + u == f(x)
v = desolve(eqn, u,ics=[0,0])
solve(v,x)
which gives me `[x == 0, sgn(x) == -1]` as solutions to the last equation. Could you help me find a way for Sage not to stop at `sgn(x) == -1`?
ThankssokingThu, 15 Jun 2017 02:20:44 -0500http://ask.sagemath.org/question/37948/indicial equationhttp://ask.sagemath.org/question/37861/indicial-equation/Let N be an integer. Let a, b, A_1,...,A_N be constant real numbers. Let g(n) be a real function of integer variable n.
g(n) satisfies the recurrence equation:
(n + 1)*(n + b)*g(n+1) = (n + a)*g(n) + sum(i=1 to N)(A_i * g(n-i))
with g(n)=0 for n<0 . g(0) is obtained through boundary conditions, so it can be considered a given constant.
I need to know the general functional form of the term g(n), as a function of the given constants of the problem: a,b,N,A_1,...,A_N and g(0).
Could you help me? Could I programm in SAGE the code to provide the searched general term g(n)?
Thanks for your attention.
Javier Garciafjgg1549Thu, 08 Jun 2017 12:34:46 -0500http://ask.sagemath.org/question/37861/problem solving equation systemshttp://ask.sagemath.org/question/36786/problem-solving-equation-systems/ var('V1', 'V2')
solve([V1+V2==0.5,7.20 == 5.5 - log(V1/V2,10)], V1, V2)
SageMath do not solve this system but when with Ctrl+C the calculation end and show in terminal the solution.
If I use natural logarithm in the expression Sage solve this system without any problem.eancedegThu, 02 Mar 2017 09:33:42 -0600http://ask.sagemath.org/question/36786/Any way to solve this differential equation?http://ask.sagemath.org/question/36122/any-way-to-solve-this-differential-equation/ sage: x(t)=function('x')(t)
sage: x
t |--> x(t)
sage: g(v,c)=1/sqrt(1-v^2/c^2)
sage: g
(v, c) |--> 1/sqrt(-v^2/c^2 + 1)
sage: var('a')
a
sage: ode = g(diff(x,t))*diff(x,t) == a*t
sage: ode
t |--> diff(x(t), t)/sqrt(-diff(x(t), t)^2/c^2 + 1) == a*t
sage: desolve(ode,x)
Traceback (most recent call last):
...
ValueError: Unable to determine independent variable, please specify.
sage: desolve(ode,[x,t])
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
sage: desolve(ode,[x,t],contrib_ode=True)
Traceback (most recent call last):
...
NotImplementedError: Maxima was unable to solve this ODE.
I can solve it by hand.
Mathematica can solve it. But I would very much prefer to learn to use Sage because it's open source.
It looks like it is Maxima that cannot solve it. But is it possible to make Sage invoke any other open source program than Maxima? Or use some trick in defining the problem that would allow Maxima to solve it?
Thank you.omoplataThu, 29 Dec 2016 13:15:36 -0600http://ask.sagemath.org/question/36122/Numerical real solution of derivativehttp://ask.sagemath.org/question/35374/numerical-real-solution-of-derivative/I would like to know where a function attains its maximum, so I'm trying to solve some
>diff(y,x),x
where y depends on y. I have difficulties with Sage returning equations, complex roots, converting equations, find_maximum_on_interval command etc, and instead of spending another hour trying to figure it out myself, I thought I would try asking here...
Here is a more concrete example:
>f = log(2.02 * x + 1) / 2 + log( -2 * x + 1) / 2
>find_local_maximum(diff(f,x), 0, 1)
What is mysterious for me, is that the above works if instead I have
>f = log(1.01 * x + 1) / 2 + log( -x + 1) / 2domotorpThu, 03 Nov 2016 00:29:02 -0500http://ask.sagemath.org/question/35374/What's this result of equation solving?http://ask.sagemath.org/question/35167/whats-this-result-of-equation-solving/Hi guys
I want to solve an equation that get from determinant of a matrix, but I cannot understand the result! Can anyone help me?
It's my code:
x = var('x')
A = Matrix([[0,1],[1,0]])
A = (I*x*A).exp()
A = A.determinant()
solve(A == 1,x,to_poly_solve ='force')
This is result!!!!!:
[x == 1/2*I*lambert_w(68)]
What is exactly that c68 (it's change every time!) [The result for equation should be pi/2]palidehxSun, 16 Oct 2016 22:46:38 -0500http://ask.sagemath.org/question/35167/How to use SageMath to solve this equation?http://ask.sagemath.org/question/34760/how-to-use-sagemath-to-solve-this-equation/ I am a beginner of SageMath. I want to solve Z in the following equation using SageMath:
(1 + rho * Z)^beta * (1 + 2 * rho * Z)^(1 - beta) < 2^(3 R / 2),
where rho > 0, Z >= 0, beta is in (0,1), and R > 0. I don't know how to do this in SageMath. Could you please teach me? Thank you very much in advance.
Wei-Cheng LiuWed, 07 Sep 2016 04:02:12 -0500http://ask.sagemath.org/question/34760/solving systems of equations returns [] Reduxhttp://ask.sagemath.org/question/34608/solving-systems-of-equations-returns-redux/I searched the wiki and found the "solve always returns []" question. But it doesn't help me. I will admit that I am a complete neophyte with Sagemath and have been playing with version 7.2 on my windows machine.
I was trying to do something very simple: solve a basic Lagrange Multiplier problem, so I defined the following:
- var('x' ,'y' ,'z', 'lam')
- var('F')
- F = x*y*z - lam * (x*y*z-9)
- var('dFx', 'dFy', 'dFz', 'dFlam')
- dFx=diff(F,x)
- dFy=diff(F,y)
- dFz=diff(F,z)
- dFlam=diff(F,lam)
- solve([dFx==0,dFy==0,dFz==0,dFlam==0],x,y,z,lam)
but the **solve** returns []. It should return something like x==3, y==3, z==3, shouldn't it? Is there an alternative way to approach this?
Thanks.
BobM
BobMSat, 27 Aug 2016 03:28:29 -0500http://ask.sagemath.org/question/34608/Unexpected Answer for an Equationhttp://ask.sagemath.org/question/33254/unexpected-answer-for-an-equation/ Hello,
I am trying to calculate the following equation in SAGE.
N = 100.
p = 0.9.
r = (N /(N-1))*(ln(N)-ln(-ln(p))); r
Unfortunately, sage gives this answer **100/99*log(100) + 2.27309831041661** , which is not the expected answer !!
But, when I used google calculator, I got the expected answer, which is **6.92478536697**
Please let me know what is going on.? Thank you. usamrfThu, 28 Apr 2016 13:52:10 -0500http://ask.sagemath.org/question/33254/Not understandable error when solving polynomial equationhttp://ask.sagemath.org/question/33050/not-understandable-error-when-solving-polynomial-equation/Hi all,
when I enter command
solve(symbolic_expression(x^12 - x^11 - 12*x^10 + 11*x^9 + 54*x^8 - 43*x^7 - 113*x^6 + 71*x^5 + 110*x^4 - 46*x^3 - 40*x^2 + 8*x + 1)==0, var(x), to_poly_solve=True)
I get the expected result, but when I enter command
solve(symbolic_expression(x^10 - 10*x^8 + 35*x^6 + x^5 - 50*x^4 - 5*x^3 + 25*x^2 + 5*x - 1), var(x), to_poly_solve=True)
I get the error message
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-203-6108bea90b72> in <module>()
----> 1 solve(symbolic_expression(x**Integer(10) - Integer(10)*x**Integer(8) + Integer(35)*x**Integer(6) + x**Integer(5) - Integer(50)*x**Integer(4) - Integer(5)*x**Integer(3) + Integer(25)*x**Integer(2) + Integer(5)*x - Integer(1)),var(x),to_poly_solve=True)
/usr/local/sage-6.4.1-x86_64-Linux/local/lib/python2.7/site-packages/sage/symbolic/relation.py in solve(f, *args, **kwds)
732 from sage.symbolic.expression import is_Expression
733 if is_Expression(f): # f is a single expression
--> 734 ans = f.solve(*args,**kwds)
735 return ans
736
/usr/local/sage-6.4.1-x86_64-Linux/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.solve (build/cythonized/sage/symbolic/expression.cpp:47061)()
/usr/local/sage-6.4.1-x86_64-Linux/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.solve (build/cythonized/sage/symbolic/expression.cpp:46887)()
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
What happened here? The error message is totally misleading (no index in the command!) and it is not to understand why the second command fails while the first works fine.
By the way, the polynomial in question has ten simple real roots, so there should be no problem to compute the roots if symbolic evaluation is not possible.
Thanks in advance
Wolfgang
wjansenSun, 10 Apr 2016 11:29:46 -0500http://ask.sagemath.org/question/33050/Define a factor of an equationhttp://ask.sagemath.org/question/30232/define-a-factor-of-an-equation/ I have the following code :
p, t= var('p t')
a=(-2*p*t^2-p^2*t)+(2*t*p-p^2)+t+1
b=(p*t^2+2*p^2*t)+(2*t*p-t^2)-p+1
c=(p*t^2-p^2*t)+(t^2+2*t*p+p^2)+t-p #3 sides (a,b,c) in terms of theta and phi [equation (1.1)]
s=factor(2*c^2+2*a^2-b^2);s
which yields
(3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1)^2
I want to use the factor `(3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1)` in my next command. How should I define that. Like I want to set `m = 3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1`. Tried using `operand()` but did not help muchShaThu, 22 Oct 2015 20:50:36 -0500http://ask.sagemath.org/question/30232/How to pick out the largest root of an equation?http://ask.sagemath.org/question/25568/how-to-pick-out-the-largest-root-of-an-equation/ I tried the following but it didn't work,
p = x^2 - 7*a*x + 5;
a=5;
m = max((p == 0).solve([x]))
PhoenixMon, 19 Jan 2015 22:22:48 -0600http://ask.sagemath.org/question/25568/About roots of a certain polynomial equationhttp://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 14:55:47 -0600http://ask.sagemath.org/question/25579/Solving a quartic equationhttp://ask.sagemath.org/question/26993/solving-a-quartic-equation/ I'm attempting to rearrange an equation from an [answer on the Mathematics StackExchange](http://math.stackexchange.com/questions/1298722/find-parametric-line-between-two-2d-line-segments-that-is-an-exact-distance-from).
The answer given is this equation:
$$L^2 = (-ab(t)+p)^2-\left(\frac{(-ab(t)+p).(cd(t)-ab(t))}{(cd(t)-ab(t))^2}(cd(t)-ab(t))\right)^2$$
Where $a$, $b$, $c$, $d$, and $p$ are known 2D points, $L$ is a known length, and $t$ is an unknown scalar. $ab(t)$ indicates interpolation between $a$ and $b$.
I am interested in rearranging this to solve for $t$. Here's what I've tried in Sage:
<pre><code>def sqr(var): return var.dot_product(var)
var('ax bx cx dx px ay by cy dy py t L')
a = vector([ax, ay])
b = vector([bx, by])
c = vector([cx, cy])
d = vector([dx, dy])
p = vector([px, py])
g = a - a*t + b*t
h = c - c*t + d*t
u = p - g
v = h - g
eq = L^2 == sqr(u) - sqr((u.dot_product(v)/sqr(v)) * v)
eq.solve(t)
</pre></code>
At the `solve` step I have observed it to sit for quite a while without producing a result. Two questions:
1. Am I inputting the problem correctly?
2. Is there any way to know if this is likely to terminate in a reasonable time? I have no idea what the solver looks like under the hood, and wouldn't want to wait for some `O(n!)` calculation to terminate :)
nicholasbishopSun, 31 May 2015 21:51:26 -0500http://ask.sagemath.org/question/26993/solve equation with double sumhttp://ask.sagemath.org/question/26465/solve-equation-with-double-sum/Hi!
Please help me with my porblem. I have two no-linear equations:
1) f(x)==h(x)
2) g(x)+S_{i,j,k}(x) == 0
I know I can solve (numerically) eq.(1) doing:
x=var('x')
find_root(f(x)==h(x),x,x_min,x_max)
In eq.(2) S_{i,j,k}(x) is a triple sum function of 'x' and i,j and k are the index of the sum.
How can I solve (numerically) eq.(2)?
Waiting for your answers. Thanks a lot!
Best regards
----------------------------------------------------------
Update:
If I run the next code:
import sympy.mpmath
N=20
A=0.7
G_0 = 37.7
B = 0.36
x = sympy.symbols('x')
def S(x_):
return sympy.mpmath.nsum(lambda i, j, k: (12*A**4*x_**6*i**4-30*A**2*x_**3*i**2*(j**2+k**2)+3*(j**2+k**2)**2)/(2*(A**2*x_**3*i**2+j**2+k**2)**(7/2)),[1,N],[1,N],[1,N])
def F(x_):
return G_0 * (x_ - 1/(x_**2))
print(sympy.mpmath.findroot(F(x) + B*A*sqrt(x)*S(x), [0.85,1]) )
I get the next error:
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<class 'sympy.mpmath.ctx_mp_python.mpf'>'
What am I doing wrong?
Best regards!
mresimulatorWed, 08 Apr 2015 07:59:34 -0500http://ask.sagemath.org/question/26465/Does Sage show steps to solving an equation?http://ask.sagemath.org/question/8042/does-sage-show-steps-to-solving-an-equation/Like how mathematica has the trace function or wolframalpha has in their features? Sometimes wolfram alpha isn't able to show steps for certain problems. I feel this feature is important to me understanding and learning a problem.
Thanks. Nanogear1014Thu, 31 Mar 2011 22:32:55 -0500http://ask.sagemath.org/question/8042/A problem with changing ringshttp://ask.sagemath.org/question/25596/a-problem-with-changing-rings/Why is this piece of code not working?
a = 1; b = 1; c = 1; m = 1; k = 6; w = exp((2*pi*I*m )/k)
p = x^4 - 6*x^2 -x *(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 -w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b))
g = real_part(p).simplify()
q = g.change_ring(QQbar)
I would have thought that I can get the exact roots of `q` above using `.solve` since in the field of algebraic numbers (`QQbar`) the above should have exact roots.PhoenixWed, 21 Jan 2015 12:03:54 -0600http://ask.sagemath.org/question/25596/