%  This function solves homework problem [H9.14]
%  ---------------------------------------------
%
echo on
diary nsds_hw9_14.dry
%
global Ron Goff
%
%  Set initial conditions
%
tf = 0.05;
dt = tf/100;
t = 0:dt:tf;
tol = 1e-5;
%
%  The current through the inductor serves as continuous state
%
uR0 = 0;
i00 = 0;
xc0 = [uR0;i00];
%
%  There is one discrete state variable:
%
%    m0 = 1 (true)  : diode is blocking
%         0 (false) : diode is conducting
%
m0 = 0;
xd0 = m0;
%
%  Simulate using RKF4/5 with root solver
%
Ron = 1e-4;
Goff = 1e-4;
echo off
[y1,xc1,xd1,tout1] = rkf45rt2(xc0,xd0,t,tol);
echo on
%
%  Repeat the simulation with different fudge values
%
Ron = 1e-5;
Goff = 1e-5;
echo off
[y2,xc2,xd2,tout2] = rkf45rt2(xc0,xd0,t,tol);
echo on
%
%  Plot the results
%
subplot(2,1,1)
plot(tout1,y1(1,:),tout2,y2(1,:))
grid on
title('Homework [H9.14]')
xlabel('Time')
ylabel('uC')
subplot(2,1,2)
plot(tout1,y1(2,:),tout2,y2(2,:))
grid on
xlabel('Time')
ylabel('h')
%
print -deps nsds_hw9_14.eps
diary off
echo off
%
return