% /home/dimarzio/Documents/working/12229/supplementary/inductor.m
% Sat Oct 14 13:37:59 2017 Chuck DiMarzio, Northeastern University
L=1; % Henry
dt=1e-3;tstop=1;tmax=2;
t1=[dt:dt:tstop];
t2=[tstop+dt:dt:tmax];
t=[t1,t2];
didt=[rand(size(t1))-0.4,zeros(size(t2))]*1000;
didt=conv(didt,ones(1,20),'same')/20;
I=cumsum(didt)*dt;
figure;;plot(t,I);grid on;
xlabel('t, Time, sec');
ylabel('I, Current, Amps');
figure;plot(t,didt);grid on;
xlabel('t, Time, sec');
ylabel('di/dt, Amps/Sec');
p=L*I.*didt;
figure;plot(t,p,'b-');grid on;
xlabel('t, Time, sec');
ylabel('p, Power, Watts');
w=cumsum(p)*dt;
figure;plot(t,w,'b-',...
	    t1(end),w(find(t1==t1(end))),'bo',...
            t([1,end]),max(w)*[1,1],'r-');grid on;
xlabel('t, Time, sec');
ylabel('w, Stored Energy, Joules');