A03.m - Calculating the Fine Structure Constant using Pre-Defined Variables

% loads the variables stored in the file constants.mat into memory
load('constants');

% calculate the fine structure constant
alpha = e^2 / (hbar * c * 4 * pi * eps0);

% display the reciprical of the fine structure consant to 5 decimal places
fprintf('fine structure constant = 1 / %.5f\n',1/alpha)

Download A03.m

Download constants.mat

This program demonstrates how to read in a .mat file that has previously defined variables and use those variables in a simple calculation. The command load command will read in variables if the argument is a .mat file and will read in data values if it is an ASCII file (more on that later).

The constants.mat file contains values for the following constants all defined in MKS units:

Feel free to download this file and add to it or customize it to your needs. To save the variables defined in memory to a file, simply use the command save('filename'). Matlab will automatically add the .mat file extension.


Monkey Home   |    Prev   |   Next