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.Thu, 24 Mar 2016 19:34:04 +0100solve a system of two equations for a derivativehttps://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/ I have the following defined:
sage: var('a, t');
sage: function('x, y, v, u')
sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)
sage: de2 = diff(y(t),t) == y(t)
I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).
sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:
sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));
i get the following error:
Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
=============================
I'd appreciate any help with this. thank you.Wed, 23 Mar 2016 08:03:07 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/Comment by ndomes for <p>I have the following defined:</p>
<p>sage: var('a, t');</p>
<p>sage: function('x, y, v, u')</p>
<p>sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)</p>
<p>sage: de2 = diff(y(t),t) == y(t)</p>
<p>I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).</p>
<p>sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:</p>
<p>sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));</p>
<p>i get the following error:</p>
<p>Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>=============================</p>
<p>I'd appreciate any help with this. thank you.</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32862#post-id-32862Why not using `desolve` ? See [documentation](http://doc.sagemath.org/html/en/prep/Quickstarts/Differential-Equations.html)Wed, 23 Mar 2016 12:13:07 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32862#post-id-32862Comment by sophia for <p>I have the following defined:</p>
<p>sage: var('a, t');</p>
<p>sage: function('x, y, v, u')</p>
<p>sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)</p>
<p>sage: de2 = diff(y(t),t) == y(t)</p>
<p>I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).</p>
<p>sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:</p>
<p>sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));</p>
<p>i get the following error:</p>
<p>Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>=============================</p>
<p>I'd appreciate any help with this. thank you.</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32869#post-id-32869I'm not trying to solve the differential equations just yet. i only want to solve the equations algebraically (explicitly) for the derivatives, so I can compute the Jacobian matrix of the right hand sides for further bifurcation analysis. the equations in my actual problem have parameters.
(this is pretty easy to do in Maple)Wed, 23 Mar 2016 21:45:55 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32869#post-id-32869Comment by kcrisman for <p>I have the following defined:</p>
<p>sage: var('a, t');</p>
<p>sage: function('x, y, v, u')</p>
<p>sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)</p>
<p>sage: de2 = diff(y(t),t) == y(t)</p>
<p>I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).</p>
<p>sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:</p>
<p>sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));</p>
<p>i get the following error:</p>
<p>Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>=============================</p>
<p>I'd appreciate any help with this. thank you.</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32880#post-id-32880See also http://ask.sagemath.org/question/32876/finding-the-derivative-of-a-functional-wrt-a-function/Thu, 24 Mar 2016 19:34:04 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32880#post-id-32880Answer by castor for <p>I have the following defined:</p>
<p>sage: var('a, t');</p>
<p>sage: function('x, y, v, u')</p>
<p>sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)</p>
<p>sage: de2 = diff(y(t),t) == y(t)</p>
<p>I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).</p>
<p>sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:</p>
<p>sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));</p>
<p>i get the following error:</p>
<p>Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>=============================</p>
<p>I'd appreciate any help with this. thank you.</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?answer=32868#post-id-32868In your case it would be something like this:
var('t');
x=function('x')(t)
y=function('y')(t)
de1 = diff(x,t) - diff(y,t) == x
de2 = diff(y,t) == y
desolve_system([de1, de2], [x,y])
and the result is as follows:
[x(t) == t*e^t*y(0) + e^t*x(0), y(t) == e^t*y(0)]
Wed, 23 Mar 2016 21:42:39 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?answer=32868#post-id-32868Comment by sophia for <p>In your case it would be something like this: </p>
<pre><code>var('t');
x=function('x')(t)
y=function('y')(t)
de1 = diff(x,t) - diff(y,t) == x
de2 = diff(y,t) == y
desolve_system([de1, de2], [x,y])
</code></pre>
<p>and the result is as follows:</p>
<pre><code>[x(t) == t*e^t*y(0) + e^t*x(0), y(t) == e^t*y(0)]
</code></pre>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32872#post-id-32872thanks for replying. i don't want to use desolve yet. all i'd like to do is to solve the equations algebraically (explicitly) for the derivatives. thank you,Thu, 24 Mar 2016 02:28:57 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32872#post-id-32872Answer by calc314 for <p>I have the following defined:</p>
<p>sage: var('a, t');</p>
<p>sage: function('x, y, v, u')</p>
<p>sage: de1 = diff(x(t),t) - diff(y(t),t) == x(t)</p>
<p>sage: de2 = diff(y(t),t) == y(t)</p>
<p>I'd like to solve these two equations algebraically for diff(x(t),t) and diff(y(t),t).</p>
<p>sage: sol = solve(de1, diff(x(t),t)); works, and i get an explicit solution for diff(x(t),t), but when i try solving both equations using:</p>
<p>sage: sol = solve([de1, de2],diff(x(t),t),diff(y(t),t));</p>
<p>i get the following error:</p>
<p>Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 822, in solve
variables = tuple(args[0])
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>=============================</p>
<p>I'd appreciate any help with this. thank you.</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?answer=32870#post-id-32870I see what you want to do, but apparently solve will not work with two equations and two derivatives in this way. I think this must have something to do with how Maxima works or how Sage is passing info to Maxima.
Another option would be to use x1 and y1 in place of your derivatives and then solve, since you are really not using the fact that you have functions of t in this solving procedure.
var('x y x1 y1')
de1 = x1 - y1 == x
de2 = y1 == y
sol = solve([de1,de2],[x1,y1])
sol
This gives:
[[x1 == x + y, y1 == y]]
To find the Jacobian, you need the appropriate vector field. You can get this from the solution with the following
F=map(lambda q: q.rhs(),sol[0])
Then, the Jacobian is:
jacobian(F,[x,y])
Does that resolve the issue?
Wed, 23 Mar 2016 22:47:39 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?answer=32870#post-id-32870Comment by sophia for <p>I see what you want to do, but apparently solve will not work with two equations and two derivatives in this way. I think this must have something to do with how Maxima works or how Sage is passing info to Maxima.</p>
<p>Another option would be to use x1 and y1 in place of your derivatives and then solve, since you are really not using the fact that you have functions of t in this solving procedure.</p>
<pre><code>var('x y x1 y1')
de1 = x1 - y1 == x
de2 = y1 == y
sol = solve([de1,de2],[x1,y1])
sol
</code></pre>
<p>This gives:</p>
<pre><code>[[x1 == x + y, y1 == y]]
</code></pre>
<p>To find the Jacobian, you need the appropriate vector field. You can get this from the solution with the following</p>
<pre><code>F=map(lambda q: q.rhs(),sol[0])
</code></pre>
<p>Then, the Jacobian is:</p>
<pre><code>jacobian(F,[x,y])
</code></pre>
<p>Does that resolve the issue?</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32871#post-id-32871thanks for replying. i'd like to automate the solution process. i tried substituting x1 for diff(x(t),t), but got an error ( i don't want to manually type in the x1 and y1 part). i tried both:
sage: de1.substitute_function(diff(x(t),t),x1) and sage: de1.subs(diff(x(t),t)=x1)
any suggestions as to how i can sub x1 for diff(x(t),t) directly in de1?
thank you,Thu, 24 Mar 2016 02:27:30 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32871#post-id-32871Comment by calc314 for <p>I see what you want to do, but apparently solve will not work with two equations and two derivatives in this way. I think this must have something to do with how Maxima works or how Sage is passing info to Maxima.</p>
<p>Another option would be to use x1 and y1 in place of your derivatives and then solve, since you are really not using the fact that you have functions of t in this solving procedure.</p>
<pre><code>var('x y x1 y1')
de1 = x1 - y1 == x
de2 = y1 == y
sol = solve([de1,de2],[x1,y1])
sol
</code></pre>
<p>This gives:</p>
<pre><code>[[x1 == x + y, y1 == y]]
</code></pre>
<p>To find the Jacobian, you need the appropriate vector field. You can get this from the solution with the following</p>
<pre><code>F=map(lambda q: q.rhs(),sol[0])
</code></pre>
<p>Then, the Jacobian is:</p>
<pre><code>jacobian(F,[x,y])
</code></pre>
<p>Does that resolve the issue?</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32873#post-id-32873Since you originally stated that you were hunting for the Jacobian, I will update my post to include what you need to get that matrix.Thu, 24 Mar 2016 04:47:31 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32873#post-id-32873Comment by calc314 for <p>I see what you want to do, but apparently solve will not work with two equations and two derivatives in this way. I think this must have something to do with how Maxima works or how Sage is passing info to Maxima.</p>
<p>Another option would be to use x1 and y1 in place of your derivatives and then solve, since you are really not using the fact that you have functions of t in this solving procedure.</p>
<pre><code>var('x y x1 y1')
de1 = x1 - y1 == x
de2 = y1 == y
sol = solve([de1,de2],[x1,y1])
sol
</code></pre>
<p>This gives:</p>
<pre><code>[[x1 == x + y, y1 == y]]
</code></pre>
<p>To find the Jacobian, you need the appropriate vector field. You can get this from the solution with the following</p>
<pre><code>F=map(lambda q: q.rhs(),sol[0])
</code></pre>
<p>Then, the Jacobian is:</p>
<pre><code>jacobian(F,[x,y])
</code></pre>
<p>Does that resolve the issue?</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32874#post-id-32874The following worked for me: `de1.subs(diff(x(t),t)==x1,diff(y(t),t)==y1)`Thu, 24 Mar 2016 04:52:16 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32874#post-id-32874Comment by sophia for <p>I see what you want to do, but apparently solve will not work with two equations and two derivatives in this way. I think this must have something to do with how Maxima works or how Sage is passing info to Maxima.</p>
<p>Another option would be to use x1 and y1 in place of your derivatives and then solve, since you are really not using the fact that you have functions of t in this solving procedure.</p>
<pre><code>var('x y x1 y1')
de1 = x1 - y1 == x
de2 = y1 == y
sol = solve([de1,de2],[x1,y1])
sol
</code></pre>
<p>This gives:</p>
<pre><code>[[x1 == x + y, y1 == y]]
</code></pre>
<p>To find the Jacobian, you need the appropriate vector field. You can get this from the solution with the following</p>
<pre><code>F=map(lambda q: q.rhs(),sol[0])
</code></pre>
<p>Then, the Jacobian is:</p>
<pre><code>jacobian(F,[x,y])
</code></pre>
<p>Does that resolve the issue?</p>
https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32877#post-id-32877that helps me solve what i wanted to, thank you!
i had simplified the problem that i wanted to solve considerably. finding the Jacobian will require solving for the derivative of a functional w.r.t a function. Instead of crowding this post, i've asked a new question here:
http://ask.sagemath.org/question/32876/finding-the-derivative-of-a-functional-wrt-a-function/
thank you again for your help.Thu, 24 Mar 2016 07:51:23 +0100https://ask.sagemath.org/question/32859/solve-a-system-of-two-equations-for-a-derivative/?comment=32877#post-id-32877