On 22 bře, 14:26, YURi KARADZhOV <yuri.karadz...@gmail.com> wrote:
> I played around with sage and found some problems with desolve command.
> To solve ode diff(y(x),x)+a*y(x)+b*x+c we should first define variables and
> functions
>
> x = var('x')
>
> a,b,c=var('a b c')
>
> y=function('y',x)
>
> eq=diff(y,x)+a*y+b*x+c
>
> but than unless it is obvious that the dependent variable is x and
> independent is y we should write such command

Thanks for working on this problem, it would be nice to declare a,b,c
as constants, but I guess that it is not possible in Sage now. Any
idea how to extend Sage in this way?

>
> desolve(eq,y,ivar=x)
>
> which is really annoying. And what is worse - we get a wrong answer
>
> -((a*x - 1)*b*e^(a*x)/a^2 + c*e^(a*x)/a - c)*e^(-a*x)
>
> but the right answer is
>
> -((a*x - 1)*b*e^(a*x)/a^2 + c*e^(a*x)/a - _C1)*e^(-a*x)

The problem is that
sage: maxima("%c").sage()

returns c, but should return some more resonable free variable, say
_C1.

>
> where _C1 - arbitrary constant.
>
> Of course, if we don't use c as a variable in equation we will get a right
> answer, but another problem will rise. If we have a bunch of ODE and want
> their solutions to interact somehow, than we expect different arbitrary
> constant for each one. But sage uses one letter c in every solution, which
> causes problems.
>
> Actually the first problem is easy to solve. We can correct
> devel/sage-main/build/sage/calculus/desolvers.py
>
> First - make dvar variable which represent dependent variable optional by
> giving it default value None.
>
> < #64
> def desolve(de, dvar, ics=None, ivar=None, show_method=False,
> contrib_ode=False):
>
> def desolve(de, dvar=None, ics=None, ivar=None, show_method=False,
> contrib_ode=False):
>
> Second - add definition of dvar.
> dvar - is one of the functions differentiated.
>
> > after #319
>
> if dvar is None
>     dvars = extract_func_from_diff(de)
>     if len(dvars) != 1:
>         raise ValueError, "Unable to determine dependent variable, please
> specify."
>     dvar = dvars.pop()
>
> Finally - change definition of ivar.
> ivar - is argument of dvar and it is also in parameter_set of
> FDerivativeOperator
>
> < #324-329
> elif ivar is None:
>     ivars = de.variables()
>     ivars = [t for t in ivars if t is not dvar]
>     if len(ivars) != 1:
>         raise ValueError, "Unable to determine independent variable, please
> specify."
>     ivar = ivars[0]
>
> elif ivar is None:
>     ivars = set(dvar.arguments()).intersection(extract_var_from_diff(de))
>     if len(ivars) != 1:
>         raise ValueError, "Unable to determine independent variable, please
> specify."
>     ivar = ivars.pop()
>

I am not sure if this will work for DE's involving term like y'(a*x
+b). But if you find a secure method how to find dependent and
independent variables from derivative, you can also fix bug
http://trac.sagemath.org/sage_trac/ticket/7401

Another related question: if we use topoly_solve=True in solve
command, we get free variabkles, say z2 and z4, if we run the same
command for the second time, we get other variables, say z_5 and z_7.
Should we have similar behavior with free variables from desolve
command? I think that it is better to get the same answer avery time
when I solve the same equation.

Thanks for working on this.

Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

To unsubscribe from this group, send email to 
sage-devel+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to