ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 06 Nov 2017 04:29:40 -0600How can I get back an expression for free variables in solve function.https://ask.sagemath.org/question/39396/how-can-i-get-back-an-expression-for-free-variables-in-solve-function/I have a number of linear equations on some symbols A,B,C,D,E,F,G. When I solve them in Sagemath, I get some free variables in the solution.
$A,B,C,D,E,F,G=var('A,B,C,D,E,F,G')$
$eqns=[A+B==0,C+D+E==0,F+G==0,A+E-F==0]$
$solution=solve(eqns,A,B,C,D,E,F,G)$
Sage gives the following solution:
$[[A == r1, B == -r1, C == r1 - r2 - r3, D == r3, E == -r1 + r2, F == r2, G == -r2]]$
Now I can ask Sage to give me an expression of any combination of the symbols, for example:
$(A+C).subs(solution)$, then I get $2*r1 - r2 - r3$.
For my purpose I would now like to have an expression for any of the free variables. If I assign $r1=var('r1')$ and ask Sage $s1.subs(solution)$ I get back $r1$ again. But I would lik to get back an expression in terms of $A,B,C,D,E,F,G$.
Any suggestions on how to do this?TheBeiramMon, 06 Nov 2017 04:29:40 -0600https://ask.sagemath.org/question/39396/Any way to solve these simultaneous equations using Sage?https://ask.sagemath.org/question/36162/any-way-to-solve-these-simultaneous-equations-using-sage/Input is as following
1: var('E_0,E,gamma,c,v,m,m_0')
(E_0, E, gamma, c, v, m, m_0)
2: eq1 = gamma == 1/sqrt(1-v^2/c^2)
3: eq2 = m == gamma*m_0
4: eq3 = E == m*c^2
5: eq4 = E_0 == m_0*c^2
6: solve([eq1,eq2,eq3,eq4],v,m,m_0,gamma)
The expected solution for v is v = c * sqrt(1-E_0^2/E^2).
I get the following error message. I tried assuming all the variables to be positive and real, but get the same error message.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-6-c0343319abfc> in <module>()
----> 1 solve([eq1,eq2,eq3,eq4],v,m,m_0,gamma)
/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
863 s = []
864
--> 865 sol_list = string_to_list_of_solutions(repr(s))
866
867 # Relaxed form suggested by Mike Hansen (#8553):
/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/symbolic/relation.pyc in string_to_list_of_solutions(s)
538 from sage.structure.sequence import Sequence
539 from sage.calculus.calculus import symbolic_expression_from_maxima_string
--> 540 v = symbolic_expression_from_maxima_string(s, equals_sub=True)
541 return Sequence(v, universe=Objects(), cr_str=True)
542
/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in symbolic_expression_from_maxima_string(x, equals_sub, maxima)
1798 if len(x) == 0:
1799 raise RuntimeError("invalid symbolic expression -- ''")
-> 1800 maxima.set('_tmp_',x)
1801
1802 # This is inefficient since it so rarely is needed:
/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in set(self, var, value)
504 raise TypeError
505 cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 506 self.eval(cmd)
507
508 def clear(self, var):
/home/sage/sage-7.4/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in _eval_line(self, line, locals, reformat, **kwds)
450 line = line[ind_dollar+1:]
451 if statement:
--> 452 maxima_eval("#$%s$" % statement)
453 if not reformat:
454 return result
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:7698)()
793
794 """
--> 795 lispargs = EclObject(list(args))
796 return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
797
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__init__ (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:7221)()
658 """
659 if len(args) != 0:
--> 660 self.set_obj(python_to_ecl(args[0]))
661
662 def __reduce__(self):
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:6254)()
473 return Cnil
474 else:
--> 475 L=cl_cons(python_to_ecl(pyobj[0]),Cnil)
476 ptr=L
477 for a in pyobj[1:]:
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.python_to_ecl (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5990)()
457 elif isinstance(pyobj,bytes):
458 s=<bytes>pyobj
--> 459 return ecl_safe_read_string(s)
460 elif isinstance(pyobj,Integer):
461 if pyobj >= MOST_NEGATIVE_FIXNUM and pyobj <= MOST_POSITIVE_FIXNUM:
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_read_string (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5409)()
374 cdef cl_object o
375 o = ecl_cstring_to_base_string_or_nil(s)
--> 376 o = ecl_safe_funcall(read_from_string_clobj,o)
377 return o
378
/home/sage/sage-7.4/src/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_funcall (/home/sage/sage/src/build/cythonized/sage/libs/ecl.c:5208)()
355 if ecl_nvalues > 1:
356 s = si_coerce_to_base_string(ecl_values(1))
--> 357 raise RuntimeError("ECL says: "+ecl_base_string_pointer_safe(s))
358 else:
359 return ecl_values(0)
RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.omoplataTue, 03 Jan 2017 20:05:25 -0600https://ask.sagemath.org/question/36162/Particular solve: find values of variables which will solve equation for any values of other variableshttps://ask.sagemath.org/question/35609/particular-solve-find-values-of-variables-which-will-solve-equation-for-any-values-of-other-variables/ Hi, this is my first time using Sage, so I hope my questions aren't too trivial.
I have to solve the following problem: find (if they exist) values of real variables x,u,v (with x,v>0) such that the following equality
Maximum{2 a/x, 2 (u*b + v*c)/(u^2 + v^2),
2 ((u - x)*(b - a) + v*c)/(v^2 + (u - x)^2)} = (a/x + c/v) + (1/v*x)*sqrt(
a^2 (u^2 + v^2) - 2 a*x*(b*u + c*v) + (b^2 + c^2)*x^2)
is verified for every value of the real values a, b, c.
It is my understanding that to evaluate the maximum I should use max_symbolic, am I right?
Let me emphasize that I don't need to find values of x,u,v with respect to a,b,c, but fixed values of x,u,v which will verify the equality for any given a,b,c. This means that I need to find x, u, v which will verify all the infinite equations we will get for any different triple of values of a, b, c.
For this reason writing
x,u,v,a,b,c=var('x u v a b c')
s1=solve([max_symbolic(2 a/x, 2*(u*b + v*c)/(u^2 + v^2), 2 ((u - x)*(b - a) + v*c)/(v^2 + (u - x)^2)) == (a/x + c/v) +(1/v*x)*sqrt(a^2 (u^2 + v^2) - 2 a*x*(b*u + c*v) + (b^2 + c^2)*x^2)],x,u,v)
show(s1)
will not work. I've thought of solving for all 6 variables, but then an error occurred saying solve() could only use 5 positional arguments..
Can you suggest me any way to proceed? Also, I fear this kind of computation will be very heavy for my cpu.. Any ideas on how to make It lighter?
Thank you very much!nibWed, 16 Nov 2016 05:12:07 -0600https://ask.sagemath.org/question/35609/System of 3 equations in 3 variables with symbolic coefficientshttps://ask.sagemath.org/question/25786/system-of-3-equations-in-3-variables-with-symbolic-coefficients/ Here is my Sage code:
a, b, c, d, e, f, k, l, m, n, x, y, z = var('a, b, c, d, e, f, k, l, m, n, x, y, z')
eq1 = x*k+(a/m)-(x*d/(sqrt(x^2+y^2+z^2)*e*f))==0
eq2 = y*l+(b/m)-(y*d/(sqrt(x^2+y^2+z^2)*e*f))==0
eq3 = z*n+(c/m)-(z*d/(sqrt(x^2+y^2+z^2)*e*f))==0
print solve([eq1,eq2,eq3],x,y,z)
When I evaluate this, all I get are my original input equations, pretty-printed.
I am expecting a solution for x, y and z in terms of the other constant symbols and that's not happening.
How can I get Sage to solve these equations?
dhathriMon, 09 Feb 2015 20:40:02 -0600https://ask.sagemath.org/question/25786/Computations in a Quotient Ringhttps://ask.sagemath.org/question/25284/computations-in-a-quotient-ring/ I'm trying to do some computations in a quotient ring in Sage, and I'm having some trouble. For example:
Working with the ring:
R.<x,y,z,w,u,z1,z2,z3,z4,z5> = PolynomialRing(QQ,10)
S.<a,b,c,d,e,m1,m2,m3,m4,m5> = R.quo((x^2,y^2+x*y, z^2+x*z + y*z, w^2 - w*x+w*y, u^2 + u*x+ u*z + u*w))
I want to compute `(a*(m3+m4+m5) + b*(m1+m2+m3+m4) + c*(m1+m3) + d*(m1+m2) + e*m1)^5`
where I'm thinking about `m1`, `m2`, `m3`, `m4`, and `m5` as arbitrary coefficients. When I type this in it returns
4/19*e^5*m1^5 + 15/19*e^5*m1^4*m2 + 10/19*e^5*m1^3*m2^2 +
10/19*e^5*m1^4*m3 + 40/19*e^5*m1^3*m2*m3 + 15/19*e^5*m1^2*m2^2*m3 -
15/19*e^5*m1*m2^2*m3^2 - 5/19*e^5*m1^2*m3^3 - 10/19*e^5*m1*m2*m3^3 +
5/19*e^5*m1^4*m4 - 15/19*e^5*m1^2*m2^2*m4 - 30/19*e^5*m1*m2^2*m3*m4 -
15/19*e^5*m1^2*m3^2*m4 - 30/19*e^5*m1*m2*m3^2*m4 - 10/19*e^5*m1^3*m4^2 -
15/19*e^5*m1^2*m2*m4^2 - 15/19*e^5*m1^2*m3*m4^2 -
30/19*e^5*m1*m2*m3*m4^2 - 5/19*e^5*m1^4*m5 - 20/19*e^5*m1^3*m2*m5 -
15/19*e^5*m1^2*m2^2*m5 - 20/19*e^5*m1^3*m3*m5 - 60/19*e^5*m1^2*m2*m3*m5
- 30/19*e^5*m1*m2^2*m3*m5 - 15/19*e^5*m1^2*m3^2*m5 -
30/19*e^5*m1*m2*m3^2*m5 - 20/19*e^5*m1^3*m4*m5 - 30/19*e^5*m1^2*m2*m4*m5
- 30/19*e^5*m1^2*m3*m4*m5 - 60/19*e^5*m1*m2*m3*m4*m5
However, this is also equivalent to `(some expression of mi's)*a*b*c*d*e`.
I want it in this form, because for the problem I'm working on I need this coefficient in front of `a*b*c*d*e`. But I'm not sure how to ask Sage to convert it to this form? For example, "solve" doesn't seem to work in a quotient ring.
(I'm sorry if this is a silly question. I'm new to Sage!)LaurenMon, 15 Dec 2014 23:16:23 -0600https://ask.sagemath.org/question/25284/Solving systems of equations always returns [ ]https://ask.sagemath.org/question/25105/solving-systems-of-equations-always-returns/Suppose I have the set of equations and I'm trying to solve for f1, f2 and f3:
![formula][1]
[1]: http://latex.codecogs.com/gif.latex?f_1%20%26%3D%26%20a+b+f_2%20%5C%5C%202f_2%20%26%3D%26%20c+d+f_1%20%5C%5C%20f_3%20%26%3D%26%20f_1+f_2
I've tried solving it in the following way
eq1 = f1 == a + b + f2
eq2 = 2*f2 == c + d + f1
eq3 = f3 == f1 + f2
solve([eq1,eq2,eq3],f1,f2,f3)
[]
This is easy to solve using matrices, and I have double-checked that the answer is fully constrained, so why does sage always return [ ]? I would have expected answers for f1, f2 and f3 in terms of a, b , c and d. Is there another argument to solve() that tells Sage what I want my answer in terms of?
I would prefer to use solve() instead of matrices both for the sake of convenience and if I have a nonlinear system later on.
EvidloWed, 03 Dec 2014 18:07:57 -0600https://ask.sagemath.org/question/25105/Why does Sage not find any solutions using .solve()?https://ask.sagemath.org/question/24991/why-does-sage-not-find-any-solutions-using-solve/ Hello everyone,
please consider this attempt to solve simultaneous equations:
P,M,R,rho,kappa,T,F,n = var('P, M, R, rho, kappa, T, F, n')
eqns = [
P==M^2*R^-4,
R^3==M*rho^-1,
T^4==M*kappa*F*R^-4,
F==M*rho*T^n,
P==rho*T,
kappa==rho*T^(-7/2),
n==4
]
eqns
assume(P>0,M>0,R>0,rho>0,T>0,F>0,kappa>0)
sols = solve(eqns,(F,R,T))
sols
(returns [])
I would like to understand why Sage can not arrive at a relation for F,M,T (and n) which I was able to do by hand. Is solve inappropriate for isolating one or more variables from a set of equations?
Thank you for your help!
zuiopTue, 25 Nov 2014 05:56:59 -0600https://ask.sagemath.org/question/24991/Elementary algebraic geometry?https://ask.sagemath.org/question/9806/elementary-algebraic-geometry/I'm not an algebraic geometer, so apologies in advance if this is a trivial question. I'm currently exploring some (Euclidean) geometry relating to various lines and circles, and their intersections. Here is one of the sorts of questions I'm looking at: given a fixed point (u,v) and a fixed circle C of radius R with centre (0,0), then given a general point (x,y) on C, find another point (X,Y) on C so that the line between (x,y) and (X,Y) is at distance d from (u,v). In other words, I'd like to express (X,Y) as a function of (x,y) in the nicest possible way. I can set up a system of equations and attempt to solve them, but this is slow and produces hugely messy results.
I was wondering if there's a more natural, or better way, in Sage.AlasdairThu, 14 Feb 2013 13:42:08 -0600https://ask.sagemath.org/question/9806/Some equations fail to solve even with to_poly_solvehttps://ask.sagemath.org/question/9288/some-equations-fail-to-solve-even-with-to_poly_solve/In the following, I would expect to obtain `[z == 1/y*lambda_w(y)]`:
sage: z=var('z')
sage: y=var('y')
sage: solve(log(z)+3*z==0, z, to_poly_solve=True)
[z == 1/3*lambert_w(3)]
sage: solve(log(z)+y*z==0, z, to_poly_solve=True)
[z == -log(z)/y]
But Sage doesn't want to solve the equation for z. Perhaps, in view of the fact that it solves the equation when 3 is in place of z, it doesn't realize that y is supposed to represent a real number. I tried `assume(y,'real')` but that command did not help.
Does anyone know a workaround?heatkernelSun, 02 Sep 2012 18:02:34 -0500https://ask.sagemath.org/question/9288/