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.Thu, 07 Mar 2019 03:08:58 -0600Cannot solve differential equation (Lane-Emden equation) numericallyhttp://ask.sagemath.org/question/45696/cannot-solve-differential-equation-lane-emden-equation-numerically/Hi, my friends,
I tried to solve Lane-Emden equation, as model of white dwarf,
$$
\frac{d^2x}{dt^2} +\frac2 t \frac{dx}{dt} + x^n = 0, ~~~~ where ~~~~n=\frac 3 2
$$
and I have some troubles in sagemath.
I am using following code:
T = ode_solver()
def f_1(t,y): return [y[1],-2/t*y[1]-y[0]^(3/2)]
T.function = f_1
def j_1(t,y): return [[0, 1], [-3/2*y[1]^(1/2), -2/t], [0,2*y[1]/t^2]] #Jacobian matrix
T.jacobian = j_1
T.algorithm = "rk8pd"
T.ode_solve(y_0=[1,0], t_span=[0,10], num_points=1000)
f = T.interpolate_solution()
plot(f, 0, 10)
Above code is very similar of the example in sagemath reference: Van der Pol equation
Both equations (Lane-Emden and Van der Pol) are non-linear differential equation, therefore, are not easy to solve.
I don't know where comes to problem in above codes, can someone give me a help?
JohnJohn BaoThu, 07 Mar 2019 03:08:58 -0600http://ask.sagemath.org/question/45696/Numerically Solve a Symbolic Equationhttp://ask.sagemath.org/question/37980/numerically-solve-a-symbolic-equation/ Hello,
In truth, I am feeling like an idiot but it has been a long while since I have done math.
What I want to do is find the intersection points between a parabola and a circle. After I put both equations in x and set them equal, I have:
var('y')
solve (sqrt(16-x^2) - 1/4*x^2-1.28==0, x)
Problem is, I get the following for answers:
[x == -2/5*sqrt(25*sqrt(-x^2 + 16) - 32), x == 2/5*sqrt(25*sqrt(-x^2 + 16) - 32)]
If I need to numerically solve the equation, which I think I must do, how do I do it in Sage?
happys5Fri, 16 Jun 2017 21:23:14 -0500http://ask.sagemath.org/question/37980/Numerically compare valueshttp://ask.sagemath.org/question/33117/numerically-compare-values/I was wondering whether there is a way to numerically compare values. I don't want to use `==` due to the limited precision of floating point arithmetic. There are some possible solutions, for example here:
http: // floating-point-gui.de/errors/comparison/
My question is, is something like this already implemented in sage?bmoiFri, 15 Apr 2016 07:17:25 -0500http://ask.sagemath.org/question/33117/Solving non linear system of equationshttp://ask.sagemath.org/question/10885/solving-non-linear-system-of-equations/Why this is not working in sage?
f=-V+exp(V)-w-1;
g=0.5*V-w;
sol=solve([f==0,g==0],V,w,solution_dict=True)
It does not return numerical solutions when there are two.
Thanks
Zardoz777Sat, 04 Jan 2014 00:19:38 -0600http://ask.sagemath.org/question/10885/Finding solution to nonlinear equations numerically in a rangehttp://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/Hi,
this question is probably quite easy to solve. I've got two nonlinear equations with a solution in the range of (0,1). As described in the sage tutorial I tried the following:
var('p t')
eq2 = p==1 - (1 - (1 - (1 - 0.01)^1036)^20)*(1 - t)^(9)
eq1 = t==(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p(1 - (2*p)^1023))
solns = solve([eq1,eq2],t, solution_dict=True)
[[s[t].n(10)] for s in solns]
Unfortunately this doesn't work. In addition I tried find_root, but failed miserably. Any ideas? rnwW6Qz3Mon, 15 Oct 2012 12:15:30 -0500http://ask.sagemath.org/question/9430/cannot evaluate symbolic expression numericallyhttp://ask.sagemath.org/question/9286/cannot-evaluate-symbolic-expression-numerically/I'm probably doing something wrong on a fundamental level, so: sorry for my ignorance. Yet i'd very much appreciate any suggestions, how to make this work:
I have me a function f, defined in somewhat lenghty way:
var('a,b,c,d')
i=matrix(SR,3,3, [1,0,0, 0,1,0, 0,0,1])
e_1=matrix(SR,3,3, [1,0,-1, 0,0,0, -1,0,1])
e_2=matrix(SR,3,3, [0,1,-1, 0,0,0, 0,-1,1])
e_3=matrix(SR,3,3, [0,0,0, 1,0,-1, -1,0,1])
e_4=matrix(SR,3,3, [0,0,0, 0,1,-1, 0,-1,1])
M=matrix(SR,3,3, [a,b,1-a-b, c,d,1-c-d, 1-a-c, 1-b-d,a+b+c+d-1])
M_1=e_1*M+M*e_1
M_2=e_2*M+M*e_2
M_3=e_3*M+M*e_3
M_4=e_4*M+M*e_4
A=matrix(SR,4,4, [ M_1[0,0], M_1[0,1],M_1[1,0],M_1[1,1], M_2[0,0], M_2[0,1],M_2[1,0],M_2[1,1], M_3[0,0], M_3[0,1],M_3[1,0],M_3[1,1], M_4[0,0], M_4[0,1],M_4[1,0],M_4[1,1] ])
f(a,b,c,d)=A.determinant()
And then I want a solution to f==0, after giving some random arguments to it
var('k,l,m,n,t,y')
for i in range(5):
k=random(); n=random()
if k>n: y=k
else: y=n
l=random()*(1-y)
m=random()*(1-y)
if k+l+m+n>1:
sols=solve([f(k*t+1-t,l*t,m*t,n*t+1-t)==0], t);
sols[1]
A wild string of numbers pops out. But how do i get to see how much is it? Changing to sols[1].n() gives "TypeError: cannot evaluate symbolic expression numerically".
Thanks in advance!
ozikSat, 01 Sep 2012 21:39:48 -0500http://ask.sagemath.org/question/9286/How do I evaluate symbolic expressions numerically in notebook()http://ask.sagemath.org/question/8589/how-do-i-evaluate-symbolic-expressions-numerically-in-notebook/I have solved an equation using this statement
s1 = solve(eq,ss)
The result is
ss = **rhs**
By setting all other variables in the right-hand side of the equation, I can retrieve a value using, among other things,
print **rhs**
or
N(**rhs**),
but when I try
N(ss)
I get the error message "cannot evaluate symbolic expression numerically". How can I evaluate the left-hand side as if it were the right-hand side?
khentiamentiuTue, 10 Jan 2012 12:52:18 -0600http://ask.sagemath.org/question/8589/