3.0

3.0 | 1 rating Rate this file 1 Download (last 30 days) File Size: 2.37 KB File ID: #15957

initializePhysicalConstants.m

by Rob Chambers

 

16 Aug 2007 (Updated 18 Aug 2007)

Creates a structure containing important physical constants (R, k, N_a, g, etc.)

| Watch this File

File Information
Description

initializePhysicalConstants.m loads important physical constants into
 the structure CONSTS. The CONSTS structure will contain both values
 (accessible by CONSTS.var_name), and descriptive information
 (CONSTS.desc.var_name.[Name, Units, Value]).
EXAMPLE USAGE:

    % What are the units of the unversal gas constant?
    CONSTS.desc.R
    ans =
    Name: 'Gas Constant'
    Units: 'J K^-1 mol^-1'
    Value: 8.3140

    % Atoms in 10 grams of oxygen:
    V = 1; %L
    P = 1; % atm
    T = CONSTS.T_o + 20; % K
    nMols = P*V / (CONSTS.R*T)
    nMols =
    4.1030e-004
    % How may atoms?
    nAtoms = nMols * CONSTS.N_a
    nAtoms =
    2.4708e+020

This program can be vastly improved; I'm happy to do so if people
 actually use it. (for example: more constants, database functionality,
 embedded dimensional information...) Just send me an email (see my
 webpage.)

Created: Rob Chambers
          http://www.stanford.edu/~robc1
          8/16/20007

Free to use or modify, just keep my reference info intact.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
19 Aug 2007 John D'Errico

Its a little kludgy. First, its a script that always creates a structure with a fixed name, CONSTS. You need to edit the code to add your own constants, since surely those chosen will not be of interest to you. But, if you must edit the code, creating a cell array inside the code with a very specific format. In that case, why not just build a structure directly in a script?

There is no error checking on whether your cell array had the proper format.

If you want to know the units on a constant, then you need to dive into the description field, which is itself a scructure.

>> initializePhysicalConstants
>> CONSTS
CONSTS =
     N_a: 6.022e+23
    desc: [1x1 struct]
       k: 1.381e-23
       e: 1.602e-19
       F: 96480
       R: 8.314
     e_o: 8.854e-12
       g: 9.807
     p_o: 101300
     T_o: 273.15

The basic idea of a structure with your constants all in one place is not bad, or you might write it as a function, setting the constants as prefs, or use a function handle.

20 Aug 2007 Rob Chambers

John--very helpful comments, thanks. This is def. not the most robust way to do things, but as the m-file says, if people use the code I'm happy to improve it. Just a couple of points:
- These are all *very* important physical constants in every field of science/engineering; In many varied classes I've taken, at least 50% of the constants I need are contained in the list.

- The reason I didn't make this a function is that when CONSTS is loaded into your workspace, you can use the TAB functionality to explore the structure and find the variable you need.

It's nothing complicated, but for doing quick-and-dirty eng. calculations in matlab, I've found it to be very useful.

-Rob

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
chemistry Rob Chambers 22 Oct 2008 09:23:07
physics Rob Chambers 22 Oct 2008 09:23:07
physical constants universal gas constant boltzmann faraday perm Rob Chambers 22 Oct 2008 09:23:07

Contact us at files@mathworks.com