Exemplo n.º 1
0
Arquivo: nmr.py Projeto: mwalde/davepy
def stats_for_i(i):
	from si_prefix import si
	from magnetics import air_coil_B_field as field
	brf = field(i, 50, 0.110)
	b1 = brf/2.0
	omega = spectral_window(b1)
	t_90 = t90(b1)
	t_180 = t180(b1)
	n = 10
	print 'brf:'.rjust(n), si(brf)
	print 'b1:'.rjust(n), si(b1)
	print 'omega:'.rjust(n), si(omega)
	print 't90:'.rjust(n), si(t_90)
	print 't180:'.rjust(n), si(t_180)
	
Exemplo n.º 2
0
def nmr_loop2(target, l, cdamp, cset, printno=15):
	'''
	Evaluate best capacitor combinations.
	
	target  = target resonant frequency.
	l       = coil inductance.
	cdamp   = capacitance of damping circuit in parallel with coil.
	          this will become part of ca and so need to be 
			  accounted for.
	cset    = list of tuples to evaluate of the form (ca, cb, cc).
	printno = number of combinations to print.
	'''
	from si_prefix import si
	results = []
	for c in cset:
		results = results + nmr_loop(target, l, c[0], c[1], c[2], cdamp)
	results.sort(key=lambda x: abs(x[-1]))
	for x in results[:printno]:
		print '{0}+{1}, {2}+{3}, {4}+{5} = {6}, {7} ({8}%)'.format(*[si(i) for i in x])
	return results
Exemplo n.º 3
0
def nmr_loop2(target, l, cdamp, cset, printno=15):
    '''
	Evaluate best capacitor combinations.
	
	target  = target resonant frequency.
	l       = coil inductance.
	cdamp   = capacitance of damping circuit in parallel with coil.
	          this will become part of ca and so need to be 
			  accounted for.
	cset    = list of tuples to evaluate of the form (ca, cb, cc).
	printno = number of combinations to print.
	'''
    from si_prefix import si
    results = []
    for c in cset:
        results = results + nmr_loop(target, l, c[0], c[1], c[2], cdamp)
    results.sort(key=lambda x: abs(x[-1]))
    for x in results[:printno]:
        print '{0}+{1}, {2}+{3}, {4}+{5} = {6}, {7} ({8}%)'.format(
            *[si(i) for i in x])
    return results
Exemplo n.º 4
0
def fr(f, l, d, t):
	'''
	Calculate Fr, the ratio of AC to DC
	resistance for a winding dure to skin 
	and proximity effects.
	
	f = frequency
	l = number of layers
	d = diameter of conductor
	t = temperature
	'''
	from math import pi, sqrt, sinh, sin, cosh, cos
	from si_prefix import si
	h = 0.886*d 								# height of equivalent rectangular conductor
	w = 2*pi*f 									# angular frequency
	a = h * sqrt(w*u0*0.5/resistivity_cu(t))
	mr = a*(sinh(2*a)+sin(2*a))/(cosh(2*a)-cos(2*a))
	dr = 2*a*(sinh(a)-sin(a))/(cosh(a)+cos(a))
	delta = sqrt(2*resistivity_cu(t)/(w*u0))	# skin depth
	print 'skin depth:', si(delta)+'m'
	fr = mr+(l**2-1)*dr/3						# Fr value
	return fr
Exemplo n.º 5
0
def fr(f, l, d, t):
    '''
	Calculate Fr, the ratio of AC to DC
	resistance for a winding dure to skin 
	and proximity effects.
	
	f = frequency
	l = number of layers
	d = diameter of conductor
	t = temperature
	'''
    from math import pi, sqrt, sinh, sin, cosh, cos
    from si_prefix import si
    h = 0.886 * d  # height of equivalent rectangular conductor
    w = 2 * pi * f  # angular frequency
    a = h * sqrt(w * u0 * 0.5 / resistivity_cu(t))
    mr = a * (sinh(2 * a) + sin(2 * a)) / (cosh(2 * a) - cos(2 * a))
    dr = 2 * a * (sinh(a) - sin(a)) / (cosh(a) + cos(a))
    delta = sqrt(2 * resistivity_cu(t) / (w * u0))  # skin depth
    print 'skin depth:', si(delta) + 'm'
    fr = mr + (l**2 - 1) * dr / 3  # Fr value
    return fr
