# 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.

edit retag close merge delete

Sort by » oldest newest most voted

You 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).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!

more

Thanks 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>)