ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 26 Jul 2011 00:55:36 +0200Solving symbolically equation systemhttps://ask.sagemath.org/question/8242/solving-symbolically-equation-system/I have an equation system:
*U(t) = R * I(t) + L * I'(t) + uC(t)*
*I(t) = C * uC'(t)*
I want to know value of *I'(t)* and *uC'(t)*, which is *(-I(t) * R + U - uC(t))/L* and *I(t)/C* respectively.
In sage I represent it this way:
R = 6; C = 10^(-4); L = 0.1
t = var('t')
U = function('U', t).function(t); I = function('I', t).function(t); uC = function('uC', t).function(t)
equations = [
U == R * I + L * I.diff(t) + uC,
I == C * uC.diff(t)
]
but
solve(equations, I.diff(t), uC.diff(t))
does't seem to be working. (*TypeError: 'sage.symbolic.expression.Expression' object is not iterable*)
why? how can I do this?
Sat, 23 Jul 2011 21:24:08 +0200https://ask.sagemath.org/question/8242/solving-symbolically-equation-system/Answer by benjaminfjones for <p>I have an equation system:</p>
<p><em>U(t) = R * I(t) + L * I'(t) + uC(t)</em></p>
<p><em>I(t) = C * uC'(t)</em></p>
<p>I want to know value of <em>I'(t)</em> and <em>uC'(t)</em>, which is <em>(-I(t) * R + U - uC(t))/L</em> and <em>I(t)/C</em> respectively.</p>
<p>In sage I represent it this way:</p>
<pre><code>R = 6; C = 10^(-4); L = 0.1
t = var('t')
U = function('U', t).function(t); I = function('I', t).function(t); uC = function('uC', t).function(t)
equations = [
U == R * I + L * I.diff(t) + uC,
I == C * uC.diff(t)
]
</code></pre>
<p>but</p>
<pre><code>solve(equations, I.diff(t), uC.diff(t))
</code></pre>
<p>does't seem to be working. (<em>TypeError: 'sage.symbolic.expression.Expression' object is not iterable</em>)</p>
<p>why? how can I do this?</p>
https://ask.sagemath.org/question/8242/solving-symbolically-equation-system/?answer=12536#post-id-12536As far as I know, `solve` only works with variables. So as a preliminary step you can substitute some new variables for `I.diff(t)` and `uC.diff(t)` and then solve. The other problem occuring is that to solve a system of equations for multiple variables, those variables should be specified as a list. Try this: (first substitute new variables `DI` and `DuC` for the two derivatives and then call `solve`)
sage: E2 = [ e.subs({I.diff(t): DI, uC.diff(t): DuC}) for e in equations ]
sage: E2
[t |--> U(t) == 0.100000000000000*DI + 6*I(t) + uC(t), t |--> I(t) == 1/10000*DuC]
sage: solve(E2, [DI, DuC])
[[DI == 10*U(t) - 60*I(t) - 10*uC(t), DuC == 10000*I(t)]]
Tue, 26 Jul 2011 00:55:36 +0200https://ask.sagemath.org/question/8242/solving-symbolically-equation-system/?answer=12536#post-id-12536