aboutsummaryrefslogtreecommitdiff
path: root/jarrio
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2021-11-01 16:18:06 -0400
committerHolden Rohrer <hr@hrhr.dev>2021-11-01 16:18:06 -0400
commit54ca67bc4b75fe2ad6d2f68aa4eff61f781d2af8 (patch)
tree3cd68fbffeabfb3352a20a957b3021b553226403 /jarrio
parent4cd17b41af04de301f84e953d7a5ebc0c97d1353 (diff)
updates for math and physics homeworks
Diffstat (limited to 'jarrio')
-rw-r--r--jarrio/week09.bc (renamed from jarrio/week9practice.bc)1
-rw-r--r--jarrio/week10.bc245
-rw-r--r--jarrio/week10resistors.py66
3 files changed, 311 insertions, 1 deletions
diff --git a/jarrio/week9practice.bc b/jarrio/week09.bc
index 611dc8e..b0357f8 100644
--- a/jarrio/week9practice.bc
+++ b/jarrio/week09.bc
@@ -1,4 +1,3 @@
-########################################################################
print "Weekly Homework 9\n"
pi = 4*a(1)
epsilon = 8.85 * 10^(-12)
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)