% script file polyfit_diode.m % % Sets arrays of measured data and uses polyfit function % to find best values for a linear regression model of % ln(i) vs v. % % The motivation for the linear regression model is the % Shockley's Law diode model: % i = Is (exp(v/vT) - 1) % where Is = reverse saturation current % vT = kT/q is thermal voltage % T = temperature in degrees K % Define physical constants. k = 1.38e-23; % J/degK Boltzmann constant q = 1.602e-19; % C electron charge % Create arrays containing measured data. v_diode = [1.3 1.35 1.4 1.41]; i_diode = [0.0006 0.0022 0.0136 0.0211]; x=v_diode; y=log([0.6e-3, 2.2e-3, 13.6e-3, 21.1e-3]); a = polyfit(x,y,1); % Calculate model predictions for the measured voltages. pred_lni_diode = a(2) + a(1) * v_diode; pred_i_diode = exp(pred_lni_diode) % Plot the measured and model values on the same plot. axes('FontSize',14) % hold off plot(v_diode, y, 'bo') hold on xlabel('LED voltage (V)','FontSize',14); ylabel('log LED current log(A)','FontSize',14); plot(v_diode, pred_lni_diode, 'r-'); legend('data','linear fit','Location','Best'); % hold off