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.Tue, 31 Mar 2020 09:35:14 -0500Solving for an unknown function in a logarithmic expressionhttp://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 -0500http://ask.sagemath.org/question/50445/how to find a local maximum?http://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 -0500http://ask.sagemath.org/question/8890/can sage return a list of numbers from solve() instead of expressions?http://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 -0600http://ask.sagemath.org/question/49245/Equation solver with assumehttp://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 -0600http://ask.sagemath.org/question/48899/How to solve an equation over finite field for exponent variable?http://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 -0600http://ask.sagemath.org/question/48869/How to find all roots with solve?http://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 -0600http://ask.sagemath.org/question/48808/obtaining all numerical roots of a function in an intervalhttp://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 -0500http://ask.sagemath.org/question/8886/How to solve this algebraic equation by SageMath (rather than by hand)http://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 -0500http://ask.sagemath.org/question/48566/Not understanding behavior with solution to simultaneous quadratic equationshttp://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 -0500http://ask.sagemath.org/question/48466/solve equation with two variables over RRhttp://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 -0500http://ask.sagemath.org/question/46915/problem: sage is not able to find solution to an equation.http://ask.sagemath.org/question/46841/problem-sage-is-not-able-to-find-solution-to-an-equation/ Hi everybody, I want to solve this non linear equation: omega_nf_eq = 0.
m,J_d,J_p,y,Y,omega,Omega,phi,Phi,z,Z,theta,Theta,k_yy,k_zz,k_phiphi,k_yphi,k_ztheta,k_thetatheta,plane_xy1,plane_xy2,plane_xz1,plane_xz2 = var('m J_d J_p y Y omega Omega phi Phi z Z theta Theta k_yy k_zz k_phiphi k_yphi k_ztheta k_thetatheta plane_xy1 plane_xy2 plane_xz1 plane_xz2')
t = var('t')
omega_nf_eq = -J_d^2*k_yy*k_zz*omega^4 + 0.382*J_d^2*k_yy*omega^6 + 0.382*J_d^2*k_zz*omega^6 - 0.145924*J_d^2*omega^8 + J_d*k_phiphi*k_yy*k_zz*omega^2 - 0.382*J_d*k_phiphi*k_yy*omega^4 - 0.382*J_d*k_phiphi*k_zz*omega^4 + 0.145924*J_d*k_phiphi*omega^6 + J_d*k_thetatheta*k_yy*k_zz*omega^2 - 0.382*J_d*k_thetatheta*k_yy*omega^4 - 0.382*J_d*k_thetatheta*k_zz*omega^4 + 0.145924*J_d*k_thetatheta*omega^6 - J_d*k_yphi^2*k_zz*omega^2 + 0.382*J_d*k_yphi^2*omega^4 - J_d*k_yy*k_ztheta^2*omega^2 + 0.382*J_d*k_ztheta^2*omega^4 + J_p^2*Omega^2*k_yy*k_zz*omega^2 - 0.382*J_p^2*Omega^2*k_yy*omega^4 - 0.382*J_p^2*Omega^2*k_zz*omega^4 + 0.145924*J_p^2*Omega^2*omega^6 - k_phiphi*k_thetatheta*k_yy*k_zz + 0.382*k_phiphi*k_thetatheta*k_yy*omega^2 + 0.382*k_phiphi*k_thetatheta*k_zz*omega^2 - 0.145924*k_phiphi*k_thetatheta*omega^4 + k_phiphi*k_yy*k_ztheta^2 - 0.382*k_phiphi*k_ztheta^2*omega^2 + k_thetatheta*k_yphi^2*k_zz - 0.382*k_thetatheta*k_yphi^2*omega^2 - k_yphi^2*k_ztheta^2 == 0
solve(omega_nf_eq, omega)
But the Sage is unable to find the solution, damn it.
I get this error message:
TypeError: ECL says: Memory limit reached. Please jump to an outer pointer, quit program and enlarge the memory limits before executing the program again.
I know the equation is big but i didn't expected such many problems.
I've already tried sympy but nothing.
Is there another way?
pull_over93Thu, 06 Jun 2019 17:35:14 -0500http://ask.sagemath.org/question/46841/AttributeError: 'dict' object has no attribute 'solve'http://ask.sagemath.org/question/46729/attributeerror-dict-object-has-no-attribute-solve/How I can fix this error '''AttributeError: 'dict' object has no attribute 'solve'
It appears after I tried to `solve(P)`:
G = I.groebner_basis()
P = {}
ind = 0
for i in range (n):
if (G[i].degree() < num):
ind = ind+1
P[ind] = G[i]
solve(P)MaoriThu, 30 May 2019 16:56:09 -0500http://ask.sagemath.org/question/46729/Solving polynoms from dictionaryhttp://ask.sagemath.org/question/46726/solving-polynoms-from-dictionary/I have a dictionary, which I feel from `for`, is there any way, to solve polynomials from `D`?
D = {}
for i in range (len(G)):
if (G[i].degree() < num):
j = j+1
D[j] = G[i]MaoriThu, 30 May 2019 13:45:02 -0500http://ask.sagemath.org/question/46726/Solve symbolic matrix cellhttp://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/I'm trying to take a cell from a matrix and solve for a variable symbolically. When I run this, I get the error:
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
This is the code I am trying to execute:
var('a','b','c','x','y','z')
Rz = matrix([[cos(a),-sin(a),0,0],[sin(a),cos(a),0,0],[0,0,1,0],[0,0,0,1]])
Ry = matrix([[cos(b),0,sin(b),0],[0,1,0,0],[-sin(b),0,cos(b),0],[0,0,0,1]])
Rx = matrix([[1,0,0,0],[0,cos(c),-sin(c),0],[0,sin(c),cos(c),0],[0,0,0,1]])
P = matrix([[x],[y],[z],[1]])
Rzyxp = Rz * Ry * Rx * P
show(Rzyxp)
eqn2 = Rzyxp[2]
show(eqn2)
result1 = solve(eqn2==0, b)
show(result1)
Any help would be appreciatedMickey_PhippsTue, 19 Mar 2019 14:44:52 -0500http://ask.sagemath.org/question/45841/Factor a solve outputhttp://ask.sagemath.org/question/45716/factor-a-solve-output/ I am new to sage. So, sorry if my question is too trivial.
I can not factor the output of "solve". For instance, this very simple example
x= var('x')
sols=solve(x==6, x)
factor(sols[0].right())
gives me
6
Why I am not getting the following?
2 * 3
which of course is the output of
factor(6).
PS: I guess that the "type" is a crucial thing here, but anyways I'd need to factor 'sage.symbolic.expression.Expression'tidessonThu, 07 Mar 2019 17:25:05 -0600http://ask.sagemath.org/question/45716/exponential equation solve problemhttp://ask.sagemath.org/question/45450/exponential-equation-solve-problem/ b=4*3^(2*x-1)==5*4^(x+2)
show(b)
solve(b,x)
The Solution is:
[4^(x + 2) == 4/5*3^(2*x - 1)]
Should the solve alg. solve for x?thethaWed, 13 Feb 2019 08:20:11 -0600http://ask.sagemath.org/question/45450/Solve, elegant way ?http://ask.sagemath.org/question/44496/solve-elegant-way/Hi
SageMath version: 8.4, OS:W10
to solve this little problem, first I tried this code:
#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m = age of Maxime a = age of Albane, x = age difference
forget()
var(' a_0 m_0 a_1 m_1 x')
assume(a_0,'real')
eq0=m_0==m_1/2
eq1=2*(a_0)==m_0
S_0=solve([eq0.substitute(m_1=32),eq1],a_0)
S_1=solve([eq0.substitute(m_1=32),eq1],a_0,m_0)
show("S_0 : ",S_0,"S_1 : ",S_1)
question 1 : in the code above what is wrong , why S_0 does not give a solution ?
afterward I tried this code below, which gives the good answer:
#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m_i = age of Maxime a_i = age of Albane, x = age difference
forget()
var(' a_0 m_0 x')
m_1=32
m_0=m_1/2
eq1=2*(a_0)==m_0
a_0=solve([eq1],a_0)[0].rhs()
x=m_0-a_0
a_1=m_1-x
show(" actual age of Albane : ",a_1)
question 2 : in order to serve me as an example, could someone show me a most elegant way to solve this little PB with SageMath ?
[problem source](https://www.futura-sciences.com/sciences/questions-reponses/mathematiques-jeu-mathematique-question-age-rend-fou-10175/#xtor=EPR-69-[QUESTIONMATH]-20181127)ortolljThu, 29 Nov 2018 02:31:33 -0600http://ask.sagemath.org/question/44496/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/solve() is not giving the right solutionshttp://ask.sagemath.org/question/44292/solve-is-not-giving-the-right-solutions/Hey there,
i need your help on this one. The following sage code is giving me a headache:
- f(x) = x^3 + x^2 - 0.1
- solve(f==0, x)
- -->
- [x == -1/2*(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3)*(I*sqrt(3) + 1) - 1/18*(-I*sqrt(3) + 1)/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3, x == -1/2*(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3)*(-I*sqrt(3) + 1) - 1/18*(I*sqrt(3) + 1)/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3, x == (1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) + 1/9/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3]
So i'm getting these 3 solutions, but they are not in R (real numbers), which they should be.
Im figuring there is some problem with really long terms or something? Is there an easy solution for this? Is the solve()-method here working as intended?
Regards,
BenbentheteacherThu, 15 Nov 2018 08:17:54 -0600http://ask.sagemath.org/question/44292/W10,Sagemath 8.4 solve() does not give a responsehttp://ask.sagemath.org/question/44249/w10sagemath-84-solve-does-not-give-a-response/ why Sagemath solve() does not give a response, and no indication on what it is missing ?
(by hand a_1=a_2=3/15)
var('X_1 X_2 a_1 a_2 b Theta')
assume(a_1,'real');assume(a_2,'real')
assume(X_1,'real');assume(X_2,'real')
assume(b,'real') ;assume(Theta,'real')
f_1=2*X_1^2*a_1 + 2*X_1*X_2*a_2 - 2*Theta*X_1 + 2*X_1*b
f_2=2*X_1*X_2*a_1 + 2*X_2^2*a_2 - 2*Theta*X_2 + 2*X_2*b
S=solve ([f_1==0,f_2==0,X_1*X_2==1,Theta*X_1==1,Theta*X_2==1,X_1*X_1==4,X_2*X_2==4,Theta*Theta==4,b==0],a_1,a_2)
show(S)
ortolljMon, 12 Nov 2018 04:06:28 -0600http://ask.sagemath.org/question/44249/Trouble finding intersection of two functionshttp://ask.sagemath.org/question/44019/trouble-finding-intersection-of-two-functions/ Hi all,
I'm still pretty new using SageMath, but I'm trying to duplicate functionality that I've been able to do in wolfram alpha
Wolfram Input:
Intersection points of [//math:90000 1.03^x//] and [//math:63000 1.095^x//]
So far I've been able to recreate and graph these functions very easily using SageMath, but I'm having a difficult time using the solve function to actually return a numerical value for the intersection point itself.
My SageMath code looks like:
x = var('x')
f1 = (63000*((1.095)^x))
f2 = (90000*((1.03)^x))
ans=solve(f2==f1,x)
print ans
print n(ans[0].rhs())
ans prints as
"[
219^x == 1/35*200^(x - 1)*103^x*100^(-x + 2)
]"
And I get an error "TypeError: cannot evaluate symbolic expression numerically" in my attempts to resolve it to an approximate number.
Can anyone tell me what I'm doing wrong?lgushurstMon, 22 Oct 2018 00:51:55 -0500http://ask.sagemath.org/question/44019/Smallest positive numerical solution of an equation in one variablehttp://ask.sagemath.org/question/43152/smallest-positive-numerical-solution-of-an-equation-in-one-variable/ I have some functions, all of which are functions of variable $x$ but some of them may not have any positive solutions. It is known that at least one of them have a positive solution. Now I need a list of all smallest positive solutions for those functions. For example consider $f=x^2+3x+2$ and $g=2^{(5x + 1)} - 3.2^{(3x + 1)}$. Here $f$ doesn't have any positive root but $g$ has (0.792481250360578). I want a sage code like min(solve([f,x>1],x))+min(solve([g,x>1],x)) to get the list as [0.792481250360578]. Thank you in advance.Deepak SarmaWed, 25 Jul 2018 06:48:40 -0500http://ask.sagemath.org/question/43152/Solving a power series equationhttp://ask.sagemath.org/question/42778/solving-a-power-series-equation/I'd like to solve the equation `f(t) == 1` where `f` is a power series:
var('n,t')
a1 = float(4 + sqrt(8))
b1 = float(3 + sqrt(8))
c1 = b1
an = 4*n*(n-1)+a1*n
an1 = 4*n*(n+1) + a1*(n+1)
anr = b1 + 2*n*(4*n+a1)
bn = 1+2*n*(n-1)+n*(b1-1)
bn1 = 1+2*n*(n+1)+(n+1)*(b1-1)
bnr = c1 + 2*n*(2*n+b1-1)
def f(t):
return (1+b1)^-t + 3/2*a1^-t + 1/2*(2*b1)^-t + b1^-t + 2*sum(an^-t +an1^-t + anr^-t + 2*bn^-t +2*bn1^-t + bnr^-t ,n,1,1000).n()
I've tried simply plugging in values for t and I estimate that if f(t) = 1 then t is approximately 1.51. I'd like to possibly do something like
solve(f(t) == 1,t)
but this appears to lock sage up and I have to interrupt the process. The true f function is actually an infinite series, but I am truncating it to the first 1000 terms. I know there are methods of solving series equations such as the method of regula falsi. Does Sage have anything like this? Thanks!Daniel LFri, 29 Jun 2018 12:52:53 -0500http://ask.sagemath.org/question/42778/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/testing if system of inequalities has solutionhttp://ask.sagemath.org/question/40741/testing-if-system-of-inequalities-has-solution/Hi there,
I have a big system of inequalities (~1500 inequalities, 45 variables) and want to check, if there exists a real solution to it.
Trying out the 'solve' and 'solve_ineq' takes a huge amount of time or it breaks during calculation and after checking
some of the questions here I even assume the solve-function is broken and sometimes gives wrong results. Does anybody know about a function/system which returns in a responsible time and reliable if there exists a solution or not (existence is enough) (I want to use this in an actual proof, so it would be useless, if I can't trust the result).
In my use case I have the variables $a1, ..., a15, b1,...,b15,c1,...,c15 \in \mathbb R^+$ and my inequalities are all of the form
$$ \frac{f(a1,...,a15)}{g(c1,\dots, c15)} \geq \frac{f'(a1,\dots,a15)}{g'(c1,\dots, c15)}$$
(and same for combinations of (a,b) and (b,c)) for given linear functions $f,f',g,g'$ (i.e. multivariate polynomials with degree at most 1), so restricting to the variables $ai$ we get a system of linear inequalities (but even trying to solve these takes long/doesn't work with the solve function).
Actually more accuratly I have indexed sets $$F_{a,b} =\{{(f_i,g_i) | i \in I \}, F_{c,b} =\{(p_i,q_i) | i \in I \} ,F_{a,c} =\{(r_i,s_i) | i \in I \} $$
and want to show, that if there exists a solution $(a,b)$ of
$$\frac{f_k(a)}{g_k(b)} = max_i \frac{f_i(a)}{g_i(b)}$$
then there exists a solution $(c)$ to
$$\frac{r_k(a)}{s_k(c)} = max_i \frac{r_i(a)}{s_i(c)}$$
$$\frac{p_k(c)}{q_k(b)} = max_i \frac{p_i(c)}{q_i(b)}$$
So far I have a the follwing snippet:
#fractionAB are the saved fractions from above, a,b,c are arrays with e.g. a=[a1,a2,...,a15]
stopIt=False
for maxStretch in cands: #cands is the index set I
ineq=[fractionAB.get(maxStretch) >= fractionAB.get(cand) for cand in cands]
if solve(ineq,a+b):
#try here if there exists a middle point on the geodesic, i.e. geodesic exists
ineq.extend([fractionAC.get(maxStretch) >= fractionAC.get(cand) for cand in cands])
ineq.extend([fractionCB.get(maxStretch) >= fractionCB.get(cand) for cand in cands])
if not solve(ineq, a+b+c):
stopIt=True
print 'Tested for candidate ' , maxStretch
if stopIt:
break
I know, there is room for improvement e.g. at reusing to first solution from (a+b), the problem is, that even that first system pretty much kills the calculation. Also multiplying the denominators on each side doesn't seem to help.
PS: The mathjax seems to be broken on this site, since the code for leftbraces seems to vanish (hence the ugly "fix" above).ctstMon, 22 Jan 2018 13:05:31 -0600http://ask.sagemath.org/question/40741/Make SageMath allow for Error of Mathematicahttp://ask.sagemath.org/question/42223/make-sagemath-allow-for-error-of-mathematica/Hello everyone!
I am currently trying on the interface of SageMath to Mathematica for the solution of polynomial equations and inequalities. Whilst doing that I came across an instance that is typical for Mathematica when solving systems of polynomial equation and inequalities. I tried to solve the system and Mathematica returned the error
> "Mathematica ERROR: Solve::ratnz:
> Solve was unable to solve the system
> with inexact coefficients.
> The answer was obtained by solving a corresponding exact system and
> numericizing the result. "
and as a result Sage raised the error and returned no solution.
I am trying to get solutions to the system:
sys={0.500000000000000*lamda2*theta3 - 3*x1^2 + 2*lamda1 - lamda3 + 5==0,lamda1 + lamda2 - lamda4 + 3*theta1 - 6*x2==0,lamda1*(theta2 + 2*x1 + x2 - 7.50000000000000)==0,(0.500000000000000*theta3*x1 + x2 - 1.50000000000000)*lamda2==0,-lamda3*x1==0,-lamda4*x2==0}
for the variables
var={x1,x2,lamda1,lamda2,lamda3,lamda4}
and a sample of the code for the solve is:
from sage.interfaces.mathematica import mathematica
sys = mathematica(sys)
var=mathematica(var)
sys.Solve(var)
Is it possible to make an exception for specific Mathematica errors so as to get the solution?
Many thanks,
Jason :)JasonKMon, 30 Apr 2018 06:45:47 -0500http://ask.sagemath.org/question/42223/Weird solve() problemhttp://ask.sagemath.org/question/41355/weird-solve-problem/I try to solve the equation
$$
a^2 + b^2 + 2 a^2 b^2 = c^2
$$
in integers. Using
var('a,b,c')
assume(a,'integer')
assume(b,'integer')
assume(c,'integer')
solve([a^2 + b^2 + 2*a^2*b^2 == c^2],[a,b,c],solution_dict=True)
gives Pythagorean triples:
{c: t1^2 + t2^2, b: 2*t1*t2, a: t1^2 - t2^2}
which clearly do not satisfy the equation (unless $t_1=t_2$ or $t_2t_2 = 0$). It seems that solve() does not see the term $2a^2b^2$; trying
solve([a^2 + b^2 + 2222*a^2*b^2 == c^2],[a,b,c],solution_dict=True)
gives the same (wrong) result.
UPDATE: The problem does not exist in the newest version (8.1).zhorasterFri, 02 Mar 2018 04:26:55 -0600http://ask.sagemath.org/question/41355/Solving system of polynomial inequalities in SageMath 8.1http://ask.sagemath.org/question/41056/solving-system-of-polynomial-inequalities-in-sagemath-81/ Hi everyone!
I am currently trying to use SageMath for the solution of a system of polynomial inequalities. In the first place based on the documentation and because solutions were returned I used the "solve" command and the "solve_ineq" command. However, when I tried to verify the answers with the one computed by Mathematica I realised the solutions were not the same. Is this a bug in the current version?
Also, I am trying to do it the normal way by computing the CAD using QEPCAD but when I tried to replicate the example on the website I get the following error:
> RuntimeError: unable to start QEPCAD
I am using SageMath 8.1 in Windows 7 64bit and jupyter notebook for interface that I call using the SageMath shell, if that is of any help.
The system I am referring to is the following:
> sys=[0.800000000000000*theta1*x1 + 0.100000000000000*theta2*x2 - 24000,
0.100000000000000*theta2*x2 + 0.0500000000000000*x1 - 2000,
0.100000000000000*x1 + 0.360000000000000*x2 - 6000,
-x1, -x2, -theta1 - 5, theta1 - 5, -theta2 - 5, theta2 - 5, -lamda1, -lamda2, -lamda3, -lamda4, -lamda5]
and using the following substitution:
> sol=[x1 == 440000/(16*theta1 - 1),
x2 == 80000*(4*theta1 - 3)/(16*theta1*theta2 - theta2),
lamda1 == 54*(3*theta2 - 2)/(16*theta1*theta2 - theta2),
lamda2 == 54*(32*theta1 - 3*theta2)/(16*theta1*theta2 - theta2),
lamda3 == 0, lamda4 == 0, lamda5 == 0]
The output of
> solve([sys[i].subs(sol)<=0 for i in range(0,len(sys))], theta1, theta2)
is
> []
Sorry for the long post but I would really appreciate and help with regards on how to solve such as system of inequalities and whether solve command has a bug?
Best,
Jason JasonKSat, 10 Feb 2018 07:58:03 -0600http://ask.sagemath.org/question/41056/How to properly declare indeterminates so that they exist in the coefficient ring.http://ask.sagemath.org/question/40918/how-to-properly-declare-indeterminates-so-that-they-exist-in-the-coefficient-ring/I'm working on a project regarding generalization of symmetric polynomials.
For the sake of simplicity, I will ask my question in the context of a minimalistic (not) working example.
Let say I am working with Symmetric Functions, I'll write an erroneous code so that you get the idea of what I'm looking for
QQt = QQ['t'].fraction_field()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
a0 = var('a0')
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
The I get the error ```unsupported operand parent(s) for *: 'Symbolic Ring' and 'Symmetric Functions over Fraction Field of Univariate Polynomial Ring in alpha over Rational Field in the monomial basis'```
OK, so I tried this instead
QQt = QQ['t,a0'].fraction_field()
t, a0 = QQt.gens()
Sym = SymmetricFunctions(QQt); Sym.inject_shorthands()
expr1 = m[1,1]
expr2 = m[2] + a0*m[1,1]
eqsys = expr1.scalar_jack(expr2)
solve(eqsys, a0)
```a0 is not a valid variable```
So then I did the following
sln = solve(SR(eqsys), SR(a0))
and it works. But the probleme is that I can't convert the solution back
QQt(sln)
```('cannot convert {!r}/{!r} to an element of {}', {a0: 2/(t + 1)}, 1, Fraction Field of Multivariate Polynomial Ring in t, a0 over Rational Field)```
And anyway this last solution does not seem very canonical. How should I proceed?
I guess that somehow what I am asking is how to declare ```a0, a1, ...``` as symbols element of QQt. LAVThu, 01 Feb 2018 08:48:50 -0600http://ask.sagemath.org/question/40918/How to solve this equation with double square root?http://ask.sagemath.org/question/40384/how-to-solve-this-equation-with-double-square-root/I am trying to solve this equation in sage
$$
\sqrt{-4 \, z^{2} + 2 \, \sqrt{-4 \, z^{2} + 1} - 1} = 0.
$$
But when I try the code
var('z')
eq = sqrt(-4*z^2 + 2*sqrt(-4*z^2 + 1) - 1) == 0
solve(eq,z)
I get
[z == -1/2*sqrt(2*sqrt(-4*z^2 + 1) - 1), z == 1/2*sqrt(2*sqrt(-4*z^2 + 1) - 1)]
Is there any way to actually solve it in sage?ablmfSat, 30 Dec 2017 19:00:00 -0600http://ask.sagemath.org/question/40384/