ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 14 Jan 2021 07:46:18 -0600SImple Trigonometric Equation solvinghttps://ask.sagemath.org/question/55268/simple-trigonometric-equation-solving/I was a MapleV user in the past (~25 years ago) an I'm very pleased to find such an elegant solution the sage is.
I try to see how it works trying to solve an easy trigonometry calculation:
var('r,l,m')
ex = l/sin(m/2/r)-r
solve(ex,r)
[r == l/sin(1/2*m/r)]
Do not want, ok. To simplify I put some real values m and l and tried again:
exval = ex.subs(l=7.2,m=10)
solve(exval,r)
[r == 36/5/sin(5/r)]
still not solving, r=3.68357 is what I'm searching for. What would be a right way to proceed?
Thank you in advance, v42
vladimir42000Thu, 14 Jan 2021 07:46:18 -0600https://ask.sagemath.org/question/55268/A Simple Exponential Equationhttps://ask.sagemath.org/question/54862/a-simple-exponential-equation/Sage can solve the equation $8^t =37$ for $t$:
solve( (8)^t ==37, t )
But strangely, cannot solve $\left(\frac 89\right)^t =37$
solve( (8/9)^t ==37, t )
Any ideas?KapcakTue, 22 Dec 2020 18:22:04 -0600https://ask.sagemath.org/question/54862/plot does not gibe with solve for log equationshttps://ask.sagemath.org/question/54209/plot-does-not-gibe-with-solve-for-log-equations/ If I plot two log equations in x and y I get an obvious intersection, but when I try solve on them I get nothing. Is there a way to get a mathematical solution that gibes with the plot?
var('x y')
implicit_plot(log(x*sqrt(y)),(x,0,8),(y,0,8),color="black") + implicit_plot(log(x^2*y^2),(x,0,8),(y,0,8),color="red")
solve(log(x*sqrt(y)) == log(x^2*y^2),x,y)
[]
![image description](/upfiles/16050592939713841.png)cybervigilanteTue, 10 Nov 2020 19:48:58 -0600https://ask.sagemath.org/question/54209/How to get access of a single solution from a bunch of solutionshttps://ask.sagemath.org/question/53996/how-to-get-access-of-a-single-solution-from-a-bunch-of-solutions/ I do not use the thing for longer time, so I had a question.
If I say
a,b,c,d,e,x = var('a b c d e x')
f(x)=a*x^4+b*x^3+c*x^2+d*x+e
f1(x)=diff(f(x),x)
f2(x)=diff(f(x),x,2)
sols = solve([f(0)==-2, f(2)==0, f1(4)==0, f(4)==8, f2(2)==0], a,b,c,d,e)
print(sols)
I get
[
[a == (3/16), b == (-41/16), c == (87/8), d == -12, e == -2]
]
How can I have these single value separately? <br>
That means: I want to get an output `f(x) = 3/16*x^4 -41/16*x^3 +87/8*x^2 -12*x -2` <br>
(which I can copy and paste).geroyxWed, 21 Oct 2020 07:12:04 -0500https://ask.sagemath.org/question/53996/Plot the solution of a system of equationshttps://ask.sagemath.org/question/53991/plot-the-solution-of-a-system-of-equations/ With
a,b,c,d,e,x = var('a b c d e x')
f(x)=a*x^4+b*x^3+c*x^2+d*x+e
f1(x)=diff(f(x),x)
f2(x)=diff(f(x),x,2)
solve([f(0)==-3, f(2)==0, f2(4)==0, f1(6)==0, f(6)==4], a,b,c,d,e)
I get `[[a == (-7/432), b == (43/216), c == (-5/6), d == (5/2), e == -3]]`
How can I plot `f(x)` with these values?geroyxWed, 21 Oct 2020 05:07:25 -0500https://ask.sagemath.org/question/53991/plotted real intersection but solve only shows imaginaryhttps://ask.sagemath.org/question/53835/plotted-real-intersection-but-solve-only-shows-imaginary/I plotted `x^3 - x` and its derivative `3*x^2 - 1` to get two intersections in the real plane.
plot([x^3-x,3*x^2 - 1],-3,3,color=['blue','green'],legend_label=["f","derivative"])
![intersection](/upfiles/16024461625093012.png)
However, when I solved the two with `solve(x^3-x == 3*x^2 - 1, x)`, all I get are imaginary values.
solve(x^3-x == 3x^2 - 1,x)
[x == -1/2*(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3)*(I*sqrt(3) + 1) - 2/3*(-I*sqrt(3) + 1)/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1, x == -1/2*(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3)*(-I*sqrt(3) + 1) - 2/3*(I*sqrt(3) + 1)/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1, x == (1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 4/3/(1/9*I*sqrt(37)*sqrt(3) + 1)^(1/3) + 1]
Shouldn't `solve` show me the two intersections or am I disastrously confused?cybervigilanteSun, 11 Oct 2020 14:39:24 -0500https://ask.sagemath.org/question/53835/What is the best way to return only real solutions?https://ask.sagemath.org/question/9307/what-is-the-best-way-to-return-only-real-solutions/I'm trying to write a function that filters out non-real solutions returned by solve. For now, I'm using
def select_real(xs):
return map(lambda eq: eq.lhs() == eq.rhs().real(), filter(lambda eq: not bool(eq.rhs().imag()), xs))
and it works for some simple cases like this
sage: select_real(solve(x^3+8==0, x))
[x == -2]
but this assumes multiple things, like fact that the solve retuns list in the form of actual solutions and imaginary part can be calculated. Generally it is only an ugly hack that I don't like.
I looked at assume(x, 'real') but found out that it does not work ( [Ticket #11941](http://trac.sagemath.org/sage_trac/ticket/11941) ). I also tried to do check using "in RR", but in above case all 3 solutions gave False. Also at first I tried using eq.full_simplify() in map step above, but it turns out that simplifying returns different root than using real/imag:
sage: ((-8)^(1/3)).full_simplify()
-2^(1/3)
sage: ((-8)^(1/3)).real()
1
After all that, I'm out of ideas. What is considered the best way to obtain only real solutions? Thanks in advance.
----------
edit:
I need such functionality because actually I'm preparing materials for high-schoolers who yet do not know about complex numbers, and shouldn't be introduced to them at that moment. My current version (above+extra full_simplify and uniq which are not really part of question) allows me to do for example this:
sage: var('x,a,b,c')
(x, a, b, c)
sage: assume(b^2-4*a*c>0)
sage: select_real(solve(a*x^2+b*x+c==0, x))
[x == -1/2*(b - sqrt(-4*a*c + b^2))/a, x == -1/2*(b + sqrt(-4*a*c + b^2))/a]
sage: forget(assumptions())
sage: assume(b^2-4*a*c==0)
sage: select_real(solve(a*x^2+b*x+c==0, x))
[x == -1/2*b/a]
sage: forget(assumptions())
sage: assume(b^2-4*a*c<0)
sage: select_real(solve(a*x^2+b*x+c==0, x))
[]giniuSun, 09 Sep 2012 09:23:39 -0500https://ask.sagemath.org/question/9307/Finding solution of expression with fractional powerhttps://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/I'm trying to solve this equation
$ 3(2.2+(\frac{64}{r})^{(1/3)})= 4(2.2+(\frac{128}{r-1})^{(1/4)})$ using solve function
I want to obtain the numerical solution
**but when i use `sol[0].n(30)`**
**TypeError:** cannot evaluate symbolic expression numerically
**when i try to `find_root(0,1,r)`**
**ValueError:** negative number to a fractional power not real
How to find the solution of this expression ?
deeppaul589Fri, 04 Sep 2020 04:18:45 -0500https://ask.sagemath.org/question/53299/solve maxima need to prechew equ to succeed (solve sympy ok)https://ask.sagemath.org/question/53100/solve-maxima-need-to-prechew-equ-to-succeed-solve-sympy-ok/ HI
Ubuntu 18.04 , Jupyter notebook SageMath 9.1
vL=['x','y','x_o','y_o','a','b']
varL=var(vL)
for v in varL :
assume(v,'real')
eq02=y - y_o == -b^2*(x - x_o)*x/(a^2*y)
eq2=x^2/a^2 + y^2/b^2 == 1
# here I need to prechew
eq03=eq02.multiply_both_sides(y/b^2).expand()
SmaximaPrechewed=solve([eq03,eq2],x,y)
show("solution maxima ok prechewed : ",SmaximaPrechewed)
SsympyNotPrechewed=solve([eq02,eq2],x,y,algorithm='sympy')
show("solution sympy ok : ",SsympyNotPrechewed)
SmaximaNotPrechewedKO=solve([eq02,eq2],x,y,algorithm='maxima')
show("solution maxima not preChewed KO : ",SmaximaNotPrechewedKO)ortolljWed, 19 Aug 2020 01:29:03 -0500https://ask.sagemath.org/question/53100/Beginner question: How to get y value given x in an equation?https://ask.sagemath.org/question/53019/beginner-question-how-to-get-y-value-given-x-in-an-equation/Hi, I have an equation like so (I put in some simplifying values for the constants):
var('h1 h2 x y n')
n = 4/3
h1 = 1
h2 = 1
g = sqrt(x^2 + y^2) + n * sqrt(x^2 + (h1 + h2 - y)^2) - (h1 + n * h2) == 0
I am able to get a beautiful implicit plot:
graph = implicit_plot(g, (x, -0.5, 0.5), (y, 0, 2.5))
show(graph)
But how do I find out the numerical values at say x = 0.2? This doesn't give numerical values (and I don't really understand its result either):
solve(g(x=0.2), y)
It gives
[sqrt(y^2 - 4*y + 101/25) == -3/4*sqrt(y^2 + 1/25) + 7/4]
Thanks
bsoFri, 14 Aug 2020 17:43:55 -0500https://ask.sagemath.org/question/53019/Solving equation with algebraic numbershttps://ask.sagemath.org/question/52927/solving-equation-with-algebraic-numbers/ Hello, SAGE gives me error when I load this:
solve(x^2-AA(sqrt(3))==0,x)
but it gives no problem when I load
solve(x^2-sqrt(3)==0,x)
This is a small example of a bigger problem I have in which I must solve a system of equations involving algebraic numbers through AA(.) and QQbar(.). How can I make SAGE solve equations with this type of numbers? or there is no way? Thanks!creyesm1992Mon, 10 Aug 2020 08:23:58 -0500https://ask.sagemath.org/question/52927/solve with "excess" equationshttps://ask.sagemath.org/question/10028/solve-with-excess-equations/Why does the following work
solve([a + b - 1, a - b], [a, b])
but this
solve([a + b - 1, a - b, c + d], [a, b])
gives an empty solution?
Can `solve` be convinced to ignore unnecessary equations?andreMon, 15 Apr 2013 02:54:19 -0500https://ask.sagemath.org/question/10028/Symbolic solvehttps://ask.sagemath.org/question/8707/symbolic-solve/Following the [change of variable thread](http://ask.sagemath.org/question/1113),
I wanted to streamline the whole process.
Namely, using the same example in the above thread, I'd like to say
integral_def_change(x*cos(x^2+1), (x, 0, 2*pi), u == x^2 + 1, u)
The difference is, I wanted also Sage to automatically solve for `x`
instead of providing `x = sqrt(u - 1)`, say. But when I tried
solve(u == x^2 + 1, x)[0].rhs()
the output was `r1`.
1- What exactly is r1 ??
A way out (see this [thread](http://ask.sagemath.org/question/1105))
seems to make of the solution a function of `u`
f(u) = solve(u == x^2 + 1, x)[0].rhs()
Now f is
u |--> -sqrt(u - 1)
2- What can I do to get `+sqrt(u - 1)` instead? Is this related to the
[positive function question there](http://ask.sagemath.org/question/989)?Green diodSat, 11 Feb 2012 04:56:41 -0600https://ask.sagemath.org/question/8707/Selecting specific values in Sagehttps://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/ I have the following solution:
solve(...)=[[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]]
Im aware I can get the whole set of solutions back with the use of
solve(...)[0]
[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]
Im only interested in getting back `xa1`. Is there a way to do that?EconJohnWed, 15 Jul 2020 22:13:23 -0500https://ask.sagemath.org/question/52488/why doesn't sage solve lnhttps://ask.sagemath.org/question/52331/why-doesnt-sage-solve-ln/I have a simple equation to solve
> solve(ln(x) -2 > 0,x)
The actual value should be
$x > e^2$
but sagemath gives
> [[log(x) - 2 > 0]]
How do I get actual value?
loloraSat, 04 Jul 2020 20:32:28 -0500https://ask.sagemath.org/question/52331/Solving a polynomial system in a quotient ringhttps://ask.sagemath.org/question/52254/solving-a-polynomial-system-in-a-quotient-ring/I want to compute all solutions in $\mathbb{Z}_9[\sqrt2,x]$, where $x$ is such that $(x+\sqrt2)^2=2(x+\sqrt2)$, of the equation
$$X^2=1.$$
I'm first defining the polynomial ring over $\mathbb{Z}_9$ in variables $x,y$, then factoring by the ideal generated by
$$y^2-2, (x+y)^2-2(x+y),$$
to get the ring $S$, but then I don't know which command to use in order to get the solutions of $X^2-1$. I have tried "solve" and "variety" (defining $S[X]$ first and then the ideal of $X^2-1$), but they do not seem to work. The code up to this point is just
R.<x,y> = PolynomialRing(IntegerModRing(9),order='lex')
J= R.ideal(x^2-2,(x+y)^2-2*(x+y))
S=R.quotient(J)
Which function should I use?Jose BroxMon, 29 Jun 2020 09:55:09 -0500https://ask.sagemath.org/question/52254/solve() need solution pre-chewedhttps://ask.sagemath.org/question/52132/solve-need-solution-pre-chewed/HI
why do i have to square the two terms of the equation so that solve gives me the solution?
why it does not alow him to do square both sides ?
vL=['x','y','r','x_0','y_0','x_p','y_p','x_t','y_t','atg','btg','alpha']
varL=var(vL)
x_0Num=-1/3 ;y_0Num=-1/4 ;rNum=1
numL=[x_0==x_0Num ,y_0==y_0Num ,r==rNum]
assume(x,'real')
assume(abs(x_0)<1)
assume(abs(y_0)<1)
assume(r>=1)
C_u(x)= sqrt(r^2-x^2)
C_d(x)= -sqrt(r^2-x^2)
delta_0(x)=y_0/x_0*x # radial to circle
delta_p(x)=-x_0/y_0*x + y_0+(x_0^2)/y_0 #perpendicular to circle radial delta_0
assume(delta_p>0)
# numerical solution
SupNum=solve((C_u(x)==delta_p(x)).substitute(numL), x, to_poly_solve=True)
# literal solutions which do not work
SupLit1=solve(C_u(x)== delta_p(x), x, to_poly_solve=True)
SupLit2=solve(C_u(x)== delta_p(x), x, algorithm='sympy')
# literal solutions ok
SupLit3=solve(C_u(x)^2== (delta_p(x))^2, x, algorithm='sympy')
SupLit4=solve(C_u(x)^2== (delta_p(x))^2, x, to_poly_solve=True)
show("Sup num : ",SupNum)
show("Sup lit 1 : ", LatexExpr(r" \huge \color{red} {?? }"),SupLit1)
show("Sup lit 2 : ", LatexExpr(r" \huge \color{red} {?? }"),SupLit2)
show("Sup lit 3 : ",SupLit3, LatexExpr(r" \huge \color{green} {OK }"))
show("Sup lit 4 : ",SupLit4, LatexExpr(r" \huge \color{green} {OK }"))
![image description](/upfiles/1592784453245354.png)
![image description](/upfiles/15928078377851914.png)
projection in the other side is easy, but unfortunately the projection matrix is not invertible.
pointInsideCircle=False # projection from outside circle to intside
# alpha is angle between radial vector([(x_0,y_0),(0,0) ]) and tangente line from x_0,y_0 to circle
# (the sides V_R,V_tg,r form a rectangle triangle)
sin(alpha)=r/sqrt(x_0^2+y_0^2)
cos(alpha)=sqrt(1-sin(alpha)^2)
# radial vector from [x_0,y_0]
# we want it directed to the center of the circle so it is multiplyed by -1
V_R0=matrix(SR,[x_0,y_0]).transpose()*-1
#reduction factor because (||V_R||*cos(alpha)=||V_tg||)
reductFactor=cos(alpha)
# rotation matrix and shrink to get tangent vector V_tg
rotM=matrix(SR,[[cos(alpha),-sin(alpha)],[sin(alpha),cos(alpha)]])*reductFactor
# projection Matrix on radial Vector
projectOnRadialVectorM=matrix(SR,[(x_0^2/(x_0^2 + y_0^2), x_0*y_0/(x_0^2 + y_0^2)),
(x_0*y_0/(x_0^2 + y_0^2), y_0^2/(x_0^2 + y_0^2))])
# V_tg is the tangent vector
V_tg=rotM*V_R0
# vector ([[0,0],[x_t,y_t]) from (0,0) to tangent point
V_r=-v_R0+V_tg
# now project the tangent vector on radial Vector
V_p=(projectOnRadialVectorM*V_tg)
V_orthoToRadial=V_tg-V_p
# projected point ProjectPt of [x_0,y_0]= projected vector - radial vector [[x_0,y_0][0,0]
ProjectPt=V_p-V_RortolljSun, 21 Jun 2020 02:10:20 -0500https://ask.sagemath.org/question/52132/solve() simple equ, something is missing ?https://ask.sagemath.org/question/51978/solve-simple-equ-something-is-missing/ HI
Sagemath 9.1 notebook ,OS :Ubuntu 18.04
what should i add or precise, so that SageMath solve this equation ?:
assume(x,'real')
solve (sqrt(-x^2 + 1)==-4/3*x - 25/36,x)
output :[x == -3/4*sqrt(-x^2 + 1) - 25/48] ?
[on wolfram alpha](https://www.wolframalpha.com/input/?i=solve+sqrt%28-x%5E2+%2B+1%29%3D-4%2F3*x+-+25%2F36)
ortolljSun, 14 Jun 2020 12:29:58 -0500https://ask.sagemath.org/question/51978/solve: Possible bug?https://ask.sagemath.org/question/51910/solve-possible-bug/Hello,
This question is relevant to Question #2 in the topic "desolve: wrong solution?!". If **desolve** is using **solve** internally when initial conditions are invoked to find the constants after obtaining the general solution, perhaps this is where the problem lies.
Consider the following expression
a=var('a')
f=-1/2*(I*sqrt(3)*2^(1/3) - 2^(1/3))/(-2*a - 1)^(1/3)
sol=solve(f==-2,a);show(sol)
sol is [a == (-5/8)]
Now, if we plug that back in f,
check=f.subs(sol).n();print(check`)
this gives 1.00000000000000 - 1.73205080756888*I, where it ought to give -2 (if there is a solution)
And I tried this with Mathematica also
Solve[-1/2 (I Sqrt[3] 2^(1/3) - 2^(1/3))/(-2 a - 1)^(1/3) == -2, a]
It returns an empty list {} for this, indicating that there is no solution.
What is wrong with Sage's **solve** function here?
Update:
I tried **solve** with "sympy" agorithm. It agreed with Mathematica. It looks like there is a problem with Maximacurios_mindThu, 11 Jun 2020 12:16:47 -0500https://ask.sagemath.org/question/51910/Solving for an unknown function in a logarithmic expressionhttps://ask.sagemath.org/question/50445/solving-for-an-unknown-function-in-a-logarithmic-expression/Hello,
Please consider the following code:
k=var('k')
f=function('f')(x)
solve(-1/3*log(f(x) + 1) + 1/3*log(f(x) - 2) == -k+x, f,to_poly_solve=True)
even if I call the solve function as
solve(-1/3*log(f(x) + 1) + 1/3*log(f(x) - 2) == -k+x, f(x),to_poly_solve=True)
or
solve(-1/3*log(f + 1) + 1/3*log(f - 2) == -k+x, f,to_poly_solve=True)
or
solve(-1/3*log(f+ 1) + 1/3*log(f - 2) == -k+x, f(x),to_poly_solve=True)
This always throws back [] at me.
However, if I substitue the function f with the variable z as shown below
k=var('k')
f=function('f')(x)
z=var('z')
solve((-1/3*log(f(x) + 1) + 1/3*log(f(x) - 2) == -k+x).subs(f(x)==z), z,to_poly_solve=True)
I get an answer
[z == (2*e^(3*k) + e^(3*x))/(e^(3*k) - e^(3*x))]
Under normal circumstances (where I don't need to use to_poly_solve=True) solve solves for the function.
Is there anyway to solve for a function (without the need to substitute it with a variable) when to_poly_solve=True is enabled?
Thanks in advance
curios_mindTue, 31 Mar 2020 09:35:14 -0500https://ask.sagemath.org/question/50445/solve() does not solvehttps://ask.sagemath.org/question/50421/solve-does-not-solve/The output of this system is [] after waiting 10 mins. What's the problem here?
var('a2,b2')
solve([
log(10,a2) + log(10,b2) * 435 == 50.88,
log(10,a2) * 435 + log(10,b2) * 8555 == 979.15], a2,b2)Alex89Sun, 29 Mar 2020 12:24:47 -0500https://ask.sagemath.org/question/50421/how to find a local maximum?https://ask.sagemath.org/question/8890/how-to-find-a-local-maximum/Hello. I'm fairly new to Sage, so lets see if someone more experienced can help!
Say I have a function f(x) continuous in [a,b] and derivable in (a,b).
How can I implement in Sage a function 'maximum(f,a,b)' that returns the maximum of f(x) in [a,b] (as a numerical approximation, not as an expression)?
Thanks you a lot!NilSun, 15 Apr 2012 08:37:12 -0500https://ask.sagemath.org/question/8890/can sage return a list of numbers from solve() instead of expressions?https://ask.sagemath.org/question/49245/can-sage-return-a-list-of-numbers-from-solve-instead-of-expressions/ is there any builtin methods to have `solve()` return a list of numbers instead of the sequence of expressions that it does?
which is to say `solve(eqn, x)` would return:
> $[x_1, x_2, ...,x_n]$
instead of:
> $[x == x_1, x == x_2, ... , x == x_n]$
or if there are not any built in functions recommended approaches? this is in a sage script im rating that at this point in the program is taking polynomials, computing their first and second derivatives, and adding the roots of those derivatives to a list, which needs to be iterable. if there does not exist some sage method or options for this, i believe i would need to revert to regex, which feels like im doing something wrong if thats what im having to do herealienfetuseaterSun, 29 Dec 2019 00:02:07 -0600https://ask.sagemath.org/question/49245/Equation solver with assumehttps://ask.sagemath.org/question/48899/equation-solver-with-assume/Odd behaviour: the following gives a solution:
x, c, k = var('x, c, k')
assume(k > 0)
assume(k, "integer")
solve(x**k == (k/c), x)
but the following does not:
x, c, k = var('x, c, k')
assume(k > 0)
assume(k, "real")
solve(x**k == (k/c), x)
I should be able to remove the assume(k, "datatype") completely, right?technossomyTue, 26 Nov 2019 14:10:48 -0600https://ask.sagemath.org/question/48899/How to solve an equation over finite field for exponent variable?https://ask.sagemath.org/question/48869/how-to-solve-an-equation-over-finite-field-for-exponent-variable/I want to resolve the following equation for exponent $n$ for given value $v$:
$$ v\equiv(r\cdot ((b+r)^n- (b-r)^n)) \cdot (2 \cdot r \cdot ((b+r)^{n-1}- (b-r)^{n-1}))^{-1} \mod P$$
with
$$r^2 = 4\cdot a+b^2 \mod P$$
and a prime $P$
Looking for a function $f(v) = n$.
The values $a,b$ are chosen in that way that for $n=[1,..,P]$ the results $v$ will be all values in ${{0,..,P-1 }\brace{ }}=\mathbb{F}_P $. That works iff there is no such root $r$ in $\mathbb{F}_P$ exists for $a, b$. If both parts in formula above are expanded only $r^2$ is left over.
*Example*:
$P=11; a=5; b=3 -> r^2=7$
R.<a,b,r,v,n>=PolynomialRing(GF(11))
[ r*((b+r)^n-(b-r)^n)/ (2* r*((b+r)^(n-1)-(b-r)^(n-1)) ) for n in R.base() if n>1]
[b,
(-5*b^2 + 2*r^2)/(-3*b),
(-3*b^3 - 3*b*r^2)/(b^2 + 4*r^2),
(-b^4 - 2*b^2*r^2 + 2*r^4)/(5*b^3 + 5*b*r^2),
(b^5 - 4*b^3*r^2 + b*r^4)/(-2*b^4 - 4*b^2*r^2 + 4*r^4),
(3*b^6 + 4*b^4*r^2 - 2*b^2*r^4 + 2*r^6)/(2*b^5 + 3*b^3*r^2 + 2*b*r^4),
(5*b^7 + 2*b^5*r^2 + 2*b^3*r^4 + 5*b*r^6)/(-5*b^6 - 3*b^4*r^2 - 4*b^2*r^4 + 4*r^6),
(-4*b^8 + 3*b^6*r^2 - b^4*r^4 - 5*b^2*r^6 + 2*r^8)/(-b^7 + 4*b^5*r^2 + 4*b^3*r^4 - b*r^6),
(-2*b^9 - 2*b^7*r^2 - 2*b^5*r^4 - 2*b^3*r^6 - 2*b*r^8)/(3*b^8 - 5*b^6*r^2 - 2*b^4*r^4 + b^2*r^6 + 4*r^8)]
in values: $0, 3 , 1 , 8 , 5 , 4 , 7 ,10 , 9 , 6 , 2 , 0 , 3 , 1 , ...$
There is some special case for $n=1$. With this the part which need to be inverted is $0$. In that case $v$ is assigned to 0.
-----------------------------------------
As a alternative form without any root $r$ (for $n>2$):
$$v\equiv \frac{2 \cdot \sum_{k=1}^{\lfloor n/2\rfloor} {n-1\choose 2k-1} b^{n-2k}(r^2)^{k} }{4\cdot \sum_{k=1}^{\lfloor (n-1)/2 \rfloor} {n-2 \choose 2k- 1} b^{n-2k-1} (r^2)^{k } } \mod P$$
in sagemath:
a,b,r,v,k,n=var('a b r v k n')
(sum( 2*binomial(n-1, 2*k-1) * b^(n-2*k)*(4*a+b^2)^(k) , k,1,floor( n/2) ))*(sum(4* binomial(n-2, 2*k-1) * b^(n-2*k-1)*(4*a+b^2)^(k) , k,1, floor( (n-1)/2) ))^(-1)-v
But only got it working with normal variables.
-------
How can I solve such equation in sagemath?
R.<n>=PolynomialRing(GF(11))
(2*k-8).roots(); #multiplication works
(2^k-8).roots(); #power not working
($a,b,r^2$ can be exchanged with current values)maanSun, 24 Nov 2019 21:25:03 -0600https://ask.sagemath.org/question/48869/How to find all roots with solve?https://ask.sagemath.org/question/48808/how-to-find-all-roots-with-solve/I have the following quantity:
c_p = 1 - (4*sin(th)^2+2*5*sin(th)/pi+(5/(2*pi))^2)
and I am trying to find its roots (the solutions for `c_p==0`).
When plotting `c_p` as a function of `th` between $-\pi$ and $\pi$, I can see the curve crosses the x-axis at four positions. However, `solve(c_p==0, th)` is only giving two roots:
$$\left[\theta = -\arcsin\left(\frac{5}{4 \ \pi} + \frac{1}{2}\right),\quad \theta = -\arcsin\left(\frac{5}{4 \ \pi} - \frac{1}{2}\right)\right].$$
It appears that `solve` can only find the roots that are in the domain of the $\arcsin$ function, i.e in the interval $[-\dfrac{\pi}{2},\dfrac{\pi}{2}]$. Is there a way to get the other two roots?TofiMon, 18 Nov 2019 18:27:26 -0600https://ask.sagemath.org/question/48808/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.NilSat, 14 Apr 2012 18:17:01 -0500https://ask.sagemath.org/question/8886/How to solve this algebraic equation by SageMath (rather than by hand)https://ask.sagemath.org/question/48566/how-to-solve-this-algebraic-equation-by-sagemath-rather-than-by-hand/$$u = \frac{\sqrt{a^2+(r+t)^2}-\sqrt{a^2+(r-t)^2}}{2r}$$
How does one solve for $t$ in terms of all the other variables using SageMath?
Note: The purpose of this problem is not to find the solution per se, since we can solve it easily by hand, but to solve it completely by the machine algebra in SageMath. I am having difficulty coaxing SageMath to do that.
I tried the following SageMath code but failed to find the solution. What is the correct script?
u,r,t,a = var('u','r','t','a')
g = (sqrt(a^2 + (r+t)^2) - sqrt(a^2 + (r-t)^2))/(2*r)
ae = (g==u)
view(solve(ae,t))
The output is:
sqrt(a^2 + r^2 + 2*r*t + t^2) == 2*r*u + sqrt(a^2 + r^2 - 2*r*t + t^2)
However, this is not the desired solution.HansThu, 31 Oct 2019 03:24:28 -0500https://ask.sagemath.org/question/48566/Not understanding behavior with solution to simultaneous quadratic equationshttps://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/Hello,
I should preface this by saying I'm brand-new to sage so am probably missing some basics.
I'm writing because I wanted to use Sage to explore the behavior of a system of quadratic equations.
Here's my code
c = 299792458
eps1 = ( vector([9, 10, 10]).norm() -1 ) / c
eps2 = ( vector([9, -10, 10]).norm() -1 ) / c
eps3 = ( vector([-11, 10, 10]).norm() -1 ) / c
eps4 = ( vector([-11, -10, 10]).norm() -1 ) / c
x,y,z,D = var('x y z D') # GPS solution
x1,y1,z1 = var('x1 y1 z1') # Coordinates of P1
eq1 = (x - 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps1 - D)^2
eq2 = (x - 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps2 - D)^2
eq3 = (x + 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps3 - D)^2
eq4 = (x + 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps4 - D)^2
If I solve the system with `S = solve([eq1, eq2, eq3, eq4,D==0], x, y, z, D)`I get symbolic solutions as expected (y is constantly 0 which is unexpected and doesn't seem right, but that's a different matter).
However, if I try to specify values for x1,y1,z1 by using `solve([eq1, eq2, eq3, eq4, x1==0, y1==0, z1==0, D==0], x, y, z)` it returns an empty list, which I assume means no solution. On the other hand, if I use my solution `S` from before and explicitly substitute `x1==0, y1==0, z1==0, D==0` I get the solutions I'm expecting.
Could anyone explain this behavior? Is it somehow easier for Sage to solve the more general equation than the one with parameters plugged in? Will Sage sometimes fail to find existent solutions to such systems, or have I just done something wrong?
Many thanks,
Justin Justin BrodyTue, 22 Oct 2019 07:52:47 -0500https://ask.sagemath.org/question/48466/solve equation with two variables over RRhttps://ask.sagemath.org/question/46915/solve-equation-with-two-variables-over-rr/Hi,
I have a problem with the following code (minimal example) in SageMath 8.7 notebook:
x, y = var('x,y', domain=RR)
solve(x == 0, x, y)
when executed, I get the following error:
/opt/sagemath-8.7/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
1357 if to_check:
1358 for ix, soln in reversed(list(enumerate(X))):
-> 1359 if soln.lhs().is_symbol():
1360 if any(a.contradicts(soln) for a in to_check):
1361 del X[ix]
AttributeError: 'list' object has no attribute 'lhs'
both
x, y = var('x,y')
solve(x == 0, x, y)
and
x, y = var('x,y', domain=RR)
solve(x == 0, x)
work as expected.
I am sorry if that question a already been posted, I don't know which keyword to use.
Pierre MacherlFri, 14 Jun 2019 09:48:56 -0500https://ask.sagemath.org/question/46915/