%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load Line Analysis of a diode circuit
% vsaxena@uidaho.edu, Jan 2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc; close all; clear all;

mA = 1e-3;
vT = 0.026;

Is = 1e-15;
R = 1e3;
Vx = 2;

V=[0:0.01:Vx];

% Diode equation
f1=@(V) (Is*(exp(V/vT)-1));

% Load line equation
f2=@(V) (Vx-V)/R;

% Graphical solution
VD = fzero(@(V)f1(V)-f2(V),0.5); %starts search from V==0.5
ID = f1(VD)/mA;

% Plot the curves
figure();
plot(V, f1(V)/mA, 'r', 'linewidth', 2);
hold on; grid on;
plot(V, f2(V)/mA, 'b',  'linewidth', 2);

% Add marker and text
plot(VD, ID,'kO')
txt2 = ['V_D = ', num2str(VD), 'V, I_D = ', num2str(ID), ' mA'];
text(VD+0.5,ID+0.5,txt2)

title('Load Line Analysis');
xlabel('V_D, V')
ylabel('I_D, mA')

xlim([0 Vx]);
ylim([0 10]);

