% maxpower.m:  Demonstration of maximum power transfer for sinusoidal steady
%              state circuits.
%
% ELEC 226, R. Kozick

Vth = 1;             % Thevenin voltage source phasor
Zth = 100 - j*100;   % Thevenin impedance of source
Rth = real(Zth);
Xth = imag(Zth);

% Case 1:  P versus RL with XL=-100;

XL = 100;
RL = logspace(0, 4, 100);
P1 = Vth*Vth'/2*RL./((Rth+RL).^2 + (Xth+XL).^2);

figure(1)
semilogx(RL, P1);
xlabel('R_L (OHMS)')
ylabel('AVERAGE POWER (W)')
title('P VERSUS R_L WITH X_L = 100')

% Case 2:  P versus XL with RL=100;

RL = 100;
XL = logspace(0, 4, 100);
P2 = Vth*Vth'/2*RL./((Rth+RL).^2 + (Xth+XL).^2);

figure(2)
semilogx(XL, P2);
xlabel('X_L (OHMS)')
ylabel('AVERAGE POWER (W)')
title('P VERSUS X_L WITH R_L = 100')

% Case 3:  P versus RL with XL=0

XL = 0;
RL = logspace(0, 4, 100);
P3 = Vth*Vth'/2*RL./((Rth+RL).^2 + (Xth+XL).^2);

figure(3)
semilogx(RL, P3);
xlabel('R_L (OHMS)')
ylabel('AVERAGE POWER (W)')
title('P VERSUS R_L WITH X_L = 0')

% Case 4:  P versus a^2 for a^2 ZL = (1 + j2) * a^2

a2 = logspace(0, 4, 100);
ZL = (1 + j*2)*a2;
RL = real(ZL);
XL = imag(ZL);
P4 = Vth*Vth'/2*RL./((Rth+RL).^2 + (Xth+XL).^2);

figure(4)
semilogx(RL, P4);
xlabel('a^2 (TURNS RATIO)')
ylabel('AVERAGE POWER (W)')
title('P VERSUS a^2ITH Z_L = a^2 (1 + j*2)')
