コード例 #1
0
ファイル: testEvaluatePoints.py プロジェクト: moncar/FYS1120
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")
コード例 #2
0
ファイル: PRELABOppgave3.py プロジェクト: moncar/FYS1120
# 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')
コード例 #3
0
ファイル: Oppgave3.2.py プロジェクト: moncar/FYS1120
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)