Sie sind auf Seite 1von 4

Key:

Program codes: blue


Program comments: blue
My comments: red.

diary ex9_1.dat

% Diode parameters
%This refers to an ordinary comment. % is used to input comments.

vt = 25.67e-3;

% vt here represents the thermal voltage (Vt), which at room temperature is a


constant. Based on standard calculations; Vt = k*T/q.
%k is Boltzmann’s constant = 1.38 * 10-23 J/0K
%q is the electronic charge = 1.6 * 10-19C.
%T is the absolute temperature in 0K.
%At room temperature (250C = 298.15K).
%The thermal voltage is about 25.67 mV.
%Thus from here we see that the code says *25.67e-3*. meaning that 'eZ' here
represents '10Z'

v = [0.1 0.2 0.3 0.4 0.5 0.6 0.7];

%From our formula we know that


%I = Io { exp (V/nVt) – 1}.
%Thus we can vary values of V (maybe in the lab) to obtain variation in the current.
%There is just a space between the 2 values to show their difference. Another syntax
used here would lead to error.

i = [0.133e-12 1.79e-12 24.02e-12 321.66e-12 4.31e-9 57.69e-9 772.58e-9];

%Here we measured our values for I using a multimeter for example and juxtaposed it
with the corresponding values of the voltage ‘V’.

lni = log(i);

% Natural log of current


%The function for Ln in matlab is just log. So Ln(i) is just log(i). Which is the natural
log of current (loge I).

%I = Io { exp (V/nVt) – 1}.


% Thus, I/Io = i = exp (V/nVt) – 1
% ln(i) = V/nVt
% and ln(I) = V/nVt + ln(Io)

% Coefficients of Best fit linear model is obtained

p_fit = polyfit(v,lni,1);

%“Polyfit” is a MATLAB function that computes a least squares polynomial for a


given set of data. Polyfit actually generates the coefficients of the polynomial (which
can be used to simulate a curve to fit the data) according to the degree specified.
%The general polyfit equation on the MATLAB is given as POLYFIT(x,y,n); where x
is the abscissa variable, y is the ordinate variable and n is the degree of the
polynomial with which we are working with.
%POLYFIT(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the
data, p(x(i)) is approximately equal to y(i), in a least-squares sense.

% linear equation is y = m*x + b

%Comparing with ln(I) = V/nVt + ln(Io), we can assume that


%m is a constant which is equal to the 1//nVt. This implies that the value of the slope
of the graph is 1/nVt = 38.95597974/n.
%b = ln(Io). Which is a constant. Thus the exponential of b should be equivalent to the
saturation current.
%x is the variable voltage. (From 0.1 – 0.7).
%Thus we have simplified our first degree equation here. This we now express in our
polyfit function in the form of y=m*x + b.
%Where in the mapping, b would be given a 2 nd order polyfit and m would be given
the 1st.

b = p_fit(2);

%generate the coefficients of the first degree polynomial best characterizing the data
set for ln(Io)

m = p_fit(1);
%generates the coefficients of the first degree polynomial best characterizing the data
set for 38.95597974/n

ifit = m*v + b;
%Combining the equation to get the actual polyfit.

% Calculate Is and n

Is = exp(b)

%Referencing from the original linear equation

%ln(i) = V/nVt + ln(Io)……..(1)


%y = m*x + b ……………...(2)

%Comparing,
%b = ln(Io) where Io is the saturation current Is.
%Therefore, exp(b) = Io = Is. This equivalent of the function exponential of the
function 'b'.

n = 1/(m*vt)

%Referencing from the original linear equation

%ln(i) = V/nVt + ln(Io)……..(1)


%y = m*x + b ……………...(2)

%Comparing,

% m = 1/nVt;
% Thus, cross multiplying,
% n = 1/mVt.

% Plot v versus ln(i), and best fit linear model

plot(v,ifit,'w', v, lni,'ow')

%This is the function for plotting. we are then plotting for the best fit in the points we
have obtained in the linear graph which would give us a straight line.
% plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding

values in X.
% If X and Y are both vectors, then they must have equal length. The plot

function plots Y versus X.

% If X and Y are both matrices, then they must have equal size. The plot

function plots columns of Y versus columns of X.

% plot(X,Y,LineSpec) sets the line style, marker symbol, and color.

% plot(X1,Y1,...,Xn,Yn) plots multiple X, Y pairs using the same axes for all

lines.

% plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn) sets the line style, marker type,

and color for each line.

% You can mix X, Y, LineSpec triplets with X, Y pairs. For example,

plot(X1,Y1,X2,Y2,LineSpec2,X3,Y3).

xlabel (‘Voltage (V)’)

%Labelling the x-axis (absicca) the term ‘Voltage’

ylabel('ln(i)')

%Labelling the Y-axis (ordinate) the term 'Ln (I)' representing the current which is in
the natural log form in other to enable us plot the graph reasonably.

title('Best fit linear model')

The title of the graph of the experiment is 'Best fit linear model'.

diary

%The results obtained from MATLAB are

Is = 9.9525e-015

n = 1.5009

Das könnte Ihnen auch gefallen