function powerdemo(vhat,ihat,phi) phirad = phi*pi/180; t = linspace(0,10); v = vhat*cos(t); i = ihat*cos(t+phirad); Pavg = vhat*ihat*cos(phirad)/2*ones(size(t)); figure(1) plot(t,v,t,i,t,v.*i,t,Pavg,'r--','linewidth',2) set(gca,'fontsize',14) legend('Voltage (V)','Current (A)','p(t) (W)','Average Power (W)') hold on plot(t,zeros(size(t)),':k') xlabel('time') hold off