Patch to make ic2 work even with i.c. 'y(x)= (fwd)




---------- Forwarded message ----------
Date: Sat, 31 Jan 2009 02:15:59 +0100 (CET)
From: Christophe Deroulers <deroulers at phare.normalesup.org>
To: maxima at math.utexas.edu
Subject: Patch to make ic2 work even with i.c. 'y(x)=

   Hello,

  This is a patch proposal / feature request.

  In brief:
  ---------
  Change subs([xa,ya],soln) to subs([ya,xa],soln) in the line 318 of the file 
share/diffequations/ode2.mac .

  This would allow initial conditions like 'y(x)=2 (for an O.D.E. written like 
"... + 'y(x)= 0") in addition to initial conditions like y=2 (for an O.D.E. 
written like "... + y = 0").

  This would also make SAGE's users' life easier.

  Details and motivation:
  -----------------------

  According to the documentation of ode2, the proper way to solve the O.D.E. 
y''(x)+y(x)=0 with initial conditions y(0)=2, y'(0)=3 is the following:

my_ode: 'diff(y,x,2) + y = 0;
my_sol: ode2(my_ode, y, x);
ic2(my_sol, x=0, y=2, 'diff(y,x)=3);

  Maxima returns

(%o3)                       y = 3 sin(x) + 2 cos(x)

as expected.

  If, instead, one tries the following:

my_ode: diff('y(x),x,2) + 'y(x) = 0;
my_sol: ode2(my_ode, 'y(x), x);
ic2(my_sol, x=0, 'y(x)=2, diff('y(x),x)=3);

Maxima returns:

(%o3)                     y(x) = 3 sin(x) + y(0) cos(x)

with y(0) instead of 2.

  It turns out that, when one solves this O.D.E. with SAGE's desolve function, 
SAGE is sending the second sequence of commands to Maxima (in a more verbose 
way). Thefore, typing "x=var('x'); y=function('y',x); 
desolve(diff(y,x,2)+y(x)==0, y, [0,2,3])" in SAGE yields the same solution with 
trailing y(0) as above instead of 3*sin(x)+2*cos(x).

  This behaviour can be easily explained: the function ic2 builds a system of 
two equations, one for each initial condition, that is solved to find the two 
unknowns of the general solution returned by ode2. The first of these two 
equations is built thanks to "subst([xa,ya],soln)" (line 318 of the file 
share/diffequations/ode2.mac) where xa is "x=0" and ya is "'y(x)=2". If x is 
replaced by 0 first, then 'y(x) by 2, the resulting equation is "y(0) = %k1" 
(right but not very useful), and y(0) remains in the final result. But, if 
'y(x) is replaced first and then x by 0, the resulting equation is "2=%k1" 
(right and useful).

  An easy way of making this second sequence of commands work would therefore be 
to swap the order of the substitutions (see proposal at the beginning of this 
message and attached patch --- as I'm a newbie I probably did not make my patch 
correctly, I did not use RCS).

  Thank you for your help! (Should I submit this to TRAC?)

   Christophe Deroulers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ic2.patch
Type: text/x-diff
Size: 695 bytes
Desc: 
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20090131/46797b92/attachment.bin