Exemplo n.º 1
0
class TestEvaluatePoints(TestCase):

    def setUp(self):
        self.deg = 3
        self.x = linspace(0, 5, 100)
        self.f = lambda t: t**2
        with open('testPoints.txt', 'w') as f:
            for i in range(100):
                f.write('%g \t %g \n' % (self.x[i], self.f(self.x[i])))

    def test_construction(self):
        self.EP = EvaluatePoints('testPoints.txt')
        self.assertEqual(self.EP.n, 100)

    def test_interpolation(self):
        self.EP = EvaluatePoints('testPoints.txt')
        self.EP.storeValues()
        self.EP.interpolate(2, 2)
        self.assertAlmostEqual(polyval(self.EP.poly, 0), self.f(0), places=5)
        self.assertAlmostEqual(polyval(self.EP.poly, 2), self.f(2), places=5)
    
    def test_plotPoints(self):
        self.EP = EvaluatePoints('testPoints.txt')
        self.EP.storeValues()
        self.EP.interpolate(2, 2)
        self.EP.plotPoints("TEST")
Exemplo n.º 2
0
# coding: utf-8
from PRELABOppgave1 import EvaluatePoints
from numpy import pi, sqrt, zeros

my_0 = (4*pi)*10**(-7) # vakuum permeabiliteten.
a = 0.02 # radius i meter.
t = 0.035 # høgde i meter.
I = 0.1 # Ampere, denne må kunne endrast.
A = pi*a**2 # Areal over sida til magneten i kvadratmeter.
V = pi*a**2*t # Volumet til sylinderen i kubikkmeter.
j = I*A/float(V) # Straumtetthet i Ampere per meter.
Bx = lambda h: my_0/2.0*j*((h + t)/sqrt((h + t)**2 + a**2) - h/sqrt(h**2 + a**2))

h = zeros(6) # Evalueringspunkter.
evaluated = zeros(6) # Verdi av Bx i h.
for i in range(6):
    h[i] = i
    evaluated[i] = Bx(h[i])

with open('Oppgave3.txt', 'w') as f:
    for i in range(6):
        f.write('%g \t %g \n' % (h[i], evaluated[i]))

EP = EvaluatePoints('Oppgave3.txt')
EP.storeValues()
EP.interpolate(2, 1)
EP.plotPoints('Test av PRELAB-kode')
Exemplo n.º 3
0
with open('Oppgave3.2table.txt', 'w') as f:
    for i in range(R.size):
        f.write("%g & %g \\\\ \n" % (R[i], V[i]))

I_formula = lambda v, r: v/float(r)

I = []

for i in range(R.size):
    I.append(I_formula(V[i], R[i]))

I = array(I)

dI = I[-1] - I[0]
dV = V[-1] - V[0]
R_i = -dV/float(dI)

with open('datapoints.txt', 'w') as f:
    for i in range(R.size):
        f.write("%g \t %g\n" % (I[i], V[i]))

EP = EvaluatePoints('datapoints.txt')
EP.storeValues()
EP.interpolate(2, 0)
EP.plotPoints("Inner resistance of Peltier-element", "InnerRP.png", "I [A]", "V [V]")

ems = V[3] + R_i * I[3]
with open('InnerRP.txt', 'w') as f:
    f.write("EMS of Peltier-element: %g V\\\\" % ems)
    f.write("Inner resistance of Peltier-element: %g ohm" % R_i)
Exemplo n.º 4
0
import os, sys
sys.path.append(os.path.abspath('../../Hall-effekt/src/'))
from PRELABOppgave1 import EvaluatePoints
from numpy import exp, log, array
from matplotlib.pylab import plot, show, xlabel, ylabel, title, savefig

U_list = array([8.9110, 7.0, 5.5, 4.35, 3.44, 2.70, 2.1, 1.65, 1.32, 1.05,\
                0.81, 0.65, 0.515, 0.410, 0.324, 0.256, 0.204, 0.161, 0.128])
t_list = array([0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220,\
                240, 260, 280, 300, 320, 340, 360])

with open('datapointsIRV.txt', 'w') as f:
    for i in range(U_list.size):
        f.write("%g \t %g\n" % (t_list[i], log(U_list[i])))

tau = -1.0/((log(U_list[-1]) - log(U_list[0]))/float(t_list[-1] - t_list[0]))

with open("InnerRV.txt", 'w') as f:
    f.write("Tau is equal to: %g s\\\\ \n" % tau)
    f.write("Inner resistance: %g ohm" % (tau/float(8.3e-6)))

EP = EvaluatePoints('datapointsIRV.txt')
EP.storeValues()
EP.interpolate(2, 0)
EP.plotPoints("Inner resistance of Voltmeter.", "InnerRV.png", "t [s]", "V [V]")
Exemplo n.º 5
0
import sys, os
sys.path.append(os.path.abspath('../../Hall-effekt/src/'))
from PRELABOppgave1 import EvaluatePoints
from numpy import array
from matplotlib.pylab import plot, show, xlabel, ylabel, title, savefig

R = array([500, 700, 1000, 1200, 1500]) # Ohm
I = array([17.28, 12.45, 8.77, 7.33, 5.88])*10**(-3) # A
V = array([200.61, 144.56, 101.84, 85.07, 68.224])*10**(-3) # V

with open('Oppgave2.1table.txt', 'w') as f:
    for i in range(R.size):
        f.write("%g & %g & %g \\\\ \n" % (R[i], I[i], V[i]))

with open('Oppgave2.1datapoints.txt', 'w') as f:
    for i in range(R.size):
        f.write("%g \t %g \n" % (I[i], V[i]))

EP = EvaluatePoints('Oppgave2.1datapoints.txt')
EP.storeValues()
EP.interpolate(2, 0)
EP.plotPoints("Inner resistance of an Amperemeter", "InnerRA.png", "I [A]", "V [V]")

dI = I[-1] - I[0]
dV = V[-1] - V[0]
R = dV/float(dI)

with open('InnerRA.txt', 'w') as f:
    f.write("Inner resistance of amperemeter: %g ohm" % R)