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, 08 Jan 2015 22:32:13 +0100Solving simultaneous equationshttps://ask.sagemath.org/question/25442/solving-simultaneous-equations/ I am new to Sagemath and I am trying to figure out how to solve two equations representing a circuit composed of a diode and a resistor. Here's what I entered into Sage :
id, vd = var('id vd')
eq1 = id == 10*10^(-12) * (e^(vd/0.039)-1)
eq2 = id == (10/500) - (vd/500)
solve([eq1,eq2],id,vd)
However, this evaluates to :
[id == -1/500*vd + 1/50, id == 1/100000000000*e^(25.64102564102564*vd) -1/100000000000]
What I would like to get is the numerical values of both id and vd (respectively the current and voltage drop across the diode), i.e. approximately 18mA and 0,8V. This simple circuit was taken from "Electronic Devices and Circuit Theory' and was originally solved using Mathcad, but I can't figure out how to do this in Sagemath.
Thanks for the help.Thu, 08 Jan 2015 21:23:12 +0100https://ask.sagemath.org/question/25442/solving-simultaneous-equations/Answer by kcrisman for <p>I am new to Sagemath and I am trying to figure out how to solve two equations representing a circuit composed of a diode and a resistor. Here's what I entered into Sage :</p>
<pre><code>id, vd = var('id vd')
eq1 = id == 10*10^(-12) * (e^(vd/0.039)-1)
eq2 = id == (10/500) - (vd/500)
solve([eq1,eq2],id,vd)
</code></pre>
<p>However, this evaluates to :</p>
<pre><code>[id == -1/500*vd + 1/50, id == 1/100000000000*e^(25.64102564102564*vd) -1/100000000000]
</code></pre>
<p>What I would like to get is the numerical values of both id and vd (respectively the current and voltage drop across the diode), i.e. approximately 18mA and 0,8V. This simple circuit was taken from "Electronic Devices and Circuit Theory' and was originally solved using Mathcad, but I can't figure out how to do this in Sagemath.</p>
<p>Thanks for the help.</p>
https://ask.sagemath.org/question/25442/solving-simultaneous-equations/?answer=25443#post-id-25443You are looking for a numerical solution; `solve` wants to give you exact solutions, and cannot solve this system - even doing it "by hand" gives
sage: solve(eq1.subs(vd=solve(eq2,vd)[0].rhs()),id)
[id == 1/100000000000*e^(-500000/39*id + 10000/39) - 1/100000000000]
To find a root between two endpoints, use something like
sage: find_root(id == 1/100000000000*e^(-500000/39*id + 10000/39) - 1/100000000000,0,10)
0.01833629407646303
Good luck!Thu, 08 Jan 2015 21:59:07 +0100https://ask.sagemath.org/question/25442/solving-simultaneous-equations/?answer=25443#post-id-25443Comment by samric for <p>You are looking for a numerical solution; <code>solve</code> wants to give you exact solutions, and cannot solve this system - even doing it "by hand" gives</p>
<pre><code>sage: solve(eq1.subs(vd=solve(eq2,vd)[0].rhs()),id)
[id == 1/100000000000*e^(-500000/39*id + 10000/39) - 1/100000000000]
</code></pre>
<p>To find a root between two endpoints, use something like</p>
<pre><code>sage: find_root(id == 1/100000000000*e^(-500000/39*id + 10000/39) - 1/100000000000,0,10)
0.01833629407646303
</code></pre>
<p>Good luck!</p>
https://ask.sagemath.org/question/25442/solving-simultaneous-equations/?comment=25444#post-id-25444Thanks for the help. Now let's suppose I had i equations (i > 2) and I wanted to get the numerical solutions for their i variables, would it be possible to do it without having to substitute those variable individually into the i equations?
To put it another way, is there a quick and easy way to get sage to resolve numerically a set of equation the way Mathcad would do it, i.e. :
Given
<set of equation>
....
Find(<variable numerical values>)Thu, 08 Jan 2015 22:32:13 +0100https://ask.sagemath.org/question/25442/solving-simultaneous-equations/?comment=25444#post-id-25444