| 1 | initial version |
Without some sample problem code, it is not easy to come up with sample solution code. So let's pontify...
You can extract the variables of a symbolic expression with the method .variables() ; this returns a tuple, which you can turn in a set thanks to the function set. Its difference() method allows you to substract the original parameters (present in the suystem before solution) ; what remains are the new parameters introduced by the solver.
What remains to do is to map such a function to the elements of the solution(s) and compute the union of the result.
Made-up example for an ordinary differential equation :
sage: Ovars=var("t, a, b, c")
sage: f=function("f")
sage: de=a*f(t).diff(t,2)+b*f(t).diff(t)+c==0
sage: with assuming(b!=0):Sol=desolve(de, f(t), ivar=t) ; Sol
_K2*e^(-b*t/a) + _K1 - (b*c*t - a*c)/b^2
sage: len(Params:=set(Sol.variables())-set(Ovars))
2
sage: Params
{_K2, _K1}
Extrapolate for multiple-elements solution(s) and/or multiple solutions, and season to teaste. Serve cool...
HTH,
| 2 | No.2 Revision |
Without some sample problem code, it is not easy to come up with sample solution code. So let's pontify...
You can extract the variables of a symbolic expression with the method .variables() ; this returns a tuple, which you can turn in a set thanks to the function set. Its difference() method allows you to substract the original parameters (present in the suystem before solution) ; what remains are the new parameters introduced by the solver.
What remains to do is to map such a function to the elements of the solution(s) and compute the union of the result.
Made-up example for an ordinary differential equation :
sage: Ovars=var("t, a, b, c")
sage: f=function("f")
sage: de=a*f(t).diff(t,2)+b*f(t).diff(t)+c==0
sage: with assuming(b!=0):Sol=desolve(de, f(t), ivar=t) ; Sol
_K2*e^(-b*t/a) + _K1 - (b*c*t - a*c)/b^2
sage: len(Params:=set(Sol.variables())-set(Ovars))
2
sage: Params
{_K2, _K1}
Extrapolate for multiple-elements solution(s) and/or multiple solutions, and season to teaste. taste. Serve cool...
HTH,
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.