Пример #1
0
def rc_data(a, b, filename, f, title, figname):
    fw, tw = import_matlab(filename)
    plt.plot(tw[:, a:b], fw[:, a:b], "o", color="blue")
    plt.close()

    t_err = np.transpose(tw[:, 1]) - np.transpose(tw[:, 0])

    v = FYS2150lib.vel(fw, f)

    dm, dc, c, m = FYS2150lib.linfit(tw[:, a:b], v[:, a:b])
    v_fit = m*tw[:, a:b] + c

    plt.plot(tw[:, a:b], v[:, a:b], "x", color="red", label="Data Points")
    plt.errorbar(np.transpose(tw[:, a:b]), np.transpose(v_fit), yerr=dm, color="blue", fmt='o', label="Error Range")
    plt.plot(np.transpose(tw[:, a:b]), np.transpose(v_fit), linestyle="-", color="black", label="Linear Fit")

    handles, labels = plt.gca().get_legend_handles_labels()
    by_label = OrderedDict(zip(labels, handles))
    plt.legend(by_label.values(), by_label.keys())

    plt.ylabel("Velocity $[ms^{-1}]$")
    plt.xlabel("Time [s]")
    plt.title("%s \n a=%.2f, $\delta a$ =%.2f$ms^{-1}$" % (title, m, dm))
    plt.savefig("figs/%s.png"%figname)
    plt.close()
Пример #2
0
def histogram1():
    sig = FYS2150lib.stddev(pendel_period)[0]
    sig_m = FYS2150lib.stddev(pendel_period)[1]
    mean = np.mean(pendel_period)
    plt.hist(pendel_period, bins=10, rwidth=1, color="blue")
    plt.xlabel("T [s]")
    plt.ylabel("N")
    plt.title("Measurements of Period of Foucault's Pendulum\n$T_{mean}$=%.2fs, $\sigma=$%.2f,$\sigma_m=$%.2f"%(mean, sig, sig_m))
    plt.axvline(mean, linestyle="--", color="red")
    plt.savefig("figs/period.png")
    plt.close()
Пример #3
0
def ex_4():
    # Ex 4
    Fg = []
    vt_2 = []
    vt_3 = []
    vt_4= []
    file = open('terminal_hastighet.dat', 'r')
    for line in file:
        cols = line.split()
        Fg.append( float(cols[0]) )
        vt_2.append( float(cols[1]) )
        vt_3.append( float(cols[2]) )
        vt_4.append( float(cols[3]) )
    file.close()

    plt.plot(Fg, vt_2, label="vt_2")
    plt.plot(Fg, vt_3, label="vt_3")
    plt.plot(Fg, vt_4, label="vt_4")
    plt.legend()
    plt.show()

    v_fd = vt_3 / np.sqrt(Fg)
    v_fd_std = fy.stddev(v_fd)
    v_fd_mean = np.mean(v_fd)
    print v_fd_std
    print v_fd_mean
Пример #4
0
def ex2():

    angles_rad = np.deg2rad(angles)
    plt.figure(figsize=(3.5, 3.5), dpi=100)

    lux3err = np.sqrt((0.05 * np.copy(lux3) + 2)**2 +
                      (0.05 * np.copy(lux3[-1]) + 2)**2)

    # plt.plot(np.cos(angles_rad) ** 2, lux2 -
    #         lux2[-1], "x", label="Measured Data")
    x = np.linspace(np.cos(angles_rad[0])**2, np.cos(angles_rad[-1])**2, 1e3)
    m, c, dm, dc = fys.linfit(np.cos(angles_rad)**2, lux2 - lux2[-1])
    plt.plot(x, m * x + c, label="Linear fit")

    plt.errorbar(np.cos(angles_rad)**2, lux2 - lux2[-1], yerr=lux3err, fmt='x')
    plt.text(0.5, 20, r'$\delta m = %.2e$' % (dm), fontsize=10)
    plt.text(0.5, 10, r'$\delta c = %.2e$' % (dc), fontsize=10)

    plt.title(
        "Intensity of polarized light\n passed through analyzer for\n different angles $\\theta$"
    )
    plt.xlabel("$\cos^2 \\theta$")
    plt.ylabel("$E(\\theta) - E(\\theta=90^\circ)$ [Lux]")
    plt.legend(loc="best")
    plt.tight_layout()
    plt.savefig("malus1.png", dpi=150)
    plt.show()

    return
