Ask Your Question
0

Maxima wants to know whether %k1 is positive or negative

asked 2021-04-07 14:49:01 +0100

Dr. Banana gravatar image

updated 2021-04-07 15:04:34 +0100

slelievre gravatar image

Trying to solve a differential equation in Sage:

sage:  de = -diff(y, x, 2) - G*M/y^2
sage: desolve(de, y, ics=[0, 1000])

I get a type error and a question:

 TypeError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(%k1>0)', see `assume?` for more details)
Is %k1 positive or negative?

But when I use assume(%k1>0) I get a syntax error, saying that there's something wrong with the percent sign.

edit retag flag offensive close merge delete

Comments

It's just a syntax. In place of %k1 substitute an actual parameter from your equation. For example, assume(G>0).

Max Alekseyev gravatar imageMax Alekseyev ( 2021-04-07 15:31:14 +0100 )edit

It's not just a syntax : Maxima asks for the sign of a constant it has itself introduced. This is, IMHO, a bug.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-04-08 08:59:07 +0100 )edit

I also think that it is a bug. SageMath does not send the assumptions to Maxima solver.

tolga gravatar imagetolga ( 2021-04-08 09:24:12 +0100 )edit

SageMath does not send the assumptions to Maxima solver.

Nope. See my answer below. When the assumptions on G and M are omitted, Maxima's question is about of the sign of GM%k1`.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-04-08 09:56:07 +0100 )edit

Then what is the problem with the following code?

var('G,M')

y=function('y')(x)

assume(G*M>0)

de = -diff(y, x, 2) - G*M/y^2

desolve(de, y, ivar=x, ics=[0, 1000])

tolga gravatar imagetolga ( 2021-04-08 10:25:13 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-04-08 10:41:57 +0100

Emmanuel Charpentier gravatar image

As said in comment, the problem is that Maxima introduces a arbitrary constant %k1 and asks the user an hypothesis about it :

sage: G,M=var("G,M")
sage: y=function("y")
sage: with assuming(G>0, M>0): Sol=desolve(de, y(x), ivar=x)

[ Snip.. ]

TypeError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(%k1>0)', see `assume?` for more details)
Is %k1 positive or negative?

The workaround to this problem is to add this assumption to what Maxima uses. This leads to another problem : there's no way to define a variable whose Maxima name would be %k1. The workaround is to ruin this directly in Sage's default Maxima interpreter :

sage: maxima_calculus("assume(%k1>0);")
[%k1>0]
sage: with assuming(G>0, M>0): Sp=desolve(de, y(x), ivar=x)
sage: maxima_calculus("forget(%k1>0);")
[%k1>0]
sage: maxima_calculus("assume(%k1<0);")
[%k1<0]
sage: with assuming(G>0, M>0): Sn=desolve(de, y(x), ivar=x)

One gets implicit answers, woese getting explicit solutions is ... problematic :

sage: Sp+Sn
[1/2*sqrt(2)*(G*M*arctan(sqrt(-(G*M*_K1*y(x) - G*M)/y(x))/sqrt(G*M*_K1)) + sqrt(G*M*_K1)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x))*y(x))/(sqrt(G*M*_K1)*G*M*_K1) == _K2 + x,
 -1/2*sqrt(2)*(G*M*arctan(sqrt(-(G*M*_K1*y(x) - G*M)/y(x))/sqrt(G*M*_K1)) + sqrt(G*M*_K1)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x))*y(x))/(sqrt(G*M*_K1)*G*M*_K1) == _K2 + x,
 1/4*sqrt(2)*(G*M*log(-(sqrt(2)*sqrt(-G*M*_K1) - sqrt(2)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x)))/(sqrt(2)*sqrt(-G*M*_K1) + sqrt(2)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x)))) + 2*sqrt(-G*M*_K1)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x))*y(x))/(sqrt(-G*M*_K1)*G*M*_K1) == _K2 + x,
 -1/4*sqrt(2)*(G*M*log(-(sqrt(2)*sqrt(-G*M*_K1) - sqrt(2)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x)))/(sqrt(2)*sqrt(-G*M*_K1) + sqrt(2)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x)))) + 2*sqrt(-G*M*_K1)*sqrt(-(G*M*_K1*y(x) - G*M)/y(x))*y(x))/(sqrt(-G*M*_K1)*G*M*_K1) == _K2 + x]

More readably :

$$ \frac{\sqrt{2} {\left(G M \arctan\left(\frac{\sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}{\sqrt{G M K_{1}}}\right) + \sqrt{G M K_{1}} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}} y\left(x\right)\right)}}{2 \, \sqrt{G M K_{1}} G M K_{1}} = K_{2} + x $$

$$ -\frac{\sqrt{2} {\left(G M \arctan\left(\frac{\sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}{\sqrt{G M K_{1}}}\right) + \sqrt{G M K_{1}} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}} y\left(x\right)\right)}}{2 \, \sqrt{G M K_{1}} G M K_{1}} = K_{2} + x $$

$$\frac{\sqrt{2} {\left(G M \log\left(-\frac{\sqrt{2} \sqrt{-G M K_{1}} - \sqrt{2} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}{\sqrt{2} \sqrt{-G M K_{1}} + \sqrt{2} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}\right) + 2 \, \sqrt{-G M K_{1}} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}} y\left(x\right)\right)}}{4 \, \sqrt{-G M K_{1}} G M K_{1}} = K_{2} + x $$

$$ -\frac{\sqrt{2} {\left(G M \log\left(-\frac{\sqrt{2} \sqrt{-G M K_{1}} - \sqrt{2} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}{\sqrt{2} \sqrt{-G M K_{1}} + \sqrt{2} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}}}\right) + 2 \, \sqrt{-G M K_{1}} \sqrt{-\frac{G M K_{1} y\left(x\right) - G M}{y\left(x\right)}} y\left(x\right)\right)}}{4 \, \sqrt{-G M K_{1}} G M K_{1}} = K_{2} + x $$

Neither Sympy nor Fricas can solve thos ODE ; Mathematica also returns an implicit solution :

sage: mathematica("DSolve[-y''[x]-G*M/y[x]^2==0, y[x], x]")
Solve[
 (-((G*M*Log[G*M + C[1]*y[x] + Sqrt[C[1]]*Sqrt[C[1] + (2*G*M)/y[x]]*y[x]])/
      C[1]^(3/2)) + (Sqrt[C[1] + (2*G*M)/y[x]]*y[x])/C[1])^2 == (x + C[2])^2, 
 y[x]]

i. e., more readibly :

$$ \text{Solve}\left[\left(\frac{y(x) \sqrt{c_1+\frac{2 G M}{y(x)}}}{c_1}-\frac{G M \log \left(\sqrt{c_1} y(x) \sqrt{c_1+\frac{2 G M}{y(x)}}+c_1 y(x)+G M\right)}{c_1^{3/2}}\right){}^2=\left(c_2+x\right){}^2,y(x)\right] $$

Note : since your ODE is of the second order, you need two boundary conditions uin order to determine your solution ; your ics gives only one...

edit flag offensive delete link more

Comments

So I tried solving this in wxmaxima: eq: 'diff(y, x, 2)=-G*M/y^2 sol2: ode2(eq, y, x) bc2(sol2, x=0, y=1000, x=pi*sqrt(1000^3/8*G*M), y=5) wxmaxima just returns []

Dr. Banana gravatar imageDr. Banana ( 2021-04-11 17:21:27 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-04-07 14:49:01 +0100

Seen: 626 times

Last updated: Apr 08 '21