From 54ca67bc4b75fe2ad6d2f68aa4eff61f781d2af8 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 1 Nov 2021 16:18:06 -0400 Subject: updates for math and physics homeworks --- jarrio/week09.bc | 161 ++++++++++++++++++++++++++++++ jarrio/week10.bc | 245 ++++++++++++++++++++++++++++++++++++++++++++++ jarrio/week10resistors.py | 66 +++++++++++++ jarrio/week9practice.bc | 162 ------------------------------ 4 files changed, 472 insertions(+), 162 deletions(-) create mode 100644 jarrio/week09.bc create mode 100644 jarrio/week10.bc create mode 100644 jarrio/week10resistors.py delete mode 100644 jarrio/week9practice.bc (limited to 'jarrio') diff --git a/jarrio/week09.bc b/jarrio/week09.bc new file mode 100644 index 0000000..b0357f8 --- /dev/null +++ b/jarrio/week09.bc @@ -0,0 +1,161 @@ +print "Weekly Homework 9\n" +pi = 4*a(1) +epsilon = 8.85 * 10^(-12) +epercoul = 6.24 * 10^18 +# Conductivity constants ( resistitvity = 1/sigma) +sigmairon = 1*10^7 +sigmacopper = 6*10^7 +sigmasilver = 6.2*10^7 +sigmagold = 4.1*10^7 +sigmaaluminum = 3.5*10^7 +sigmatungsten = 1.8*10^7 +sigmanichrome = 6.7*10^5 +sigmacarbon = 2.9*10^4 + +print "Question 1\n" +#params +i = 1.9/1000 # A +diam = 5/1000 # m + +r = diam/2 +"Protons Per Second " +i*epercoul +# i = \int_0^R J_edge (r/R) 2\pi r dr +# = J_edge/R [ 2\pi r^3 / 3 ]_0^R +# = 2\pi J_edge R^2/3 +jedge = 3*i/(2*pi*r^2) +"J_edge (A/m^2) " +jedge + +print "Question 2\n" +# Equilibrium: eta/2epsilon + EF_I2 = EF_I1 +# EF_I = V/L = IR/L = I(L/sigma/A)/L = I/(sigma*A) +# eta = 2epsilon * ( I/(sigma1*A)-I/(sigma2*A) ) +# Corrections from pearson: apparently it should be eta/epsilon, and the +# sign was opposite, so correct is +print "eta = epsilon * ( I/(sigma2*A)-I/(sigma1*A))\n" +#params +diam = 1/1000 # m +i = 3 # A + +a = pi*r^2 # m^2 +r = diam/2 # m +"Charge on the boundary " +# eta * a +epsilon * i * (1/(sigmairon*a) - 1/(sigmacopper*a)) * a + +print "Question 3\n" +#params +diam = .5 # mm +i = 20 # mA + +diam = diam/1000 # m +r = diam/2 # m +i = i/1000 # A + +a = pi*r^2 +j = i/a +# j = ef*sigma +ef = j/sigmasilver +"Electric Field (V/m) " +ef + +"Electron drift speed (m/s) " # idk lol +ve = 5.8 * 10^28 # number/m^3 +ie = i*epercoul # number/s +ie/a/ve + +print "Question 4\n" +diam = 1 # mm +diam = diam/1000 # m +r = diam/2 +a = pi*r^2 +# efnichrome = efaluminum +# jnichrome/sigmanichrome = jaluminum/sigmaaluminum +# i/pi*(diam_nichrome/2)^2/sigmanichrome = i/a/sigmaaluminum +# pi*(diam_nichrome/2)^2*sigmanichrome = a*sigmaaluminum +"Diameter of nichrome (m) " +2*sqrt(a*sigmaaluminum/sigmanichrome/pi) + +print "Question 5\n" +#params +l = 10 # cm +innerdiam = 2.8 # mm +outerdiam = 3 # mm +v = 3 # V + +l = l/100 # m +innerdiam = innerdiam/1000 # m +innerr = innerdiam/2 +outerdiam = outerdiam/1000 # m +outerr = outerdiam/2 +a = pi*outerr^2 - pi*innerr^2 +ef = v/l +j = ef*sigmanichrome +i = j*a +"Current (A) " +i + +print "Question 6\n" +print "60W means higher resistance, so it has a higher voltage drop\n" +print "and takes more energy\n" + +v = 120 # V +w1 = 60 # W (wattage of lightbulb 1 @ 120V) +# w1 = i*v = v*v/r1 +r1 = v^2/w1 +r1 +w2 = 100 # W +r2 = v^2/w2 +i = v/(r1+r2) +print "Power by the first bulb (W) " +i^2*r1 +print "Power by the second bulb (W) " +i^2*r2 + +print "Question 7\n" +#params +r = 70 # Ohm + +v = 9 # V +i = v/r + +"Magnitude of Current (A) " +i + +print "Direction is left to right (positive to negative)\n" + +print "Question 8\n" +#params +w = 1100 # W + +v = 120 # V +"Resistance (Ohm) " +r = v^2/w +r + +"Current (A) " +v/r + +print "Question 9\n" +#params +m = 1 # g aluminum +p = 8 # W +v = 1.5 # V + +m = m/1000 # kg +r = v^2/p # Ohm +densityaluminum = 2.7 # g/cm^3 +densityaluminum = densityaluminum*1000 #kg/m^3 +vol = m/densityaluminum # m^3 +rhoaluminum = 1/sigmaaluminum # Ohm*m +# R = rhoaluminum * l / A = rhoaluminum * l / (vol/l) = +# rhoaluminum*l^2 / vol +l = sqrt(r/rhoaluminum*vol) # m +# Cross-sectional area +a = vol/l # m^2 +"Diameter (mm) " +2*sqrt(a/pi) * 1000 + +"Length (m) " +l diff --git a/jarrio/week10.bc b/jarrio/week10.bc new file mode 100644 index 0000000..80a8fee --- /dev/null +++ b/jarrio/week10.bc @@ -0,0 +1,245 @@ +print "Daily Homework 10a\n" + +print "Question 4\n" +#params +vbattery = 3.05 +vchange = 2.9 +ammeter = 1.7 + +bigr = vchange/ammeter +"emf " +vbattery +"internal resistance " +rtot = vbattery/ammeter +rtot - bigr +"circuit resistance " +bigr + +print "\nDaily Homework 10b\n" + +print "Question 1\n" +#params +r1 = 2 +r2 = 5 +r3 = 1 +r4 = 7 +r5 = 3 +r6 = 3 +r7 = 3 + +"RA " +r4+r3+1/(1/r1+1/r2) +"RB (open) " +r5 + r4 + r3 + 1/(1/(r6+r1) + 1/r2) +"RB (closed) " +r5 + 1/(1/r4+1/r7) + r3 + 1/(1/(r6+r1) + 1/r2) + +print "Question 2\n" +print "Rlong^2\n" + +print "Question 3\n" +# params +ratio = 10 # Ip = 10Is +# Without loss of generality, let Is = 1, and R2 = 1, so r = R1. +# IR = V +# 1(1+r) = V +# 10/(1/1 + 1/r) = V +# 1 + r = 10/(1 + 1/r) +# (1+r)(1+1/r) = 10 +# r^2 + 2r + 1 = 10r +# r^2 - 8r + 1 = 0 +b = 2 - ratio +(-b - sqrt(b^2 - 4*1*1))/2 + +print "Question 4\n" +#params +ammeter = 9 + +# clockwise loop rule on top loop +# ammeter - 3*i1 + 2*ammeter = 0 +i1 = ammeter +print "I1 (A)\n" +i1 + +# branch rule +i2 = i1+ammeter +print "I2 (A)\n" +i2 + +# clockwise loop rule on bottom loop +# -2*ammeter + electromotive - 1*i2 = 0 +electromotive = 2*ammeter + i2 +print "Electromotive (V)\n" +electromotive + +print "\nDaily Homework 10c\n" +print "Question 2\n" +print "C > A = E > B > D\n" + +print "Question 3\n" +#params +c = 10 # uF +q = 30 # uC +r = 1.8 # kOhm +qtarget = 15 # uC + +# c = q(t)/v(t) --> v(t) = q(t)/c +# dq(t)/dt = -I = -v(t)/r +# dq(t)/dt = -q(t)/cr +# q(t) = Ce^{-t/cr} +# C = q +# q(t) = qe^{-t/cr} = qtarget => -t/cr = ln(qtarget/q) + +r = r*1000 # Ohm +qtarget = qtarget/10^6 # C +c = c/10^6 # F +q = q/10^6 # C + +t = -c*r*l(qtarget/q) +print "Time (s)\n" +t + +print "\nWeekly Homework 10\n" +print "Question 1\n" +#params +r1 = 2.5 # kOhm +r2 = 4.0 # kOhm +r3 = 5.0 # kOhm +v = 100 # V +# v = ir +# p = iv = v^2/r + +pparallel = v^2 / (1/(1/r1 + 1/r2 + 1/r3)) +pseries = v^2 / (r1 + r2 + r3) +pparallel/pseries + +print "Question 2\n" +# I = ef/(r+R) +# P = I^2R = ef^2*R/(r+R)^2 +# dP/dR = 0 = d/dR (ef^2*R/(r+R)^2) +# d/dR (R/(r+R)^2) = 0 +# (r+R)/(r+R)^3 - 2R/(r+R)^3 = (r-R)/(r+R)^3 = 0 +# r = R +print "Part A: R = r\n" + +print "Part B\n" +# params +ef = 5 # V +r = 1.8 # Ohm +i = ef/(r+r) +print "Power (W)\n" +i^2*r + +print "Question 3\n" +#params +bulbr = 6 # Ohm +r = .8 # Ohm +v = 1.5 # V + +iopen = v/(r+bulbr) +print "I_open (A)\n" +iopen + +iclosed = v/(r+bulbr/2) / 2 # because current is even between a and b +print "I_closed (A)\n" +iclosed + +print "pct change\n" +100*(iclosed-iopen)/iopen + +print "Question 4\n" +v = 24 # V +# No params. Effective resistance w/ open is 6Ohm and 6Ohm in parallel, +# giving 3Ohm +print "Part A - Ibat (A)\n" +v/3 + +print "Part B - dV (V)\n" +v/3 + +# the two pairs of parallel resistors = two effective resistors in +# parallel +print "Part C - Ibat (A)\n" +v / (1/(1/3 + 1/5) + 1/(1/3 + 1)) + +print "Part D - dV (V)\n" +0 + +print "Question 5\n" +v = 24 # V +i6 = v/10 # effective resistance calculation +i5 = v/15 # same +i10 = i5 +i4 = i6 + +print "Currents (i6, i5, i10, i4)\n" +i6 +i5 +i10 +i4 + +v6 = i6*6 # V = IR +v5 = i5*5 +v10 = i10*10 +v4 = i4*4 +print "Voltages (v6, v5, v10, v4)\n" +v6 +v5 +v10 +v4 + +print "Question 6\n" +#params +v = 150 +rtot = 2 + 1/(1/20 + 1/5) + 4 +itot = v/rtot +vparallel = itot / (1/20 + 1/5) # v through the parallel resistors +i20 = vparallel/20 + +print "I20 (A)\n" +i20 + +print "Question 7\n" + +# 1/(1/4 + 1/12) = 3. +# 3 + 5 = 8 +# 1/(1/8 + 1/24) = 6. +# Assume current goes clockwise. +# Loop: 12 - I*6 - 3 - I*3 = 0 +# 9 = I*9 => I = 1A. +# Then, week10resistors.py has the solution +print "See source\n" + +print "Question 8\n" +#params +tconstant = 7 # ms + +print "Charge reduced to half (ms)\n" +-l(1/2)*tconstant + +print "Energy reduced to half (ms)\n" +-l(1/sqrt(2))*tconstant + +print "Question 9\n" +#params +c = 40 # uF +# The graph shows a reduction from 30V to 10V in 4ms, giving a time +# constant of +tconstant = 4/l(30/10) # ms +# tconstant = cr => r = tconstant/c +c = c/10^6 # F +tconstant = tconstant/1000 # s +r = tconstant/c +print "Resistance\n" +r + +print "Question 10\n" +#params +c = .25 # uF +v = 70 # V +r1 = 25 # Ohm (the one the question asks about) +r2 = 150 # Ohm +q = c*v # uC +j = q*v/2 +print "Energy dissipated (uJ)\n" +j*r1/(r1+r2) diff --git a/jarrio/week10resistors.py b/jarrio/week10resistors.py new file mode 100644 index 0000000..f7041c7 --- /dev/null +++ b/jarrio/week10resistors.py @@ -0,0 +1,66 @@ +class resistor: + def __init__(self, resistance: float): + self._resistance = resistance; + self.has_current(0) + + def has_current(self, current: float): + self._current = current + self._voltage = current*self._resistance + + def has_voltage(self, voltage: float): + self._voltage = voltage + self._current = voltage/self._resistance + + def __repr__(self): + return f"Resistor with resistance {self._resistance}: current {self._current} through voltage {self._voltage}" + +class parallel(resistor): + def __init__(self, r1: resistor, r2: resistor): + self._r1 = r1 + self._r2 = r2 + self._resistance = 1/(1/r1._resistance + 1/r2._resistance) + + def _update_children(self): + self._r1.has_voltage(self._voltage) + self._r2.has_voltage(self._voltage) + + def has_current(self, current: float): + self._current = current + self._voltage = current*self._resistance + self._update_children() + + def has_voltage(self, voltage: float): + self._voltage = voltage + self._current = voltage/self._resistance + self._update_children() + +class series(resistor): + def __init__(self, r1: resistor, r2: resistor): + self._r1 = r1 + self._r2 = r2 + self._resistance = r1._resistance + r2._resistance + + def _update_children(self): + self._r1.has_current(self._current) + self._r2.has_current(self._current) + + def has_current(self, current: float): + self._current = current + self._voltage = current*self._resistance + self._update_children() + + def has_voltage(self, voltage: float): + self._voltage = voltage + self._current = voltage/self._resistance + self._update_children() + +r24 = resistor(24) +r4 = resistor(4) +r12 = resistor(12) +r5 = resistor(5) +rtot = parallel( r24, series( parallel(r4,r12), r5 ) ) +rtot.has_current(1) +print(r24) +print(r5) +print(r4) +print(r12) diff --git a/jarrio/week9practice.bc b/jarrio/week9practice.bc deleted file mode 100644 index 611dc8e..0000000 --- a/jarrio/week9practice.bc +++ /dev/null @@ -1,162 +0,0 @@ -######################################################################## -print "Weekly Homework 9\n" -pi = 4*a(1) -epsilon = 8.85 * 10^(-12) -epercoul = 6.24 * 10^18 -# Conductivity constants ( resistitvity = 1/sigma) -sigmairon = 1*10^7 -sigmacopper = 6*10^7 -sigmasilver = 6.2*10^7 -sigmagold = 4.1*10^7 -sigmaaluminum = 3.5*10^7 -sigmatungsten = 1.8*10^7 -sigmanichrome = 6.7*10^5 -sigmacarbon = 2.9*10^4 - -print "Question 1\n" -#params -i = 1.9/1000 # A -diam = 5/1000 # m - -r = diam/2 -"Protons Per Second " -i*epercoul -# i = \int_0^R J_edge (r/R) 2\pi r dr -# = J_edge/R [ 2\pi r^3 / 3 ]_0^R -# = 2\pi J_edge R^2/3 -jedge = 3*i/(2*pi*r^2) -"J_edge (A/m^2) " -jedge - -print "Question 2\n" -# Equilibrium: eta/2epsilon + EF_I2 = EF_I1 -# EF_I = V/L = IR/L = I(L/sigma/A)/L = I/(sigma*A) -# eta = 2epsilon * ( I/(sigma1*A)-I/(sigma2*A) ) -# Corrections from pearson: apparently it should be eta/epsilon, and the -# sign was opposite, so correct is -print "eta = epsilon * ( I/(sigma2*A)-I/(sigma1*A))\n" -#params -diam = 1/1000 # m -i = 3 # A - -a = pi*r^2 # m^2 -r = diam/2 # m -"Charge on the boundary " -# eta * a -epsilon * i * (1/(sigmairon*a) - 1/(sigmacopper*a)) * a - -print "Question 3\n" -#params -diam = .5 # mm -i = 20 # mA - -diam = diam/1000 # m -r = diam/2 # m -i = i/1000 # A - -a = pi*r^2 -j = i/a -# j = ef*sigma -ef = j/sigmasilver -"Electric Field (V/m) " -ef - -"Electron drift speed (m/s) " # idk lol -ve = 5.8 * 10^28 # number/m^3 -ie = i*epercoul # number/s -ie/a/ve - -print "Question 4\n" -diam = 1 # mm -diam = diam/1000 # m -r = diam/2 -a = pi*r^2 -# efnichrome = efaluminum -# jnichrome/sigmanichrome = jaluminum/sigmaaluminum -# i/pi*(diam_nichrome/2)^2/sigmanichrome = i/a/sigmaaluminum -# pi*(diam_nichrome/2)^2*sigmanichrome = a*sigmaaluminum -"Diameter of nichrome (m) " -2*sqrt(a*sigmaaluminum/sigmanichrome/pi) - -print "Question 5\n" -#params -l = 10 # cm -innerdiam = 2.8 # mm -outerdiam = 3 # mm -v = 3 # V - -l = l/100 # m -innerdiam = innerdiam/1000 # m -innerr = innerdiam/2 -outerdiam = outerdiam/1000 # m -outerr = outerdiam/2 -a = pi*outerr^2 - pi*innerr^2 -ef = v/l -j = ef*sigmanichrome -i = j*a -"Current (A) " -i - -print "Question 6\n" -print "60W means higher resistance, so it has a higher voltage drop\n" -print "and takes more energy\n" - -v = 120 # V -w1 = 60 # W (wattage of lightbulb 1 @ 120V) -# w1 = i*v = v*v/r1 -r1 = v^2/w1 -r1 -w2 = 100 # W -r2 = v^2/w2 -i = v/(r1+r2) -print "Power by the first bulb (W) " -i^2*r1 -print "Power by the second bulb (W) " -i^2*r2 - -print "Question 7\n" -#params -r = 70 # Ohm - -v = 9 # V -i = v/r - -"Magnitude of Current (A) " -i - -print "Direction is left to right (positive to negative)\n" - -print "Question 8\n" -#params -w = 1100 # W - -v = 120 # V -"Resistance (Ohm) " -r = v^2/w -r - -"Current (A) " -v/r - -print "Question 9\n" -#params -m = 1 # g aluminum -p = 8 # W -v = 1.5 # V - -m = m/1000 # kg -r = v^2/p # Ohm -densityaluminum = 2.7 # g/cm^3 -densityaluminum = densityaluminum*1000 #kg/m^3 -vol = m/densityaluminum # m^3 -rhoaluminum = 1/sigmaaluminum # Ohm*m -# R = rhoaluminum * l / A = rhoaluminum * l / (vol/l) = -# rhoaluminum*l^2 / vol -l = sqrt(r/rhoaluminum*vol) # m -# Cross-sectional area -a = vol/l # m^2 -"Diameter (mm) " -2*sqrt(a/pi) * 1000 - -"Length (m) " -l -- cgit