Is there a way to provide get dsolve()
to use arbitrary constants named by a different sequence than C1, C2, etc?
cse()
allows a symbols
parameter that accepts an infinite generator of names, but I don't see a similar parameter to dsolve()
.
I'm solving circuit equations full of symbolic capacitances, and the dsolve
constants are getting confusing.
Failing that, is there a quick way to replace the arbitrary constants with others such as k_1, k_2, etc? It looks like dsolve()
is using C1, C2, etc, for its constants while my code uses C_1, C_2, etc for capacitances. I could change my naming everywhere to use a non-standard capacitance symbol, but I'd prefer not to.
With thanks to @Marshmallow, I've started using this routine which wraps dsolve lets me change the symbols after the fact. There's still the risk of collision, but it's good enough for now:
def newdsolve(eq,*args,**kwds):
ss=kwds.get('symbols')
sln=dsolve(eq,*args,**kwds)
psyms=((newdsolve.csre.match(n.name),n) for n in eqVc.free_symbols)
if ss and isinstance(ss,str):
subsdict=dict([(n[1],'k_'+n[0].group(1)) for n in psyms if n[0]])
elif ss:
subsdict=dict([(n[1],next(ss)) for n in psyms if n[0]])
else: subsdict={}
return sln.subs(subsdict)
newdsolve.csre=re.compile(r'C(\d+)')