# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
import math

data = pd.read_csv("q2.csv", names=["e", "U", "I"])

sigma_e = 1
sigma_U = 0.02
sigma_I = 1
data["N"] = round(data["U"] * data["I"] / 1000, 4)
data["R"] = round((data["N"] * 1000000) / (data["I"]**2), 2)
sigma_N = data["N"].mean() * math.sqrt((sigma_I / data["I"].mean())**2 + (sigma_U / data["U"].mean())**2)
X = data["N"].values
sigma_X = sigma_N
data["T"] = round(data["e"] / 40.7, 3)
Y = data["T"].values
sigma_Y = sigma_e / 40.7

A = np.vstack([X, np.ones(len(X))]).T
k, b = np.linalg.lstsq(A, Y, rcond=None)[0]
sigma_k = math.sqrt((Y.std() - Y.mean()**2 ) / (X.std() - X.mean()**2 ) - b**2 ) / math.sqrt(len(X))
eps_k = sigma_k / k
#sigma_b = sigma_k * math.sqrt(X.std() / X.mean() - X.mean()**2 )

fig = plt.figure(figsize=(12, 7))
ax = fig.gca()
plt.scatter(X, Y, marker=".")
plt.errorbar(X, Y, xerr=sigma_X, yerr=sigma_Y, linestyle="None")
delta_x = (X.max() - X.min()) / len(X)
delta_y = (Y.max() - Y.min()) / len(Y)
ax.set_xlim(X.min() - delta_x/2, X.max() + delta_x/2)
ax.set_ylim((Y.min() - delta_y/2), Y.max() + delta_y/2)
plt.xlabel("$N, W$")
plt.ylabel("$\Delta T, K$")
plt.plot(X, (k*X + b), 'r', label='Fitted line')
plt.grid(True)
plt.savefig("q2.png")

eps_k

b

data



StarcoderdataJupyterScriptsDedupFiltered