Пример #5
0
def ex8():
    col1 = []
    col2 = []
    file = open('diameter.dat', 'r')
    for line in file:
        cols = line.split()
        col1.append(float(cols[0]))
        col2.append(float(cols[1]))
    file.close()

    U = np.array(col1)
    D = np.array(col2)
    lambd_C = const.physical_constants["Compton wavelength"][0]

    lambd = lambd_C * np.sqrt(const.m_e * const.c**2 /
                              (2 * const.e * U)) * f(U)

    phi_bar = 1.0 / len(lambd) * np.sum(lambd / D)
    print phi_bar
    print fys.stddev(lambd / D)
Пример #6
0
def plot_stddev():
    """Plots the standard deviation of h(m)
    as m is increased"""
    deviation = np.zeros(len(h_1))
    for i in xrange(len(h_1)):
        deviation[i] = fys.stddev(
            array([h_1[i], h_2[i], h_3[i], h_4[i], h_5[i]]))[0]
    plot(mass_dat, deviation, linestyle="--")
    plot(mass_dat, deviation, "o")
    ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
    title("Standard deviation of deflection for each m\n")
    xlabel("Load [kg]")
    ylabel("$\sigma$ (Std. dev.)")
    savefig("figs/h_m_deviation.png")
    close()
Пример #7
0
def rc_vel(a, b, filename, f, title, figname):
    fw, tw = import_matlab(filename)
    plt.plot(tw[:, a:b], fw[:, a:b], "o", color="blue")
    plt.close()

    v = FYS2150lib.vel(fw, f)
    v_abs = np.sqrt(v**2)
    plt.plot(tw[:, a:b], v_abs[:, a:b], "x", color="red")
    plt.ylabel("|v| $[ms^{-1}]$")
    plt.xlabel("Time [s]")
    plt.ylim(0, 4)
    plt.xlim(0, 7)
    plt.title("%s" % (title))
    plt.savefig("figs/%s.png"%figname)
    plt.close()
Пример #8
0
def weight_data(set=1):
    "set decides which data set the function returns."
    set = set.lower()  # Forces lowercase
    sets = ["masses", "rod"]
    # Mass of weights measured with balance
    m_a_balance = 500.1e-3
    m_b_balance = 1000.3e-3
    m_c_balance = 2000.5e-3

    # Mass of reference weights
    m_reference = array([0.5, 1.0, 2.0])
    m_reference_balance = array([500.0e-3, 999.9e-3, 2000.1e-3])  # Weighed

    # Using linear fit to correct for error in balance
    a, b, da, db = fys.linfit(m_reference, m_reference_balance)
    # Corrected masses
    m_a = (m_a_balance - b) / a  # approx 500g
    m_b = (m_b_balance - b) / a  # approx 1000g
    m_c = (m_c_balance - b) / a  # approx 2000g

    # print "\nref weight \n", (m_reference_balance - b) / a
    # print "\ncalibrated rough", m_a, m_b, m_c
    # print "error rough", da
    # print

    m_rod_ring = np.array([2482.7, 2482.5, 2482.1]) * 1e-3
    m_ring = 34.4 * 1e-3  # kg
    m_rod_ring_c = (mean(m_rod_ring) - b) / a  # kg
    m_ring_c = (m_ring - b) / a  # kg
    m_rod_c = m_rod_ring_c - m_ring_c

    # print mean(m_rod_ring)
    # print "\ncalibrated rod", m_rod_c
    # print "mass rod error", np.sqrt(2 * da**2)
    # print

    if set == sets[0]:  # Return corrected masses
        return m_a, m_b, m_c

    if set == sets[1]:
        return m_rod_c

    if set not in sets:
        print "Invalid set"
        print "List of valid sets:", sets
        print "exiting..."
        exit()
