I currently have a large system autonomous differential equations. I've indexed a more managable dummy system of identical form, using Part
to reference each individual equation, so:
eqns = {c1' == -kf*c1 + kr*c2, c2 == kf*z1 - kr*z2 - kf*c2, c3' == kp*c2}
with each LHS denoted cn'
where n ranges from 0 to 3 (or the # of equations). Inputting eqns[[1]]
yields:
c1' == -a kf + b kr
Whereas inputting FullSimplify @ eqns[[1]]
yields kf c1 + c1' == kr c2
.
Does anyone know a way to specify that the format ought be maintained, ie.
Some Input
which would isolate c1' in the FullSimplify
term, or yield c1' == kr c2 - kf c1
This sounds petty and is in this dummy example, but isn't for larger systems.
Thank you in advance.
Edit:
I've spent awhile digging around online and in the help to no avail other than possibly changing my notation format, which would render my future use of NDSolve, where I hope to use the shorthand of eqns
, problematic given Mathematica's understanding of prime notation for derivatives. (Also, another complication in changing the LHS notation of c1', ..., cn'
is in that each is an implicit (rather than explicit) function of (t) (see my attached link in line 1), and so in NDSolve each cn'
and cn
must be appended with a [t]
on the end at some point in the NDSolve
function.
Answer
As discussed in chat earlier here the two main issues:
First, to apply FullSimplify
only on the RHS of each equation, many ways are possible. One very verbose way is to use replacement rules. The following example shows how to apply a function FS
(you can replace this with FullSimplify
) only on the RHS of equations having a Derivative
as LHS:
eqns = {a'[t] == -k1f a[t] + k1r b[t],
b'[t] == k1f a[t] - k1r b[t] - k2f b[t], c'[t] == k2f b[t],
a[0] == a0, b[0] == 0, c[0] == 0};
eqns /. ((lhs : Derivative[1][_][t]) == rhs_) :> (lhs == FS[rhs])
Second, although the time $t$ does not appear explicitly in your pde (because it is autonomous), you still have to use it on symbols, which are dependent on the time. The example in the wiki-page you linked was $y'=(2-y)y$, but to use it with NDSolve
you have to make the dependency explicit:
NDSolve[{y'[t] == (2 - y[t])*y[t], y[0] == 2}, y, {t, 0, 10}]
Comments
Post a Comment