Differences between revisions 9 and 13 (spanning 4 versions) Back to page
Revision 9 as of 4:01AM, Apr 25, 2011
Size: 1534
Editor: Gweon
Comment:
Revision 13 as of 4:03AM, Apr 25, 2011
Size: 1682
Editor: Gweon
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[ Matlab and Python | First, here is some base-line discussion for Matlab and Python]]. === Here is some discussion of the programming part of Homework #4. ===

[[ Matlab and Python | First, here is some base-line discussion for Matlab and Python that you might find useful]].  Please read it, or at least scan through it.

Here is some discussion of the programming part of Homework #4.

First, here is some base-line discussion for Matlab and Python that you might find useful. Please read it, or at least scan through it.

Now, for this homework, you basically need to calculate some functions and plot up the results. Example 2.3 of the textbook is a pretty good "template" for this task, and so I will discuss that example.

Here is the Matlab code for Example 2.3. This code is somewhat different from the code in the text book, but does the same thing.

%E2.3: Fermi Function Calculation, f(E-EF,T)

%Initialization
clear
close

%Constant
%25.85 meV for 300 K is an equivalent way to remember it.
k=8.617e-5;

%Google for "Matlab linspace", to find out what linspace does!
dE=linspace(-0.2,0.2);
for ii=1:4;
    T=100*ii;
    kT=k*T;
    f(ii,:)=1./(1+exp(dE./kT));
    end

%Plotting result
close
plot(dE,f); grid;
xlabel('E - E_F (eV)'); ylabel('f (E)');
text(.05,.22,'T=400K'); text(-.03,.12,'T=100K');

%Octave-specific -- uncomment this line for using with Octave.
%print -djpg E2.3.oct.jpg

The obtained images by Matlab and Octave are as follows (click to see full images).

Inlined image: E2.3.jpg Inlined image: E2.3.oct.jpg

To run the above code with Octave, you should un-comment the last line, and then run

octave E2.3.oct.m

Of course, for this command to run successfully, octave must be in the path (which is not the case by default for Windows installation! -- I had to add the Octave bin directory to path manually!), and E2.3.oct.m must be the file name of the above code.