Exemplo n.º 6
0
#                                                                                                                                                    cxxx.
#                                                                                                                                                    .ll:
#                                                                                                                                                    .ll:
#                                                                                                                                                    .ll:
#                                                                                                                                                    .ll:
#                                                                                                                                                    .ll:
#                                                                                                                                           .........,llc.........
#                                                                                                                                          .cccccccccclllccccccccc.
#                                                                                                                                           ......................
#                                                                                                                                               ',,,,,,,,,,,,'
#                                                                                                                                              .;;;;;;;;;;;;;;
#                                                                                                                                                   ......
#                                                                                                                                                  .cllllc
#                                                                                                                                                   ......
#
#

R1 = R3 = 1000  # ohm
R2 = R4 = R5 = 2000  # ohm
V1 = 3  # v
# a)
A = np.array([[R1 + R2, -R2, -R1], [-R2, R3 + R2 + R4, -R4],
              [-R1, -R4, R4 + R1 + R5]])
b = np.array([V1, 0, 0])
X = np.linalg.solve(A, b)
print("8.\na)\ni1 = {}A\ni2 = {}A\ni3 = {}A".format(si(X[0]), si(X[1]),
                                                    si(X[2])))
print("a potencia fornecida é de {}W".format(si(X[0] * V1)))

# b)
Exemplo n.º 7
0
# i1*R3/R3*R2 = i2

i3 = I1 * R3 / (R2 + R3)
v3 = V1 * R2R3 / Rreq
print("b) i3: {}A v3: {}V".format(si_format(i3), si_format(v3)))
print()

# c)

A = np.array([[1000, 2000, 0], [1, -1, -1], [0, -2000, -2000]])
b = np.array([1, 0, 0])
X = np.linalg.solve(A, b)
print(X)

print("solução do stor c) ir1: {}A ir2: {}A ir3: {}A".format(
    si(X[0]), si(X[1]), si(X[2])))
print("c)")
print(
    "como já sabemos i1 com a formula de ohm (V=I.R) sabemos que a corrente de R1 é {}A"
    .format(si_format(i1)))
print("pelo teorema de kirchhof:")
print("V_R1 = R1*V1/Rreq")
V_R1 = R1 * V1 / Rreq
print("V_R1: {}V".format(V_R1))
print()

# ou como deve ser feito pelo sistema de equalções

# d) Calcule a potência dissipada na resistência R1.
# P=I.V
print("P_R1: {}W".format(si_format(V_R1 * i1)))
Exemplo n.º 8
0
def print_comb(x):
	from si_prefix import si
	print 'ca=[{0}||{1}], cb=[{2}||{3}], cc=[{4}||{5}] = {6}, {7} ({8}%)'.format(*[si(i) for i in x])
Exemplo n.º 9
0
R1 = 4e3
R2 = 6e3
R3 = 1e4
R4 = 1e4
I1 = 5e-3
V1 = 5

# R2
#
A = np.array([
    #    i1  i2  i3            currentes/malhas
    [1, 0, 0],  #   I1
    [-R2, R1 + R2 + R3, -R3],  #   I2
    [-R4, -R3, R4 + R3]
])  #I3
b = np.array([I1, 0, -V1])  #voltagens
# como já sabemos o valor de i1/currente na
# malha I1 podemso meter uma resistemcia teorica
# de 1 para meter o valor de I1 no campo da voltagem

X = np.linalg.solve(A, b)
for i in range(X.size):
    print("i{} : {}A".format(i + 1, si(X[i])))

V_R2 = (X[0] - X[1]) * R2
V_R4 = (X[0] - X[2]) * R4
V_I1 = (V_R4 + V_R2)
P_I1 = V_I1 * I1
print("V_R2: {}V ; V_R4: {}V ;  V_I1:  {}V ; P_I1: {}W".format(
    si(V_R2), si(V_R4), si(V_I1), si(P_I1)))
Exemplo n.º 10
0
def format(v):
	from si_prefix import si
	return si(v, space=0).replace('M', 'meg')
Exemplo n.º 11
0
def format(v):
    from si_prefix import si
    return si(v, space=0).replace('M', 'meg')
