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.Mon, 06 Dec 2021 00:36:56 +0100Manipulate 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/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/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/to_poly_solve problem?https://ask.sagemath.org/question/38030/to_poly_solve-problem/Hello,
I have:
var ('N,m,sec,a,t,c')
T = (1.27 * 10^6)
Fg = ((9.81*107000))
a = ((T-Fg)/107000)
a = 2.05915887850467
v = a*t
P3 = plot(v, (t,0,11))
v.integral(t)
y = 1.029579439252335*t^2
P1 = plot(y, (t,0,12))
T1 = 1.27*e^(-(t-11)/2) * 10^6
Fg = 9.81*107000
a1 =(T1-Fg)/107000
v1 = a1.integral(t)
v1 = -9.81*t - 23.738317757009348*e^(-1/2*t + 11/2) + 154.299065420560
P4 = plot(v1, (t,11,22))
v1.integral(t)
y1 = -4.905*t^2 + 154.29906542056*t + 47.476635514018696*e^(-1/2*t + 11/2) -1026.68224299065
P2 = plot (y1, (t,12,22))
P = P1 + P2;
show(P)
Impact = y1.find_root(21,22)
Impact
P5 = P3 + P4
show(P5)
differentiate = diff(y1, t)
solve(-9.81000000000000*t - 23.73831775700935*e^(-1/2*t + 11/2) + 154.299065420560 == 0, t, to_poly_solve=True)
I am learning SageMath.
When I try to solve the last solve equation that has an exponential with a "t" (the last line in the code) while using to_poly_solve=True, I get the following error:
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
I would like to solve for "t" so that I can find the maximum of a function.
Thanks in advance.happys5Tue, 20 Jun 2017 04:15:34 +0200https://ask.sagemath.org/question/38030/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?heatkernelMon, 03 Sep 2012 01:02:34 +0200https://ask.sagemath.org/question/9288/solving polynomial equations with to_poly_solvehttps://ask.sagemath.org/question/8821/solving-polynomial-equations-with-to_poly_solve/I have a system of (quadratic) polynomial equations which I'd like to solve with Sage. Here and elsewhere I've seen references to the fact that `to_poly_solve` is faster than just calling `solve` in Sage.
Can I somehow tell `to_poly_solve` that I'd like to work over `RR` or `RDF` instead of whatever symbolic ring it's using by default? The coefficients of the equations I'm using are floats, but my solutions are coming out as huge fractions. I imagine it would be faster if the solver were working over `RR`.
EDIT: Upon further reflection, I suspect this is really a Maxima question, since the entire solving process is carried out there. Nevertheless, I would like to know if such functionality exists in Maxima and whether I can use it from Sage.
If you'd like to know, here are some test equations:
vars = var('a0, a1, a2, R')
eqs = []
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 2*a0 - 1.56835186587759*a1 - 1.79444137578129*a2 + 1]
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.56835186587759*a0 - 2*a1 - 1.12952287573422*a2 + 1]
eqs += [R^2 == a0^2 + 1.56835186587759*a0*a1 + 1.79444137578129*a0*a2 + a1^2 + 1.12952287573422*a1*a2 + a2^2 - 1.79444137578129*a0 - 1.12952287573422*a1 - 2*a2 + 1]
eqs += [a0 + a1 + a2 == 1]
maxima.load('topoly_solver')
meqs = maxima(eqs)
solns = meqs.solve(vars)
For example, here is the value of `a0` and `R` in this case:
sage: solns[0][0]
a0=-127216901572440833725/188266808300071978748
sage: solns[0][3]
R=9*sqrt(149350213112030161)/sqrt(47066702075017994687)
sage: solns[0][0].rhs().parent()
Maxima
nilesFri, 30 Mar 2012 17:51:55 +0200https://ask.sagemath.org/question/8821/