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, 07 Jul 2021 20:57:41 +0200Solve cannot get algebraic answer without taking logarithmhttps://ask.sagemath.org/question/57910/solve-cannot-get-algebraic-answer-without-taking-logarithm/I'm trying to solve the simple, one variable equation: `8^(3*x) = 16^(x+1)`.
I am new to Sage, so I assume that I am doing something wrong. I like the Jupyter notebook interface and am hoping to use SageMath as my "go to" tool.
Mathematica, wolframalpha, and Mathcad 6 (mupad symbolic engine) solve this as is (x=4/5).
Sage and Mathcad 7 (new symbolic engine) both seem to require what would be the first step if I were to do manual solve -- take log of both sides.
SageMath 9.2
Fails:
sage: x = var('x')
sage: assume(x,'real')
sage: solve( 8^(3*x)-16^(x+1)==0, x)
[8^x == 1/2*16^(1/3*x + 1/3)*(I*sqrt(3) - 1),
8^x == -1/2*16^(1/3*x + 1/3)*(I*sqrt(3) + 1),
8^x == 16^(1/3*x + 1/3)]
Works:
sage: x = var('x')
sage: assume(x,'real')
sage: solve( ln(8^(3*x))-ln(16^(x+1))==0, x)
[x == (4/5)]rogergunWed, 07 Jul 2021 20:57:41 +0200https://ask.sagemath.org/question/57910/solve with 2 unknows typeshttps://ask.sagemath.org/question/56933/solve-with-2-unknows-types/HI
I would like SageMath will give me the solution `[x_00=0,x_10=-2,x_20=0]`
is there a way to do that with 9.2 or should I wait for 9.3 ?
uV=var('x_00, x_10, x_20',domain='integer')
#xyzV=var('x,y, z', domain='real')
xyzV=var('x,y, z', domain='complex')
solve(x^2*x_00 + x*x_10*y + x_20*y^2 == -2*x*y,[x_00 , x_10 , x_20])
solve(x^2*x_00 + x*x_10*y + x_20*y^2 == -2*x*y,[x_00 , x_10 , x_20])
[link text](https://ask.sagemath.org/question/46915/solve-equation-with-two-variables-over-rr/)ortolljTue, 04 May 2021 12:25:01 +0200https://ask.sagemath.org/question/56933/What implementation does sage use for solve?https://ask.sagemath.org/question/56730/what-implementation-does-sage-use-for-solve/What algorithm does sage use when you solve polynomials with the solve() function? MathAllOverThePlaceMon, 19 Apr 2021 20:48:21 +0200https://ask.sagemath.org/question/56730/Cannot evaluate symbolic expression to a numerical valuehttps://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/ I'm trying to do this:
```
(sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)).roots( ring=RealField(100))
```
Unfortunately I get the error in the title.
Also any other way of solving the above equation numerically would be appreciated. I was able to do it in maxima using `find_root` but was hoping for a better function (one that doesn't require specifying an interval). I couldn't use find_root in sage because it returns the error 'unable to simplify to float approximation' and ofcourse `solve` doesn't return explicit solutions.Dr. BananaFri, 16 Apr 2021 17:06:47 +0200https://ask.sagemath.org/question/56672/f(leftVarlist)== f(rigthVarList)=solve(sysEqu,leftVarList,rigthVarList)https://ask.sagemath.org/question/55752/fleftvarlist-frigthvarlistsolvesysequleftvarlistrigthvarlist/ I will find it convenient that SageMath would have a solve function like this:
sysEqu=[] # system of equations ;
leftVarList=[] # left variables list ;
rightVarList=[] # right variables list
solve(sysEqu,leftVarList,rigthVarList)
It will return f(leftVarlist)== f(rigthVarList) if possible and return [] if not.
Maybe it is too hard to write this kind of function ? (I know simplification is difficult subject in math soft), or
maybe the solve function is already able to do this, and I just need to set it up correctly ? (Sorry if it is the case!)
To illustrate my proposal I started to write a draft of this kind of function, (badly written, and which does not work correctly!) :
varL=[]
# all red segments
varL.append(var("A",latex_name=r"\color{red}{A}"))
varL.append(var("Ap",latex_name=r"\color{red}{A'}"))
varL.append(var("App",latex_name=r"\color{red}{A''}"))
# all green segments
varL.append(var("AppX",latex_name=r"\color{green}{\overline{A''X}}"))
varL.append(var("AU",latex_name=r"\color{green}{\overline{AU}}"))
varL.append(var("ApY",latex_name=r"\color{green}{\overline{A'Y}}"))
# all pink segments
varL.append(var("AX",latex_name=r"\color{pink}{\overline{AX}}"))
varL.append(var("ApW",latex_name=r"\color{pink}{\overline{A'W}}"))
# all blue segments
varL.append(var("X",latex_name=r"\color{blue}{X}"))
varL.append(var("U",latex_name=r"\color{blue}{U}"))
varL.append(var("W",latex_name=r"\color{blue}{W}"))
varL.append(var("Y",latex_name=r"\color{blue}{Y}"))
varL.append(var("Z",latex_name=r"\color{orange}{Z}"))
for v in varL :
assume(v,'real')
assume(v!=0)
eqL=[
AppX/X == AU/U,
AppX/X == ApY/Y,
App/X == A/U,
App/X == Ap/Y,
AppX/App == AU/A,
AppX/App == ApY/Ap,
A/X == Ap/W,
A/X == -(A - Ap)/(W - X),
A/AX == Ap/ApW,
X/AX == W/ApW,
AU/AX == ApY/ApW,
AU/(U - X) == -ApY/(W - Y),
AX/(U - X) == -ApW/(W - Y),
]
show(varL)
index=0
latexL=[]
for eq in eqL :
show(" equ # : ",index," \t : ",eq," \t valid =",eq.is_exact())
latexL.append(r"\text{equ #} "+str(index)+" : "+latex(eq))
index+=1
def isTheSame(t0,t1):
#test if tuple or list have same elements notwithstanding order
t0l=len(t0) ;t1l=len(t1)
if t0l!=t1l :
return False
for tt in t0:
if tt not in t1 :
return False
return True
# I have to tinker !!
# Do It YourSelf function which does not work correctly.
def solvit(eq0L,vare,mainVariables) :
advanticeVariablesL=[]
for eq in eq0L :
vart=eq.variables()
for v in vart :
if v not in mainVariables :
if v not in advanticeVariablesL :
advanticeVariablesL.append(v)
mainVariables=tuple(mainVariables)
advanticeVariables= tuple(advanticeVariablesL)
show("advantice Variables : ",advanticeVariables)
# show("main :",mainVariables)
#stopLoop=False
#solution=0==0
for indexAdv in range(0,len(advanticeVariables)-1):
#if stopLoop:
# break
v=advanticeVariables[indexAdv]
#show("var to remove : ",v," : ",indexAdv)
equLength=len(eq0L)-1
indexEq=0
while indexEq < equLength :
#if stopLoop:
# break
#show("indexEq : ",indexEq)
if v in (eq0L[indexEq]).variables(): # look for unwanted variables
sol=solve(eq0L[indexEq],v)
eq0L.remove(eq0L[indexEq])
equLength-=1
#show("eq0L length : ",equLength)
for indexEq in range(0,equLength-1):# replace v in all other equ
eqt=eq0L[indexEq].subs(sol).simplify_full()
eq0L[indexEq]=eqt
soleqt=solve(eqt,vare)
if len(soleqt)>0 :
#show("soleqt : ",soleqt)
if isTheSame(soleqt[0].variables(),mainVariables) :
solution=soleqt[0]
#show("solution : ",solution)
return [solution,eq0L,indexAdv,advanticeVariables[indexAdv]]
#stopLoop=True
#break
indexEq+=1
return [0==1,eq0L,indexAdv,advanticeVariables[indexAdv]]
solution,remainingEquationsL,indexAdv,Adv=solvit(copy(eqL),W,[U,X,Y,W])
show("solution : ",solution," \t len remainingEquationsL : ",len(remainingEquationsL),
" \t step :",len(eqL)-len(remainingEquationsL),"\t index Adv :",indexAdv,"\t Adv : ",Adv)
# attempt with solve only
show("With solve only W ",solve(eqL,W))
show("With solve [U,W,X,Y] ",solve(eqL,[U,W,X,Y]))
show("With solve only only W sol dict",solve(eqL,W,solution_dict=True))
show("With solve [U,W,X,Y] and sol dict",solve(eqL,[U,W,X,Y],solution_dict=True))
[complete code on SageCell](https://sagecell.sagemath.org/?z=eJztXd1u20YWvi_Qd5hIFyJtypKcDYK6y8UKmxTdIgWKTbWUoHiFkTiSWFMkTQ5lOoFfZu_S1_CL7TkzJEVJpOL83O35Wsgi53znb85QM8zFSdbhndFaxuGGybVg8zC8YVe_hWnM_M7PYRAI-OYKuHidRLEn2c_phnuBxSK-EuzFS2b9InjAXnkidUH68WPL_P67ROlcSxld9Xp3d3cXQbpx-eYijFc9Hktv4Yve299-_nU2-OGHv8xms-ez4WDWv4jcJbJdsWS-F4ifwKffQi-QiRHJgRXJS_Pq--8YwFsyuHU57V93YQT-mM_sPrtibca3oeey9yIOmettvcQLA_ZMkxDcVryB5g2uzd6BHi0q_ERcnWIN-v8xuoO-uZPR3-a2lujyM61Q346FTOOATbk1tzZeYOgxS5s2mbXh2cE9IO4n4h-hWA4DV-XD4CA2KJLRYBMU2dMk9LfC4GfZ-dy2-1ZmwvBFvE4M06rzDfg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Qgizn0Qy9BOvoT8fuECbm7vwljjhewEFaPH4PHj3B5UdH2igcJOJNKthDsFlbKHyo8cAi-BB0upcoLTxcpxBA_fsSXIyJIBFr5QwW2wew9fgwXizTSYYIzfieEMsMpcDsYYurJqllIp68NMfUPUSpKSF4aM4gZkuvCyVjoqLzu5vHPjdin84C9goS7mKSPLb09K_cSbdy-CPUvaWUF4SamvTvsQDmX_xapa1nc5v9KZ-aCauzcHvwPM6-bjQ==&lang=sage&interacts=eJyLjgUAARUAuQ== )ortolljWed, 17 Feb 2021 08:58:43 +0100https://ask.sagemath.org/question/55752/Simple 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 14:46:18 +0100https://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?KapcakWed, 23 Dec 2020 01:22:04 +0100https://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)cybervigilanteWed, 11 Nov 2020 02:48:58 +0100https://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 14:12:04 +0200https://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 12:07:25 +0200https://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 21:39:24 +0200https://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 16:23:39 +0200https://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 11:18:45 +0200https://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 08:29:03 +0200https://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
bsoSat, 15 Aug 2020 00:43:55 +0200https://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 15:23:58 +0200https://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 09:54:19 +0200https://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 11:56:41 +0100https://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?EconJohnThu, 16 Jul 2020 05:13:23 +0200https://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?
loloraSun, 05 Jul 2020 03:32:28 +0200https://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 16:55:09 +0200https://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 09:10:20 +0200https://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 19:29:58 +0200https://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 19:16:47 +0200https://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 16:35:14 +0200https://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 19:24:47 +0200https://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 15:37:12 +0200https://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 07:02:07 +0100https://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 21:10:48 +0100https://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)maanMon, 25 Nov 2019 04:25:03 +0100https://ask.sagemath.org/question/48869/