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.Fri, 24 Oct 2014 18:08:25 +02002nd-order ODE: Maxima wants sign of 1 constant before finishinghttps://ask.sagemath.org/question/24624/2nd-order-ode-maxima-wants-sign-of-1-constant-before-finishing/ I'm trying to solve a 2nd-order nonlinear ODE using desolve(). Maxima gets partway through, but then asks for the sign of one of the integration constants. How can I tell it to assume something that doesn't exist before I call desolve()?
t,P,x0=var('t,P,x0')
x=function('x',t)
de=(diff(x,t,2)*x^2+P==0)
forget()
assume(P>0,x0>0)
desolve(de,x,ics=[0,x0,0],ivar=t)
gives the error:
TypeError: ECL says: Maxima asks: Is %k1 positive or negative?
Fri, 24 Oct 2014 17:16:29 +0200https://ask.sagemath.org/question/24624/2nd-order-ode-maxima-wants-sign-of-1-constant-before-finishing/Answer by kcrisman for <p>I'm trying to solve a 2nd-order nonlinear ODE using desolve(). Maxima gets partway through, but then asks for the sign of one of the integration constants. How can I tell it to assume something that doesn't exist before I call desolve()?</p>
<pre><code>t,P,x0=var('t,P,x0')
x=function('x',t)
de=(diff(x,t,2)*x^2+P==0)
forget()
assume(P>0,x0>0)
desolve(de,x,ics=[0,x0,0],ivar=t)
</code></pre>
<p>gives the error:</p>
<pre><code>TypeError: ECL says: Maxima asks: Is %k1 positive or negative?
</code></pre>
https://ask.sagemath.org/question/24624/2nd-order-ode-maxima-wants-sign-of-1-constant-before-finishing/?answer=24625#post-id-24625That is a very good question, and my answer will both be workarounds. I'm not sure we can solve this directly because of the way we interact with Maxima. Below is some gory detail of trying to do it directly in Maxima.
----------
That will be annoying because the syntax will be different, but then you could answer the question. Unfortunately, the syntax is not nice, and took me a bit of reading through our code for `desolve??` as well as [the Maxima desolve docs](http://maxima.sourceforge.net/docs/manual/maxima_21.html).
But in fact the solution doesn't even seem to solve it - there is a `y` on the left hand side in several places. I'm also not sure why `x0` doesn't appear, but I suspect it has something to do with the reason it asks a question - probably there is some two integrations happening internally and it's not getting the initial condition in right?
sage: maxima_console()
<snip stuff>
(%o13) [x0 > 0]
(%i14) assume(P>0);
(%o14) [P > 0]
(%i15) atvalue(y(x),x=0,x0);
(%o15) x0
(%i16) atvalue('diff(y(x),x),x=0,0);
(%o16) 0
(%i17) display2d:false;
(%o17) false
(%i18) ode2('diff(y,x,2)*y^2+P,y,x);
Is %k1 positive or negative?
p;
(%o18) [(sqrt(2)*atan(sqrt(-(%k1*y-1)/y)/sqrt(%k1))
+sqrt(2)*sqrt(%k1)*y*sqrt(-(%k1*y-1)/y))
/(2*%k1^(3/2)*sqrt(P))
= x+%k2,
-(sqrt(2)*atan(sqrt(-(%k1*y-1)/y)/sqrt(%k1))
+sqrt(2)*sqrt(%k1)*y*sqrt(-(%k1*y-1)/y))
/(2*%k1^(3/2)*sqrt(P))
= x+%k2]
(%i19) ode2('diff(y,x,2)*y^2+P,y,x);
Is %k1 positive or negative?
n;
(%o19) [(sqrt(2)*log((sqrt(-(%k1*y-1)/y)-sqrt(-%k1))
/(sqrt(-(%k1*y-1)/y)+sqrt(-%k1)))
+2^(3/2)*sqrt(-%k1)*y*sqrt(-(%k1*y-1)/y))
/(4*sqrt(-%k1)*%k1*sqrt(P))
= x+%k2,
-(sqrt(2)*log((sqrt(-(%k1*y-1)/y)-sqrt(-%k1))
/(sqrt(-(%k1*y-1)/y)+sqrt(-%k1)))
+2^(3/2)*sqrt(-%k1)*y*sqrt(-(%k1*y-1)/y))
/(4*sqrt(-%k1)*%k1*sqrt(P))
= x+%k2]Fri, 24 Oct 2014 18:08:25 +0200https://ask.sagemath.org/question/24624/2nd-order-ode-maxima-wants-sign-of-1-constant-before-finishing/?answer=24625#post-id-24625