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, 15 Jun 2022 15:19:19 +0200Correct syntax for "solve(f.derivative(x1,x2)==(0,0))"https://ask.sagemath.org/question/62846/correct-syntax-for-solvefderivativex1x200/ I am trying to create simple code to identify critical points of a multivariate function. For pedagogical reasons, I want to do this completely manually. That is, I first want to compute the gradient, and then I want to solve for points where the gradient is zero. Here is my code:
var('x1 x2')
f(x1,x2) = x1^2 + x2^2
Df=f.derivative()
solve(Df(x1,x2)==(0,0),(x1,x2))
The third step returns what I want. If I evaluate `Df(x1,x2)`, Sage returns `(2*x1, 2*x2)` as expected. However the final step returns the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-bc76a33e3a15> in <module>
----> 1 solve(Df(x1,x2)==(Integer(0),Integer(0)),(x1,x2))
/var/tmp/sage-jc4b6yulaujayb9sr94ia88eourzeqip0oidmas3/local/lib/python3.8/site-packages/sage/symbolic/relation.py in solve(f, *args, **kwds)
1045
1046 if not isinstance(f, (list, tuple)):
-> 1047 raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
1048
1049 # f is a list of such expressions or equations
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
cav24Wed, 15 Jun 2022 15:19:19 +0200https://ask.sagemath.org/question/62846/Solving multilinear integer equationshttps://ask.sagemath.org/question/8699/solving-multilinear-integer-equations/I'd like to explore the solutions of a multilinear diophantine equation like $12(yz) + 6(y+z) +2 -4xw -2(w+x) = 0$. In particular I'd like to generate instances of solutions. I tried the function solve like:
(x,y,z,w) = var('x,y,z,w')
assume(x, 'integer'); assume(y, 'integer')
assume(z, 'integer'); assume(w, 'integer')
solve([12*(y*z) + 6*(y+z) +2 -4*x*w -2*(w+x) == 0, y==y], x)
which gives me the not particularly useful output:
[[x == (3*(2*r1 + 1)*r2 + 3*r1 - r3 + 1)/(2*r3 + 1), y == r1, z == r2, w == r3]]
I'd like to generate some actual quadruples that solve this equation or possibly investigate the structure more. Is there some systematic way to do this? In particular, when playing around with coefficients, is there a test of existence of an integer solution?
**Edit**: I had typos in the first version, I edited the equation.
ThomasMon, 06 Feb 2012 09:06:08 +0100https://ask.sagemath.org/question/8699/Strange problem with Solve functionhttps://ask.sagemath.org/question/62372/strange-problem-with-solve-function/I am running into a strange issue when trying to solve an equation, which seems pretty simple to solve. When I ask SAGE preform
x=var('x')
solve(1630*x^3 + 2991*x^2 + 1628*x + 1==0, x)
Everything goes fine, and it gives me the roots of the equation. However, when I ask it to do the same for a larger equation, I get this:
x=var('x')
solve(1953125*x^5 + 6793750*x^4 + 5942255*x^3 + 8749866*x^2 + 5857878*x + 1==0, x)
and the result is:
[0 == 1953125*x^5 + 6793750*x^4 + 5942255*x^3 + 8749866*x^2 + 5857878*x + 1]
And I do not understand why. I even checked using WolframAlpha, and the issue is not that this equation has no roots. Indeed, WolframAlpha was able to solve this equation with no issues.
What is the issue here? What am I missing?RuneMon, 09 May 2022 19:02:02 +0200https://ask.sagemath.org/question/62372/Solve much slower than Mathematica for simple systemhttps://ask.sagemath.org/question/61202/solve-much-slower-than-mathematica-for-simple-system/Mathematica solves the following system of multivariate polynomials almost instantaneously while sagemath takes around 10 seconds. Is there any way to speed up solve?
vars('a15, x13_14, a4, a11, a0, x14_15, x11_13, x5_5, x9_12, a5, a12, x3_4, a1, x7_7, x11_14, x12_15, x5_6, x4_4, x9_9, a6, a13, x3_5, a2, x10_10, x7_8, x6_6, x5_7, x12_12, x8_8, a7, x3_6, x6_7, x14_14, a9, x15_15, x4_6, x11_11, x8_9, a8, x10_12, a14, x13_13, a3, a10, x4_7, x12_14, x11_12, x13_15, x10_13')
polys = [-x3_4*x9_12, -x10_12*x3_4, -x10_13*x3_4, -x11_12*x3_4, -x11_13*x3_4, -x11_14*x3_4, x3_4^2*x7_7, x7_8*x8_9, -x11_12^2*x8_8, -x12_12*x3_4 + x3_4*x4_4, -x12_14*x3_4 + x3_4*x4_6, -x12_15*x3_4 + x3_4*x4_7, -x13_13*x3_4 + x3_4*x5_5, -x13_14*x3_4 + x3_4*x5_6, -x13_15*x3_4 + x3_4*x5_7, -x14_14*x3_4 + x3_4*x6_6, -x14_15*x3_4 + x3_4*x6_7, -x15_15*x3_4*x7_8 + x3_4*x7_8, x3_4*x3_5*x7_7, x3_4*x3_6*x7_7, a0 - 1, a1 - 1, a2 - 1, a3 - 1, a4*x4_4 - 1, a5*x5_5 - 1, a6*x6_6 - 1, a7*x7_7 - 1, a8*x8_8 - 1, a9*x9_9 - 1, a10*x10_10 - 1, a11*x11_11 - 1, a12*x12_12 - 1, a13*x13_13 - 1, a14*x14_14 - 1, a15*x15_15 - 1]
vs = [a15, x13_14, a4, a11, a0, x14_15, x11_13, x5_5, x9_12, a5, a12, x3_4, a1, x7_7, x11_14, x12_15, x5_6, x4_4, x9_9, a6, a13, x3_5, a2, x10_10, x7_8, x6_6, x5_7, x12_12, x8_8, a7, x3_6, x6_7, x14_14, a9, x15_15, x4_6, x11_11, x8_9, a8, x10_12, a14, x13_13, a3, a10, x4_7, x12_14, x11_12, x13_15, x10_13]
%time solve(polys, *vs)
This takes about 10 seconds
dddFri, 18 Feb 2022 19:57:18 +0100https://ask.sagemath.org/question/61202/Using "Z with subscript" parameters in `solve` solutionshttps://ask.sagemath.org/question/61127/using-z-with-subscript-parameters-in-solve-solutions/Trying to solve some equation and faced with `z` with subscript notation. Tried to google it but failed.
sage: t = SR.var('t')
sage: eq = cos(t) + 6 - 5 - 1.5 * sin(t) == 0
sage: sol = solve([eq], t, to_poly_solve=True)
sage: sol
[t == pi + 2*pi*z1798, t == 2*pi*z1816 + arctan(12/5)]
Guess `z1798` and `z1816` mean "any integer".
But what do numbers after z mean?
Can I set an integer manually and calculate the corresponding solution?protaWed, 16 Feb 2022 12:12:15 +0100https://ask.sagemath.org/question/61127/Solve a system of equations for functionshttps://ask.sagemath.org/question/60708/solve-a-system-of-equations-for-functions/If I run the following code:
var('r')
f = function('f')(r)
g = function('g')(r)
eq1 = diff(f,r) + diff(g,r) == 6
eq2 = diff(f,r) - diff(g,r) == 4
solve([eq1,eq2],diff(f,r),diff(g,r))
I get:
> TypeError: diff(f(r), r) is not a valid variable.
However, solving eq1 or eq2 independently does provide a solution:
sage: solve(eq1, diff(f,r))
[diff(f(r), r) == -diff(g(r), r) + 6]
sage: solve(eq2, diff(g,r))
[diff(g(r), r) == diff(f(r), r) - 4]
What could be wrong here? Could it be that in a system of equations 'Solve' only provides a solution if the unknowns are variables and not functions (or derivative of functions)?kekoMon, 17 Jan 2022 14:34:17 +0100https://ask.sagemath.org/question/60708/Apparent issue in geodesic solverhttps://ask.sagemath.org/question/60476/apparent-issue-in-geodesic-solver/Attempted to solve geodesic equations in FLRW metric for peculiar velocities.
WHAT HAPPENED?
Attempted to solve geodesic equations in FLRW metric for peculiar velocities.
geodesic solver gives out of domain errors for 1st point no matter how I tweak the code. Current copy of the work book has been altered to flat Minkowski space and still gives domain errors.
HOW DID THIS DIFFER FROM WHAT YOU EXPECTED?
I can't figure out the error. The Minkowski space case should be a piece of cake and produce no errors as far as I can tell.
My sage worksheet
https://cocalc.com/projects/ed2b5273-35c2-4f85-b882-2c6911cfe324/files/FLRW%20geodesic%20peculiar%20motion.sagewsDocPhilThu, 30 Dec 2021 17:28:11 +0100https://ask.sagemath.org/question/60476/How can I easily create and handle polynomials with symbolic coefficients?https://ask.sagemath.org/question/60439/how-can-i-easily-create-and-handle-polynomials-with-symbolic-coefficients/ I would like to create polynomial functions with symbolic (yet unknown) coefficients, like:
p(x)=a*x^5 + b*x^4 + c*x^3 + d*x^2+e*x+f
Then I would like to experiment with the degree and thus the number of coefficients, for example:
p(x)=a*x^7 + b*x^6 + c*x^5 + d*x^4+e*x^3+f*x^2+g*x+h
The problem is I always have to explicitely declare the coefficients, as variables, like:
var("a b c d e f g h")
So I should always have to enumerate them by hand.
Isn't exist some automatism to do this? For example:
Polynomial(x,degree=7)
and it would return
c0*x^7 + c1*x^6 + c2*x^5 + c3*x^4+c4*x^3+c5*x^2+c6*x+c7
Sometimes I also would like to query the coefficients, to solve an equation system, which contains those coefficients:
p(x)=a*x^7 + b*x^6 + c*x^5 + d*x^4+e*x^3+f*x^2+g*x+h
eq=[
derivative(p(x),x).subs(x=0)==0,
derivative(p(x),x,2).subs(x=0)==0,
p(x=0)==0,
p(x=x0)==1,
p(x=1)==1+z,
derivative(p(x),x).subs(x=1)==0,
derivative(p(x),x,2).subs(x=1)==0,
derivative(p(x),x).subs(x=x0)==1
]
s=solve(eq,a,b,c,d,e,f,g,h)
Again, when calling solve(), I have to explicitly enumerate the coefficients again, instead of some shortcut, like:
s=solve(eq,p(x).coefficients())
When I try to experiment with the degree of my polynomial p(x), to try out a higher or lower degree, and with more or less equations in the system, I always have to declare my coefficients as vars again and again, which is very annoying.
Furthermore when I tried to query coefficients by, eg.:
p.coefficient(x)
or
p.coefficient(x^3)
The first returns "g" as the coefficient, which is good. But how can I access or query the "free" coefficient, "h" which isn't multiplied by x?
p.coefficient(0)
Doesn't return anything. If it would return the free coeff, then I could get the coefficients by calling a map() with lambda function.
KonstantinSat, 25 Dec 2021 23:19:49 +0100https://ask.sagemath.org/question/60439/Manipulate dummy variable after solving trighttps://ask.sagemath.org/question/60108/manipulate-dummy-variable-after-solving-trig/Hi!
This might be somewhat basic, but is there a way to directly reference the dummy variable that pops up, when solving trigonometric functions?
sy(t)=sin(t)/2+7*sin(t/3)/2
sols=solve(sy(t)==0,t, to_poly_solve='force')
sols[0]
returns:
t == 3*pi + 6*pi*z27541
This dummy variable obviously changes every time the command is run, so there is no way of directly referencing it without changing the reference every time. Obviously this doesn't work:
sols[0](z=0)
The closest I have come, is just blindly referencing the variable which works if there are no other variables in the right hand side, like this:
sols[0].rhs()(0)
but this gives the obnoxious error message, that "*Substitution using function-call syntax and unnamed arguments is deprecated (...)*"
Is there a way to cleanly tell sage to evaluate an expression, when all z variables are 0 or 1 etc?jakuplMon, 06 Dec 2021 00:36:56 +0100https://ask.sagemath.org/question/60108/Solve within assumptionshttps://ask.sagemath.org/question/60084/solve-within-assumptions/I am trying to get the solutions of an inequality which has several variables. These variables move within intervals I have defined with `assume`. When I call `solve` the assumptions seem to be ignored. Below is my code:
variables = var('n_s','alpha','n_p','m','omega_p')
for variable in variables:
assume(variable, 'real')
for refractive_index in {n_s, n_p}:
assume(refractive_index > 1)
assume(0 < alpha, alpha < 1)
assume(omega_p > 0)
assume(m > 0)
assume(m < omega_p)
Xi = ((1-alpha)**2-(m/omega_p)**2)**(1/2)
expression = (n_s**2*alpha**2 + n_p**2 - Xi)/(2*n_p*n_s*alpha)
solve([1>expression],[n_p])
and this produces the following output
[[0 < n_p,
0 < n_s,
0 < alpha,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
0 < n_s,
alpha < 0,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
n_s < 0,
alpha < 0,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
n_s < 0,
0 < alpha,
-alpha^2*n_s^2 + 2*alpha*n_p*n_s - n_p^2 + sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
0 < n_s,
alpha < 0,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
0 < n_s,
0 < alpha,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[0 < n_p,
n_s < 0,
0 < alpha,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0],
[n_p < 0,
n_s < 0,
alpha < 0,
alpha^2*n_s^2 - 2*alpha*n_p*n_s + n_p^2 - sqrt((alpha^2 - 2*alpha + 1)*omega_p^2 - m^2)/omega_p > 0]]
This is clearly ignoring the assumptions, for example the second solution has `alpha < 0`. Is it possible to somehow check for my assumptions automatically?
iovcrerufTCRRYSat, 04 Dec 2021 18:23:16 +0100https://ask.sagemath.org/question/60084/Difference between solve's `r` and `c` solution parametershttps://ask.sagemath.org/question/59176/difference-between-solves-r-and-c-solution-parameters/ Hello, everybody! The author of [this related question](https://ask.sagemath.org/question/59063/weird-c-values-from-solving-system-of-equations/) pointed out an interesting fact: if a system of equations has parameters in its solutions, sometimes the parameters are written as `rN` and sometimes as `cN`, where `N` is a positive integer.
As far as I can tell, the `r`s are produced by Maxima's `solve()` function, while the `c`s are produced by Maxima's `to_poly_solve()` function. Indeed, consider the following system (obtained from a comment in the mentioned question):
a_1, a_2, b_1, b_2 = var('a_1, a_2, b_1, b_2')
eq1 = a_2^2 - a_2*a_1^2 == 0
eq2 = a_2*b_2 - 2*a_1*a_2*b_1 + a_2*b_2 - a_1^2*b_1 == 0
eqs = [eq1, eq2]
If we solve with
from sage.calculus.calculus import maxima
m = maxima(eqs)
sols = m.solve([a_1,a_2,b_1,b_2])
sols._sage_()
then, we get
[[a_1 == 0, a_2 == 0, b_1 == r31, b_2 == r32],
[a_1 == r33, a_2 == 0, b_1 == 0, b_2 == r34],
[a_1 == r35, a_2 == r35^2, b_1 == r36, b_2 == 1/2*(2*r35 + 1)*r36]]
The `r` parameters seem to indicate real parameters, as indicated by [this answer](https://ask.sagemath.org/question/8707/symbolic-solve/) by @kcrisman (sorry to ping you). However, it can clearly be seen that complex parameters are also acceptable. Moreover, the code
from sage.calculus.calculus import maxima
m = maxima(eqs)
sols = m.to_poly_solve([a_1,a_2,b_1,b_2])
sols._sage_()
then, we get
[[a_1 == 0, a_2 == 0, b_1 == c1973, b_2 == c1974],
[a_1 == c1975, a_2 == 0, b_1 == 0, b_2 == c1976],
[a_1 == c1977, a_2 == c1977^2, b_1 == c1978, b_2 == 1/2*(2*c1977 + 1)*c1978]]
There are two possibilities here:
1. `to_poly_solve` is more sophisticated, so it works with complex parameters.
2. The parameters don't indicate real or complex.
Could somebody clarify the difference between `r` and `c` parameters?
Thank in advance for your answers!dsejasMon, 27 Sep 2021 18:01:32 +0200https://ask.sagemath.org/question/59176/four vars but only one eq generate solve() errorhttps://ask.sagemath.org/question/58229/four-vars-but-only-one-eq-generate-solve-error/ Hi
W10 SageMath 9.2
why I m not allowed to have only one equation in the equation list, (uncomment line 4)?
varL=var('a,b,c,d',domain='real')
eqL=[a == -d, b*c == 0, a*(b + c) == 0]
eqL=[a == -d, b*c == 0]
#eqL=[a == -d]
show("so we need : \t ",eqL)
S=solve(eqL,varL)
show(S)
but with `eqL=[a == -d,1==1]` ,solve is ok
ortolljTue, 03 Aug 2021 08:06:48 +0200https://ask.sagemath.org/question/58229/system eqs + eq with abs() then solve() kills the Kernelhttps://ask.sagemath.org/question/58202/system-eqs-eq-with-abs-then-solve-kills-the-kernel/ Hi
W10 ,SageMath 9.2
if I uncomment line 3 below, it kills the Kernel.
varL=var('a,b,c,d',domain='real')
eqL=[a == -d, b*c == 0, a*(b + c) == 0]
#eqL.append((abs(a)+abs(b)+abs(c))!=0)
show("so we need : \t ",eqL)
S=solve(eqL,varL)
show(S)
ortolljMon, 02 Aug 2021 10:28:54 +0200https://ask.sagemath.org/question/58202/Solve 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-1ZmwvBFvE4M06rzDfgMPSite8nva_GWb4Qh-9bOZFuKROIsyDTyBQuhVjy4seZbwRKQhgSKjYCJY0Eo7zy5TiQPXC9YgagrYq1E9n3bFwFoNtmPcpBfDMxyikHgmQ0DrDIVubc_cZghfXcJ1iU4E4B8RRD5Es2rkUFVR72e_M7vcSqK6DF7njTEbf-NteWxsLDy_81jj899kZiFTvBgJaSRO87dLQ-gxEUp-MaeXu98FbfoEeqs-gTqpS1uL7YFyajUFtK2yEKpw0gg0G0R555_h4KHwjWO1lEaYrrgUSQC19jmfu6ZtlVdGPvpakqPravIqDFilgurrR8pIAPLvGUdy-bq23XuEwg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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/