Пример #9
0
tellinger = np.array([
    6, 2, 3, 2, 2, 2, 5, 5, 3, 4, 3, 5, 4, 7, 4, 2, 3, 2, 2, 4, 6, 2, 3, 2, 6,
    3, 7, 10, 6, 4, 2, 4, 6, 0, 3, 5, 3, 1, 5, 4, 9, 5, 7, 1, 5, 1, 6, 4, 4, 0,
    3, 4, 4, 2, 5, 3, 2, 4, 2, 3, 1, 6, 3, 4, 3, 2, 2, 7, 2, 2, 2, 2, 5, 2, 3,
    1, 0, 6, 3, 6, 1, 2, 3, 6, 1, 2, 3, 6, 4, 4, 4, 3, 5, 0, 2, 2, 3, 3, 7, 3,
    8, 3
])

# MERK Tellinger 1 var notert ned feil. Tellinger er basert paa daniels journal.
# Dobbelt sjekk at verdiene stemmer.

print len(tellinger)

mean = np.mean(tellinger)
print "mean:", mean
print "\nstd dev.:", FYS2150lib.stddev(tellinger)
print "\nsqrt mean:", np.sqrt(mean)


def theoretical_poisson(N, m, k):
    y = np.zeros(k)
    y[0] = N * np.exp(-m)
    for i in range(1, k):
        y[i] = (m / (i)) * y[i - 1]
    return y


print theoretical_poisson(100, mean, 11)

plt.hist(tellinger, label="Measured", bins=10)
plt.plot(theoretical_poisson(101, mean, 10), label="Predicted")
Пример #10
0
        validFrames = np.array(validFrames)

        print "Find start/stop of terminal velocity (straight, steep line) to perform linfit:"
        plt.subplot(211)
        plt.plot(validFrames, x)
        plt.xlabel("Frame")
        plt.ylabel("x-position of center of mass [px]")
        plt.title("Use to determine start/stop frame of linfit")
        plt.subplot(212)
        plt.plot(np.diff(x))
        plt.show()

        start = int(input("Start index:"))
        stop = int(input("Stop index:"))

        m, c, dm, dc = fys.linfit(validFrames[start:stop], x[start:stop])

        plt.subplot(211)
        plt.plot(validFrames, x, ".", label="Position of CM")
        plt.plot(validFrames[start:stop],
                 validFrames[start:stop] * m + c,
                 label="linear fit, y=mx+c")
        plt.text(0, 1000,
                 "m = %.2f [px/frame]\n dm = %.2f [px/frame]" % (m, dm))
        plt.xlabel("Frame")
        plt.ylabel("x-pos [px]")
        plt.legend()
        plt.subplot(212)
        plt.plot(validFrames, y, ".", label="Position of CM")
        plt.xlabel("Frame")
        plt.ylabel("y-pos  [px]")
Пример #11
0
print np.std(dat)
print np.mean(dat)


skjerming = np.array([
				0, 4.0, 8.0, 12.0, 16.0, 20.0, 24.0
				]) * 1e-3

n = np.array([
			13.7, 12.4, 11.0, 9.7, 8.9, 7.9, 7.1
			])

mu = (np.log(n[0]) - np.log(n)) / skjerming

dm, dc, c, m = FYS2150lib.linfit(skjerming, np.log(n))
print "\nex5:"
print m, dm
print c, dc

print "\nex 4:"

r = 2e-2
d = 20e-2
A = 10e6
nr = 23
nb = 2