Exemplo n.º 12
0
def _finder(target, function, series, n_min=2, n_max=2, quiet=False, symetric=True):
	'''
	Combines the values listed in series using the function defined 
	by function and rates them by how close the combined value is 
	to the target value.
	
	target = target value.
	function = function with which to combine values.
	series = series to search.
	[n_min] = minimum number of combined values.
	[m_max] = maximum number of combined values.
	[quiet] = enables of disables printing.
	[symetric] = enables or disables removal of equivalent input 
	             combination for symetric functions.
	'''
	from si_prefix import si
	
	# Wrap function to return function result and a comparason to target result.
	def _calc(*x):
		calc = function(*x)
		within = ((calc*100.0)/target)-100.0
		return (calc, within)
	
	# Print target value.
	if quiet == False:
		print 'TARGET = ', si(target)
	
	# Construct possible combinations of series.
	x = []		# combinations
	l = len(series)
	for n in range(n_min, n_max+1):
		for i in range(l**n):
			xi = []
			for j in range(n):
				xi.append((i/(l**j))%l)
				
				# If function inputs are symetric (can be aritrarily swapped) then 
				# the list of combinations can be minimised by not repeating equivalent 
				# combinations. For example if A,B = B,A.
				if (len(xi) > 1) & (symetric==True):
					if xi[-1] < xi[-2]:
						break
			else:
				x.append(tuple([series[xii] for xii in xi]))
	
	# Run all input combinations.
	results = [_calc(*xi) + xi for xi in x]
	
	# result of line above leaves the within variable in column 1 of each tuple.
	within_index = 1
	
	# Sort results by error from target.
	results.sort(key=lambda x: abs(x[within_index]))
	
	# Print top results.
	if quiet == False:
		for x in results[:min(15,len(results))]:
			print si(x[0]), '{0:.3f}% | '.format(x[1]).rjust(12),
			for y in x[2:]:
				print si(y),
			print ''
	
	# Return top results.
	return [x[2:] for x in results[:min(15,len(results))]]
Exemplo n.º 13
0
def _finder(target,
            function,
            series,
            n_min=2,
            n_max=2,
            quiet=False,
            symetric=True):
    '''
	Combines the values listed in series using the function defined 
	by function and rates them by how close the combined value is 
	to the target value.
	
	target = target value.
	function = function with which to combine values.
	series = series to search.
	[n_min] = minimum number of combined values.
	[m_max] = maximum number of combined values.
	[quiet] = enables of disables printing.
	[symetric] = enables or disables removal of equivalent input 
	             combination for symetric functions.
	'''
    from si_prefix import si

    # Wrap function to return function result and a comparason to target result.
    def _calc(*x):
        calc = function(*x)
        within = ((calc * 100.0) / target) - 100.0
        return (calc, within)

    # Print target value.
    if quiet == False:
        print 'TARGET = ', si(target)

    # Construct possible combinations of series.
    x = []  # combinations
    l = len(series)
    for n in range(n_min, n_max + 1):
        for i in range(l**n):
            xi = []
            for j in range(n):
                xi.append((i / (l**j)) % l)

                # If function inputs are symetric (can be aritrarily swapped) then
                # the list of combinations can be minimised by not repeating equivalent
                # combinations. For example if A,B = B,A.
                if (len(xi) > 1) & (symetric == True):
                    if xi[-1] < xi[-2]:
                        break
            else:
                x.append(tuple([series[xii] for xii in xi]))

    # Run all input combinations.
    results = [_calc(*xi) + xi for xi in x]

    # result of line above leaves the within variable in column 1 of each tuple.
    within_index = 1

    # Sort results by error from target.
    results.sort(key=lambda x: abs(x[within_index]))

    # Print top results.
    if quiet == False:
        for x in results[:min(15, len(results))]:
            print si(x[0]), '{0:.3f}% | '.format(x[1]).rjust(12),
            for y in x[2:]:
                print si(y),
            print ''

    # Return top results.
    return [x[2:] for x in results[:min(15, len(results))]]
Exemplo n.º 14
0
def print_comb(x):
    from si_prefix import si
    print 'ca=[{0}||{1}], cb=[{2}||{3}], cc=[{4}||{5}] = {6}, {7} ({8}%)'.format(
        *[si(i) for i in x])