basic question on constant of integration when using desolve

72 views
Skip to first unread message

Nasser M. Abbasi

unread,
Jul 26, 2012, 6:37:56 AM7/26/12
to sage-s...@googlegroups.com
I do not know much of anything about sage. But I was using desolve on http://www.sagenb.org to compare an answer,
and I am confused on the type-setting of of constant of integration in solution of an ode.

Googled around but nothing specific I could find.

When I ask sage to solve an ode using desolve, it seems to use `c` for constant of integration in the result, like this:

reset()
x
= var('x')
y
= function('y', x)
desolve
(diff(y,x)+y, y,ivar=x)

which gives

c*e^(-x)

I wish it generated at least uppercase `C` or such. But any way. Now the confusing part.

If I use `c` myself in the ode, then the result will contains 2 c's. The constant of integration `c` that sage uses, and my own `c` which I have in the ode itself. So how is a user to know which is which when they look at the result??

reset()
x
,c= var('x c')
y
= function('y', x)
desolve
(diff(y,x)+c*y, y,ivar=x)


which gives
c*e^(-c*x)

Is there a way to tell sage to use at least upper case letter for constant of integration?

This is how Mathematica does it:

In[67]:= DSolve[y'[x]+c*y[x]==0,y[x],x]
Out[67]= {{y[x]->E^(-c x) C[1]}}


You can see it is easy to see which is the constant of integration in the result. If there are
more than one constant of integrations, they become C[1], C[2], etc....

same with Maple

dsolve(diff(y(x),x)+c*y(x)=0);
 y
(x) = _C1 exp(-c x)


see, it uses _C1

How can one make sage change this behavior so it is easier to read the results? lower case
letters for constant of integrations is not really a good way to do this.

thanks,


kcrisman

unread,
Jul 26, 2012, 11:02:52 AM7/26/12
to sage-s...@googlegroups.com


On Thursday, July 26, 2012 6:37:56 AM UTC-4, Nasser M. Abbasi wrote:
I do not know much of anything about sage. But I was using desolve on http://www.sagenb.org to compare an answer,

Tata!  You clearly know *something* about it, or you wouldn't have done as well as you have finding stuff out.

When I ask sage to solve an ode using desolve, it seems to use `c` for constant of integration in the result, like this:


Yes, we get this directly from Maxima, except (I believe) as %c.

 
reset()
x
= var('x')
y
= function('y', x)
desolve
(diff(y,x)+y, y,ivar=x)

which gives

c*e^(-x)

I wish it generated at least uppercase `C` or such. But any way. Now the confusing part.


Actually, it's worse than that.

c
Traceback (click to the left of this block for traceback)
...
NameError: name 'c' is not defined

So as you can see, this "c" from Maxima is not really "there" in the same sense.  Interestingly, Sage still knows it's there and a symbolic expression (the "c", I mean), but it's purely local in some sense that I don't quite get.
 
If I use `c` myself in the ode, then the result will contains 2 c's. The constant of integration `c` that sage uses, and my own `c` which I have in the ode itself. So how is a user to know which is which when they look at the result??


Right, this is a problem.


Is there a way to tell sage to use at least upper case letter for constant of integration?


I don't think that would make any difference.  Then people who like defining upper-case variables would get upset.  The real problem is that some conflict should be detected and this variable replaced by something - but what?  I could imagine someone already having defined c, c1, c2, c3, C, C1, C2, C3, c_1, C_1, etc. - now what should Sage pick?  It's not obvious.

Anyway, this has been noticed in the past - see http://trac.sagemath.org/sage_trac/ticket/9421 for where we are tracking this.  http://trac.sagemath.org/sage_trac/ticket/6882 should in theory solve this, but first we would need to find a way to do that in a user-friendly way.

achrzesz

unread,
Jul 26, 2012, 11:51:33 AM7/26/12
to sage-s...@googlegroups.com
Sometimes a workaround is possible:

sage: x = var('x')
sage: y = function('y', x)
sage: C = var('C')
sage: f = desolve(diff(y,x) + y, y, ics=[0,C]); f
C*e^(-x)
sage: c = var('c')
sage: f = desolve(diff(y,x) +c*y, y,ivar=x, ics=[0,C]); f
C*e^(-c*x)
Reply all
Reply to author
Forward
0 new messages