Professional Documents
Culture Documents
1.4 Rappture and MATLAB PDF
1.4 Rappture and MATLAB PDF
1.4 Rappture and MATLAB PDF
MATLAB Applications
Michael McLennan
HUBzero® Platform for Scientific Collaboration
Purdue University
% more out.dat
FERMI-DIRAC FUNCTION F1/2
https://nanohub.org/infrastructure/rappture
source code: rappture/examples/app-fermi
2
What is the interface?
disp('Enter
disp('Enter the
the Fermi
Fermi level
level (eV):');
(eV):'); number
Ef
Ef == input('
input(' Ef
Ef == ');
');
disp('Enter
disp('Enter the
the temperature
temperature (K):');
(K):'); number
TT == input('
input(' TT == ');
');
kT
kT == 8.61734e-5
8.61734e-5 ** T;
T; physics
Emin
Emin == Ef
Ef -- 10*kT;
10*kT;
Emax
Emax == Ef
Ef ++ 10*kT;
10*kT;
EE == linspace(Emin,Emax,200);
linspace(Emin,Emax,200);
ff == 1.0
1.0 ./
./ (1.0
(1.0 ++ exp((E
exp((E -- Ef)/kT));
Ef)/kT));
fid
fid == fopen('out.dat','w');
fopen('out.dat','w');
fprintf(fid,'FERMI-DIRAC
fprintf(fid,'FERMI-DIRAC FUNCTION
FUNCTION
F1/2\n\n');
F1/2\n\n');
fprintf(fid,‘f1/2
fprintf(fid,‘f1/2 Energy
Energy (eV)\n');
(eV)\n');
fprintf(fid,'------------
fprintf(fid,'------------ ------------\n');
------------\n'); curve
fprintf(fid,'%12g
fprintf(fid,'%12g %12g\n',
%12g\n', [f;
[f; E]);
E]);
fclose(fid);
fclose(fid);
quit;
quit;
3
Build the interface: Temperature input
4
Build the interface: Ef input
5
Build the interface: Curve output
6
Build the interface: Use MATLAB/Octave
7
Add physics to the generated code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
kT
kT == 8.61734e-5
8.61734e-5 ** T;
T; physics
% Add your code here for the main body of your program
Emin
Emin == Ef
Ef -- 10*kT;
10*kT;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Emax
Emax == Ef
Ef ++ 10*kT;
10*kT;
EE == linspace(Emin,Emax,200);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
linspace(Emin,Emax,200);
% Save output values backff to Rappture
== 1.0
1.0 ./
./ (1.0
(1.0 ++ exp((E
exp((E -- Ef)/kT));
Ef)/kT));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
kT = 8.61734e-5 * temperature;
Emin = Ef - 10*kT;
Emax = Ef + 10*kT;
E = linspace(Emin,Emax,200);
f = 1.0 ./ (1.0 + exp((E - Ef)/kT));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<XML> driver1827.xml
Builder Runner
kT
kT == 8.61734e-5
8.61734e-5 ** temperature;
temperature; physics
Emin
Emin == Ef
Ef -- 10*kT;
10*kT;
<?xml
<?xml version="1.0"?>
version="1.0"?> Emax == Ef
Emax Ef ++ 10*kT;
10*kT;
<run>
<run>
…… EE == linspace(Emin,Emax,200);
linspace(Emin,Emax,200);
ff == 1.0
1.0 ./
./ (1.0
(1.0 ++ exp((E
exp((E -- Ef)/kT));
Ef)/kT));
<output>
<output>
<curve
<curve id="f12">
id="f12">
……
<component>
<component>
<xy>
<xy>
0.999955
0.999955 2.33365
2.33365
0.99995
0.99995 2.33431
<XML>
2.33431 <XML>
0.999944 2.33498
0.999944 2.33498
……
</output>
</output>
</run>
</run> tool.xml run12703129102.xml
10
Debugging
Run it by hand:
$ ls
driver1529.xml fermi.m tool.xml
$ use rappture
$ matlab –r infile=\’driver1529.xml\’,main
11
Assignment #4: Build a simple Spirograph tool
n1 n2 n3
number number number
Spirograph equation
z
curve
In MATLAB/Octave:
t = linspace(0, 1, 1000);
z = exp(i*2*pi*n1*t) + exp(i*2*pi*n2*t) + exp(i*2*pi*n3*t);
plot(real(z),imag(z));
12