Exemple #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")
Exemple #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')