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, 05 Jun 2019 10:48:51 +0200Solve ODE numericallyhttps://ask.sagemath.org/question/46801/solve-ode-numerically/I'd like to solve this ODE: (y')^2=(1-y^2)*(y^2)/(y^2+a) where a is a nonnegative constant. After that, I'd like to get two solutions: y(x0)=p and y(x1)=q, and obtain the difference x0-x1 numerically (It seems that y may be periodic, and the smallest difference is preferred). I got stuck after using desolve to obtain the function. What should I do?Hang WuWed, 05 Jun 2019 10:48:51 +0200https://ask.sagemath.org/question/46801/Strange Solutionshttps://ask.sagemath.org/question/41996/strange-solutions/Sometimes the solutions given by Sage are weird. For example, the
equation below has only one solution, yet sage gives this output.
sage: solve(0.1*1==1*e^(-0.38*t),t)
[t == 50*log(10^(1/19)*e^(2/19*I*pi)),
t == 50*log(10^(1/19)*e^(4/19*I*pi)),
t == 50*log(10^(1/19)*e^(6/19*I*pi)),
t == 50*log(10^(1/19)*e^(8/19*I*pi)),
t == 50*log(10^(1/19)*e^(10/19*I*pi)),
t == 50*log(10^(1/19)*e^(12/19*I*pi)),
t == 50*log(10^(1/19)*e^(14/19*I*pi)),
t == 50*log(10^(1/19)*e^(16/19*I*pi)),
t == 50*log(10^(1/19)*e^(18/19*I*pi)),
t == -900/19*I*pi + 50/19*log(10),
t == -800/19*I*pi + 50/19*log(10),
t == -700/19*I*pi + 50/19*log(10),
t == -600/19*I*pi + 50/19*log(10),
t == -500/19*I*pi + 50/19*log(10),
t == -400/19*I*pi + 50/19*log(10),
t == -300/19*I*pi + 50/19*log(10),
t == -200/19*I*pi + 50/19*log(10),
t == -100/19*I*pi + 50/19*log(10),
t == 50/19*log(10)]o6pThu, 12 Apr 2018 21:21:12 +0200https://ask.sagemath.org/question/41996/Using Singular's solve.libhttps://ask.sagemath.org/question/40490/using-singulars-solvelib/ I am trying to use Singular's `solve.lib` from Sage, but I am running into issues with getting the result out of Singular. I tried using the Singular interface and was able to make it this far:
sage: singular.lib('solve.lib')
sage: r = singular.ring('complex', '(x,y)', 'lp')
sage: I = singular.ideal('(x-5)*y/32', 'y^2-x^3-5*x-10')
sage: R = singular.fglm_solve(I)
sage: singular.setring(R)
at which point the result is stored in a list `rlist` inside of `R`. I can do `singular.eval('rlist')` and see the answer, but in order to get it back into Sage I would have to parse the resulting string. Is there a better way to get `rlist`?
Alternatively, I tried to use `libSingular` as follows:
sage: from sage.libs.singular.function import singular_function, lib
sage: lib('solve.lib')
sage: fglm_solve = singular_function('fglm_solve')
sage: P = PolynomialRing(QQ,'x,y',order='lex'); x,y = P.gens()
sage: I = Ideal((x-5)*y/32, y^2-x^3-5*x-10)
sage: R = fglm_solve(I)
// 'fglm_solve' created a ring, in which a list rlist of numbers (the
// complex solutions) is stored.
// To access the list of complex solutions, type (if the name R was assigned
// to the return value):
setring R; rlist;
<RingWrap>
But then `R` is a `<RingWrap>` instance and this time I don't even know how to go about seeing the answer. Also, I would prefer to work over the complex field, but I couldn't get `fglm_solve` to accept an ideal in `CC['x,y']`
Any help in either direction would be greatly appreciated.jaebondSat, 06 Jan 2018 04:35:56 +0100https://ask.sagemath.org/question/40490/scipy.optimize.roothttps://ask.sagemath.org/question/9334/scipyoptimizeroot/Hello,
I'm trying to use scipy.optimize.root without any luck (http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root.html#scipy.optimize.root). An import attempt returns: "'module' object has no attribute 'root'"
Any suggestions on how I can get this module?
Thanks,
jv
Methods tried:
"import scipy
from scipy import optimize
from scipy.optimize import root"
"import scipy
from scipy import optimize
sol = optimize.root(q, [0., 0.])"mattiasFri, 21 Sep 2012 06:26:30 +0200https://ask.sagemath.org/question/9334/simple numerical solve (2-variables!!)https://ask.sagemath.org/question/9325/simple-numerical-solve-2-variables/Hello,
Thanks for the help, I'm trying to move from Mathematica to Sage, but I'm still having some trouble with the basics. Specifically, I'm moving from 1-var to 2-var numerical optimization/solver. I want to optimize function g or, equivalently, solve the system of first-order conditions, f. So far, I have not been able to get any of the scipy routines to work. Is there a simple way to do this? (Note: the objective function is concave wrt to both arguments.)
Thanks!
jv
#Constants
y_a = 50
y_b = 50
x = 40
alpha_a = .2
alpha_b = .2
#Functions
v(n)= n^.5
v1(n) = derivative(v(n),n)
u(n)= n^.5
u1(n) = derivative(u(n),n)
#Variables
var('g_a')
var('x_a')
#Optimization (over [0, x])
g = (v(g_a+alpha_b*(x-g_a))-u(y_a)+u(y_a-x_a))*(v(x-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x-x_a)))
f1 = ((1-alpha_b)*v1(g_a+alpha_b*(x - g_a)))/((1-alpha_a)*v1(x-g_a+alpha_a*(g_a)))==(v(g_a+alpha_b*(x-g_a))-u(y_a)+u(y_a-x_a))/(v(x-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x-x_a)))
f2 = (u1(x_a)/u1(x-x_a)) == (v(g_a+alpha_b*(x-g_a))-u(y_a)+u(y_a-x_a))/(v(x-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x-x_a)))
f(g_a, x_a) = (f1, f2)mattiasMon, 17 Sep 2012 07:01:13 +0200https://ask.sagemath.org/question/9325/Is there an equivalent of NSolve of mathematica?https://ask.sagemath.org/question/7827/is-there-an-equivalent-of-nsolve-of-mathematica/I am trying to solve a system of non-linear system of equations. Is there a equivalent of NSolve or FindRoot of mathematica in sage. I looked up on the net and there is a equivalent command nsolve in sympy. However, for some reason "from sympy import nsolve" gives a error.ShashankMon, 20 Dec 2010 06:07:15 +0100https://ask.sagemath.org/question/7827/