``````

In [54]:

import numpy as np
import matplotlib.pyplot as plt
import uncertainties as unt
import uncertainties.unumpy as unp

#constantes e temperatura
k = 1.38e-23
e = 1.6e-19
t = 298
#caracteristicas do led
led_cov = [[0.137718, -0.000218895, 52367800000000],
[-0.000218895, 9.65134E-7, -261883000000],
[52367800000000, -261883000000, 7.22381E+28]]

(p0, p1, p2) = unt.correlated_values([13.0666, 0.0991019, 1.01277e15], led_cov)

rl = p0
n = p1 * e / (k * t)
n = unt.ufloat(n.n, np.sqrt(9.65134E-7) * e / (k * t))
i0 = 1 / p2

#resistencias do circuito
r1 = unt.ufloat(99.8, 0.29288)
r2 = unt.ufloat(46.7, 0.14270)

#resistencia interna da pilha
pil_cov = [[7.89941E-7, 7.16902E-6], [7.16902E-6, 0.000135634]]

(up, rp) = unt.correlated_values([1.37634, 0.866158], pil_cov)

``````
``````

In [55]:

p0

``````
``````

Out[55]:

13.0666+/-0.3711037590755448

``````
``````

In [56]:

def bisection(a,b,tol,f,*args):
c = (a+b)/2.0
while (b-a)/2.0 > tol:
if f(c,*args) == 0:
return c11
elif f(a,*args)*f(c,*args) < 0:
b = c
else :
a = c
c = (a+b)/2.0
return unt.ufloat(c, tol / unp.sqrt(24))

``````
``````

In [57]:

def Uled1(i):
return rl * i + (n*k*t/e) * unp.log(i / i0 + 1)

def Uled1root(i, u):
return (rl) * i + (n*k*t/e) * unp.log(i / i0 + 1) - u

def Iled1(u):
return bisection(0, 3, 1e-15, Uled2root, u)

def Uled2(i):
return (rl+r2) * i + (n*k*t/e) * unp.log(i / i0 + 1)

def Uled2root(i, u):
return (rl+r2) * i + (n*k*t/e) * unp.log(i / i0 + 1) - u

def Iled2(u):
return bisection(0, 3, 1e-15, Uled1root, u)

def func(u):
return (r1+2*rp)*(Iled1(u)+Iled2(u))-2*up+u

``````
``````

In [58]:

res = bisection(2.3, 2.7, 1e-10, func)

``````
``````

In [59]:

i1 = Iled1(res)
i2 = Iled2(res)
i = i1+i2
vr = r1 * i
vl = res
vp = 2 * rp * i
v = vl + vr + vp
print("V: %s" % v)
print("Vp: %s" % (v-vp))
print("Vr: %s" % vr)
print("Vl: %s" % vl)
print("i: %s" % i)
print("i1: %s" % i1)
print("i2: %s" % i2)

``````
``````

V: 2.75268+/-0.00025
Vp: 2.75123+/-0.00025
Vr: 0.08372+/-0.00025
Vl: 2.667510478478+/-0.000000000020
i: 0.00083884151316971+/-0.00000000000000029
i1: 0.00038358357487334+/-0.00000000000000020
i2: 0.00045525793829637+/-0.00000000000000020

``````
``````

In [42]:

um1 = unt.ufloat(2.761, 0.007)
um2 = unt.ufloat(2.58, 0.021)

(up, rp) = unt.correlated_values([1.37634, 0.866158], pil_cov)
(up, rp) = unt.correlated_values([um2.n/2, 0.866158], pil_cov)

``````
``````

In [60]:

up*2

``````
``````

Out[60]:

2.75268+/-0.0017775725020375398

``````
``````

In [53]:

Uled2(i2)

``````
``````

Out[53]:

2.5579996782638768+/-0.036494036573066824

``````
``````

In [ ]:

``````