1. Foundations
Four ideas explain 90% of circuit behavior.
Think water: voltage is the height difference, current is how fast water flows, resistance is the valve restricting it.
2. Ohm's Law V = I × R
Change any slider — the other value updates instantly. Power is P = V·I.
V = 12; R = 470; I = V/R; P = V*I; disp(I)
3. Series and Parallel Resistors
Voltage Divider
Vout = Vin × R2 / (R1 + R2)
R = [100, 220, 330]; Rs = sum(R); Rp = 1/sum(1./R)
4. Kirchhoff's Laws
KCL: currents into a node sum to zero. KVL: voltages around a loop sum to zero.
% KVL for two loops
A = [10 -5; -5 15]; b = [12; -5]; I = A\b
5. Capacitors and RC Time Constant
Q = C·V. In an RC charge: Vc(t)=Vin·(1−e^(−t/τ)), with τ = R·C. At t=τ, Vc ≈ 63.2% of Vin.
R=10e3; C=100e-6; tau=R*C; t=0:tau/20:5*tau; Vc=5*(1-exp(-t/tau)); plot(t,Vc); xlabel('t (s)'); grid on
6. Inductors Basics
Inductor voltage opposes change: V = L·di/dt. Stored energy: E = ½·L·I². For an RL step, I(t)=I∞·(1−e^(−t/τ)), τ = L/R.
L=0.1; R=50; tau=L/R; t=0:0.001:0.05; I=0.2*(1-exp(-t/tau)); plot(t,I)
7. AC, Phasors, Impedance
Use complex impedance: ZR=R, ZC=1/(jωC), ZL=jωL, ω=2πf.
RC low-pass gain: |H| = 1/√(1+(2πfRC)²), cutoff fc=1/(2πRC).
f=logspace(1,5,200); w=2*pi*f; R=1e3; C=1e-7; H=1./(1+1j*w*R*C); semilogx(f,20*log10(abs(H))); grid on
9. Diodes — The One-Way Valve
A PN junction conducts easily forward, blocks reverse. Silicon diodes drop about 0.6–0.7 V when on, and break down (often destructively) if reverse voltage exceeds the rating.
Shockley Diode Equation
I = Is ( eV/(n·VT) − 1 ), where VT = kT/q ≈ 26 mV at 300 K.
Half-Wave Rectifier
Is=1e-12; n=1.7; Vt=25.85e-3; V=0:0.01:0.8; I=Is*(exp(V/(n*Vt))-1); plot(V,I); xlabel('Vd (V)'); ylabel('Id (A)'); grid on
10. Transistors — Switches and Amplifiers
Two workhorses: BJTs (current-controlled) and MOSFETs (voltage-controlled).
BJT (NPN) Common-Emitter
In active mode: IC = β·IB. Base–emitter is ~0.7 V when on.
MOSFET (NMOS)
In saturation: ID = k·(VGS−Vth)² for VGS > Vth.
% BJT bias
Vcc=12; Rb=220e3; Rc=2.2e3; beta=150; Ib=(Vcc-0.7)/Rb; Ic=beta*Ib; Vce=Vcc-Ic*Rc;
% MOSFET
k=0.01; Vth=1; Vgs=0:0.1:5; Id=k*max(0,Vgs-Vth).^2; plot(Vgs,Id)
11. Op-Amps — Ideal Amplifiers
Golden rules with negative feedback: (1) no input current, (2) V⁺ ≈ V⁻.
Waveform shows a sine input (blue) and inverting output (teal). Increase gain or Vin to see clipping at ±Vsupply.
% Inverting amp
Rin=10e3; Rf=100e3; t=0:1e-5:0.002; Vin=0.1*sin(2*pi*1000*t); Vout=-(Rf/Rin)*Vin; plot(t,Vin,t,Vout)
8. Octave Lab — Copy-Paste Starter Kit
Paste these into GNU Octave to compare with the interactives above.
1) Ohm's law sweep
% Ohm's law sweep
R = 470;
V = 0:0.5:12;
I = V / R;
P = V .* I;
plot(V, I, 'linewidth', 2);
xlabel('Voltage (V)'); ylabel('Current (A)'); grid on;
title('I vs V for R = 470 Ω');
2) Resistor networks
% Series and parallel
R = [100, 220, 330];
Rs = sum(R)
Rp = 1 / sum(1 ./ R)
% Voltage divider
Vin = 12; R1 = 1e3; R2 = 1e3;
Vout = Vin * R2 / (R1 + R2)
3) Nodal / mesh analysis
% Two-loop KVL: [R1+R2 -R2; -R2 R2+R3] * [I1;I2] = [V1; -V2]
R1=5; R2=5; R3=10; V1=12; V2=5;
A = [R1+R2, -R2; -R2, R2+R3];
b = [V1; -V2];
I = A \ b % I(1)=I1, I(2)=I2
4) RC transient
% RC charging
R=10e3; C=100e-6; Vin=5;
tau=R*C; t=0:tau/50:5*tau;
Vc = Vin * (1 - exp(-t/tau));
plot(t, Vc, 'linewidth', 2); grid on;
xlabel('t (s)'); ylabel('Vc (V)');
line([tau tau], [0 Vin], 'linestyle','--');
text(tau, 0.1, ' tau');
5) RL transient
% RL step response
L=0.1; R=50; Iinf=0.2;
tau=L/R; t=0:0.0002:0.03;
I = Iinf * (1 - exp(-t/tau));
plot(t, I, 'linewidth', 2); grid on;
xlabel('t (s)'); ylabel('I (A)'); title('RL step');
6) AC Bode plot
% RC low-pass Bode magnitude
R=1e3; C=1e-7;
f=logspace(1,5,400); w=2*pi*f;
H = 1 ./ (1 + 1j*w*R*C);
semilogx(f, 20*log10(abs(H)), 'linewidth',2); grid on;
xlabel('Frequency (Hz)'); ylabel('|H| (dB)');
title('RC Low-Pass');