z3 - How to use Z3Py online to solve problems with Operational Amplifiers -
find value of r in following circuit
this problem solved using following code:
r, v1, v2, vo = reals('r v1 v2 vo') i1 = v1/(r -50) i2 = v2/(r + 10) g = - r*(i1 + i2) print g equations = [vo == g] print equations problem = [vo == -2 , v1 == 1, v2 == 0.5, r != -10, r != 50, r > 0] solve(equations + problem)
and corresponding output is:
-r·(v1/(r - 50) + v2/(r + 10)) [vo = -r·(v1/(r - 50) + v2/(r + 10))] [r = 143.8986691902?, v2 = 1/2, v1 = 1, vo = -2]
other example: find value of r in following circuit
this problem solved using following code:
r, vs, ve, r1, r2 = reals('r vs ve r1 r2') g1 = (vs - ve)/r1 print g1 g2 = ve/r2 print g2 equations = [g1 == g2, r1 == 2*r - 100, r2 ==r] print equations problem = [vs == 35 , ve == 15, r > 0, r1 >0, r2 >0] solve(equations + problem)
and corresponding output is:
(vs - ve)/r1 ve/r2 [(vs - ve)/r1 = ve/r2, r1 = 2·r - 100, r2 = r] [r = 150, ve = 15, vs = 35, r2 = 150, r1 = 200]
other example:
this problem solved using following code:
rf, rg, vo, v1, v2, r1, r2, i1, i2, v = reals('rf rg vo v1 v2 r1 r2 i1 i2 v') equations = [v1 - v == r1*i1, v - vo == rf*i1, v2 - v == r2*i2, v == rg*i2] print equations problem = [v1 == 10 , v2 == 15, r1 == 100, r2 == 200, rf == 100, rg ==500] solve(equations + problem)
and corresponding output is
[v1 - v = r1·i1, v - vo = rf·i1, v2 - v = r2·i2, v = rg·i2] [i1 = -1/140, vo = 80/7, rg = 500, rf = 100, r2 = 200, r1 = 100, v2 = 15, v1 = 10, i2 = 3/140, v = 75/7]
other example:
code:
rf, rg, vo, v1, v2, r1, r2, i1, i2, v = reals('rf rg vo v1 v2 r1 r2 i1 i2 v') equations = [v1 - v == r1*i1, v - vo == rf*i1, v2 - v == r2*i2, v == rg*i2, rf == 200 + rg] print equations problem = [v1 == 10 , v2 == 15, r1 == 100, r2 == 200, vo == 20, rg > 0, rf >0 ] solve(equations + problem)
output:
[v1 - v = r1·i1, v - vo = rf·i1, v2 - v = r2·i2, v = rg·i2, rf = 200 + rg] [i1 = -0.0113999063?, rg = 577.2001872658?, vo = 20, r2 = 200, r1 = 100, v2 = 15, v1 = 10, i2 = 0.0193000468?, v = 11.1399906367?, rf = 777.2001872658?]
other example:
code:
vi, r1, i1, va, r2, i2, r4, r3, vo= reals('vi r1 i1 va r2 i2 r4 r3 vo') equations = [vi == r1*i1, -va == r2*i1, va == r4*i2, va - vo ==r3*(i1-i2)] print equations problem = [vi == 1, r1 == 1000, r2 == 1000, r3 == 1000, r4 == 10] solve(equations + problem)
output:
[vi = r1·i1, -va = r2·i1, va = r4·i2, va - vo = r3·(i1 - i2)] [r4 = 10, r3 = 1000, r2 = 1000, r1 = 1000, vi = 1, vo = -102, i2 = -1/10, va = -1, i1 = 1/1000]
other example:
code:
vi, r1, i1, va, r2, i2, r4, r3, vo= reals('vi r1 i1 va r2 i2 r4 r3 vo') equations = [vi == r1*i1, -va == r2*i1, va == r4*i2, va - vo ==r3*(i1-i2), r2 == r1 - 100, r3 == r1 - 200] print equations problem = [vi == 1, vo == -10, r4 == 10, r1 >0, r2 > 0, r3 >0] solve(equations + problem)
output:
[vi = r1·i1, -va = r2·i1, va = r4·i2, va - vo = r3·(i1 - i2), r2 = r1 - 100, r3 = r1 - 200] [i1 = 0.0030468970?, r1 = 328.2027496108?, i2 = -0.0695310291?, r4 = 10, vo = -10, vi = 1, r3 = 128.2027496108?, r2 = 228.2027496108?, va = -0.6953102918?]
other example:
code:
vi, v1, r, i1, v2, ri, i2, r1, vo, rf, a= reals('vi v1 r i1 v2 ri i2 r1 vo rf a') equations = [vi-v1 == r*i1,v1 -v2 == ri*i2, v2 == r1*i2, v1 - vo ==rf*(i1-i2), vo==a* (v2-v1)] print equations problem = [vi == 1, r1 == 2000, ri == 100, rf == 1000, r == 300, == 100] set_option(rational_to_decimal=true) solve(equations + problem)
output:
[vi - v1 = r·i1, v1 - v2 = ri·i2, v2 = r1·i2, v1 - vo = rf·(i1 - i2), vo = a·(v2 - v1)] [i2 = 0.0001658374?, = 100, r = 300, rf = 1000, ri = 100, r1 = 2000, vi = 1, vo = -1.6583747927?, i1 = 0.0021724709?, v1 = 0.3482587064?, v2 = 0.3316749585?]
other example:
code:
vi, v1, r, i1, v2, ri, i2, r1, vo, rf, a= reals('vi v1 r i1 v2 ri i2 r1 vo rf a') equations = [vi-v1 == r*i1,v1 -v2 == ri*i2, v2 == r1*i2, v1 - vo ==rf*(i1-i2), vo==a* (v2-v1), rf == r + 1000, ri == r + 500, r1 == r + 1500] print equations problem = [vi == 1, == 100, vo == -2, r >0, rf >0, r1 >0] set_option(rational_to_decimal=true) solve(equations + problem)
output:
[vi - v1 = r·i1, v1 - v2 = ri·i2, v2 = r1·i2, v1 - vo = rf·(i1 - i2), vo = a·(v2 - v1), rf = r + 1000, ri = r + 500, r1 = r + 1500] [i2 = 0.0000150298?, r = 830.6885937397?, i1 = 0.0011375745?, vo = -2, = 100, vi = 1, rf = 1830.6885937397?, v1 = 0.0550298124?, v2 = 0.0350298124?, r1 = 2330.6885937397?, ri = 1330.6885937397?]
other example:
what value of resistance rb provide balance of bridge yielding vo = 0
code:
v, rc, rd, i1, vb, ra,rb, i2, va, v2, r1, i3, r2, v1, r3, r4, i4, vo = reals('v rc rd i1 vb ra rb i2 va v2 r1 i3 r2 v1 r3 r4 i4 vo') equations = [v == (rc+rd)*i1, vb == rd*i1, v == (ra + rb)*i2, va == rb*i2, vb-v2 == r1*i3, v2 == r2*i3, va-v1 == r3*i4, v1 - vo == r4*i4, v2 == v1, rd == rb + 10] print equations problem = [vo == 0, v == 5, r1 == 10, r2 == 12, r3 == 10, r4 == 22, ra ==1, rc ==1, rb >0, rd >0] set_option(rational_to_decimal=true) solve(equations + problem)
output:
[v = (rc + rd)·i1, vb = rd·i1, v = (ra + rb)·i2, va = rb·i2, vb - v2 = r1·i3, v2 = r2·i3, va - v1 = r3·i4, v1 - vo = r4·i4, v2 = v1, rd = rb + 10] [i1 = 0.3626991607?, rb = 2.7855295545?, i2 = 1.3208191688?, i4 = 0.1149744009?, i3 = 0.2107864017?, rc = 1, ra = 1, r4 = 22, r3 = 10, r2 = 12, r1 = 10, v = 5, vo = 0, v1 = 2.5294368214?, v2 = 2.5294368214?, va = 3.6791808311?, vb = 4.6373008392?, rd = 12.7855295545?]
please let me know think , if know more efficient code these kind of problems. many thanks.
Comments
Post a Comment