First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 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,

click to hide/show revision 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,