omega = r**2 * np.pi / d**2
omega_red = omega / (np.pi * 4.0)
Пример #12
0
    d = diameter of rod
    M = mass of rod
    '''
    return (16.0 * M * L * f**2) / (np.pi * d**2)


def E_sound_error(E, sd, sf, sL, sM, d, f, L, M):
    return E * np.sqrt((2 * sd / d)**2 + (2 * sf / f)**2 + (2 * sL / L)**2 +
                       (2 * sM / M)**2)


d = np.array([
    15.98, 15.99, 15.99, 16.00, 15.99, 15.99, 15.98, 15.99, 15.99, 15.99
]) * 1e-3
d_mean = np.mean(d)
d_err = fys.stddev(d)[1]  # Std dev of mean

hist(d)
ticklabel_format(style='sci', axis='x', scilimits=(0, 0))
xlabel("thickness [m]")
ylabel("No. occurrences")
xticks(rotation=20)
title("Measured thickness of rod\nmean thickness=%.3em, $\sigma_m=$%.3e" %
      (d_mean, d_err))
savefig("figs/thickdat.png")
close()

f_root = 1213.72
#f_root = 1240
f_err = 0.04  # resolution of FFT
M_err = 9.8974331835e-05  # from linfit above (da)
Пример #13
0
def errors_len():
    print
    print "Ruler data:"
    print "mean l_a", np.mean(L_a_hultafors)
    print "std l_a", FYS2150lib.stddev(L_a_hultafors)[0]
    print "std mean l_a", FYS2150lib.stddev(L_a_hultafors)[1]

    print "mean l_b", np.mean(L_b_hultafors)
    print "std l_b", FYS2150lib.stddev(L_b_hultafors)[0]
    print "std mean l_b", FYS2150lib.stddev(L_b_hultafors)[1]
    diff_hultfors = abs(L_a_hultafors - L_b_hultafors)
    print "mean diff", np.mean(diff_hultfors)
    print "std diff", FYS2150lib.stddev(diff_hultfors)[0]
    print "std mean diff", FYS2150lib.stddev(diff_hultfors)[1]

    print "\n -----------\n"
    print "Laser data:"
    print "mean l_a", np.mean(L_a_laser)
    print "std l_a", FYS2150lib.stddev(L_a_laser)[0]
    print "std mean l_a", FYS2150lib.stddev(L_a_laser)[1]

    print "mean l_b", np.mean(L_b_laser)
    print "std l_b", FYS2150lib.stddev(L_b_laser)[0]
    print "std mean l_b", FYS2150lib.stddev(L_b_laser)[1]
    diff_laser = abs(L_a_laser - L_b_laser)
    print "mean diff", np.mean(diff_laser)
    print "std diff", FYS2150lib.stddev(diff_laser)[0]
    print "std mean diff", FYS2150lib.stddev(diff_laser)[1]
Пример #14
0
    print "std l_a", FYS2150lib.stddev(L_a_hultafors)[0]
    print "std mean l_a", FYS2150lib.stddev(L_a_hultafors)[1]

    print "mean l_b", np.mean(L_b_hultafors)
    print "std l_b", FYS2150lib.stddev(L_b_hultafors)[0]
    print "std mean l_b", FYS2150lib.stddev(L_b_hultafors)[1]
    diff_hultfors = abs(L_a_hultafors - L_b_hultafors)
    print "mean diff", np.mean(diff_hultfors)
    print "std diff", FYS2150lib.stddev(diff_hultfors)[0]
    print "std mean diff", FYS2150lib.stddev(diff_hultfors)[1]

    print "\n -----------\n"
    print "Laser data:"
    print "mean l_a", np.mean(L_a_laser)
    print "std l_a", FYS2150lib.stddev(L_a_laser)[0]
    print "std mean l_a", FYS2150lib.stddev(L_a_laser)[1]

    print "mean l_b", np.mean(L_b_laser)
    print "std l_b", FYS2150lib.stddev(L_b_laser)[0]
    print "std mean l_b", FYS2150lib.stddev(L_b_laser)[1]
    diff_laser = abs(L_a_laser - L_b_laser)
    print "mean diff", np.mean(diff_laser)
    print "std diff", FYS2150lib.stddev(diff_laser)[0]
    print "std mean diff", FYS2150lib.stddev(diff_laser)[1]
errors_len()

print FYS2150lib.stddev(np.array([2.29, 2.29, 1.99]))

print "\nVernier:"
print "mean:", np.mean(L_ab_direct*1e-1)
print "sigma, sigma_m", FYS2150lib.stddev(L_ab_direct*1e-1)