Home > atmlab > physics > constants.m

constants

PURPOSE ^

CONSTANTS Phyiscal and math constants

SYNOPSIS ^

function [const,unit] = constants(name)

DESCRIPTION ^

 CONSTANTS   Phyiscal and math constants

    This function returns physical constants. It gives an 
    error message, if the constant is not defined. If no constant is
    given, the function's list of available constants are shown.

    The following constants are defined:
        
       AVOGADRO                   [1/mol]
       BOLTZMANN_CONST            [J/K]
       CBGR                       [K] Temperature of cosmic background 
                                      radiation 
       DEG2RAD                    [rad] Conversion from degrees to radians
       EARTH_MASS                 [kg] Mass of the earth.
       EARTH_RADIUS               [m] Equatorial radius of the earth.
       EARTH_RADIUS_MEAN          [m] Mean radius of the earth.
       EARTH_STANDARD_GRAVITY     [m/s^2] As defined from CGPM in m/s^2
       EARTHORBIT_RADIUS          [m] Radius of the Earth orbit, around the Sun
       GAS_CONST                  [J.K-1.mol-1] Universal gas constant.
       GAS_CONST_DRY_AIR          [J.kg-1e4.K-1] Gas constant for dry air
     
       GAS_CONST_WATER_VAPOR      [J.kg-1.K-1] Gas constant for water vapor
       GRAVITATIONAL_CONSTANT     [m3.kg-1.s-3] The gravitational constant, G
       LATENT_HEAT_VAPORIZATION   [J.kg-1] Latent heat of vaporization of
                                           water vapor (at 373.15K)

       LATENT_HEAT_VAPORIZATION_273 [J.kg-1] Latent heat of vaporization of
                                           water vapor at 273K
       NAUTICAL_MILE              [m] 1 nautical mile 
       PLANCK_CONST               [Js]
       RAD2DEG                    [deg] Conversion from radians to degrees
       SPECIFIC_HEAT_CP_DRY_AIR   [J.kg-1.K-1] Specific heat at constant 
                                               pressure, at sea level and 0C
       SPECIFIC_HEAT_CV_DRY_AIR   [J.kg-1.K-1] Specific heat at constant 
                                               pressure 
       SPEED_OF_LIGHT             [m/s]
       STEFANBOLTZMANN            [J.K-1.m-2.s-1] Total blackbody emission
                                                  is STEFANBOLTZMANN*T^4
       SUN_RADIUS                 [m] Sun radius
        
 FORMAT   [const,unit] = constants(name)

 OUT   const   Value of the constant.
       unit    String name of the associated unit.

 IN    name    Name of the constant (if empty, the list of constants 
               are shown).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

constants.m

SOURCE CODE ^

0001 % CONSTANTS   Phyiscal and math constants
0002 %
0003 %    This function returns physical constants. It gives an
0004 %    error message, if the constant is not defined. If no constant is
0005 %    given, the function's list of available constants are shown.
0006 %
0007 %    The following constants are defined:
0008 %
0009 %       AVOGADRO                   [1/mol]
0010 %       BOLTZMANN_CONST            [J/K]
0011 %       CBGR                       [K] Temperature of cosmic background
0012 %                                      radiation
0013 %       DEG2RAD                    [rad] Conversion from degrees to radians
0014 %       EARTH_MASS                 [kg] Mass of the earth.
0015 %       EARTH_RADIUS               [m] Equatorial radius of the earth.
0016 %       EARTH_RADIUS_MEAN          [m] Mean radius of the earth.
0017 %       EARTH_STANDARD_GRAVITY     [m/s^2] As defined from CGPM in m/s^2
0018 %       EARTHORBIT_RADIUS          [m] Radius of the Earth orbit, around the Sun
0019 %       GAS_CONST                  [J.K-1.mol-1] Universal gas constant.
0020 %       GAS_CONST_DRY_AIR          [J.kg-1e4.K-1] Gas constant for dry air
0021 %
0022 %       GAS_CONST_WATER_VAPOR      [J.kg-1.K-1] Gas constant for water vapor
0023 %       GRAVITATIONAL_CONSTANT     [m3.kg-1.s-3] The gravitational constant, G
0024 %       LATENT_HEAT_VAPORIZATION   [J.kg-1] Latent heat of vaporization of
0025 %                                           water vapor (at 373.15K)
0026 %
0027 %       LATENT_HEAT_VAPORIZATION_273 [J.kg-1] Latent heat of vaporization of
0028 %                                           water vapor at 273K
0029 %       NAUTICAL_MILE              [m] 1 nautical mile
0030 %       PLANCK_CONST               [Js]
0031 %       RAD2DEG                    [deg] Conversion from radians to degrees
0032 %       SPECIFIC_HEAT_CP_DRY_AIR   [J.kg-1.K-1] Specific heat at constant
0033 %                                               pressure, at sea level and 0C
0034 %       SPECIFIC_HEAT_CV_DRY_AIR   [J.kg-1.K-1] Specific heat at constant
0035 %                                               pressure
0036 %       SPEED_OF_LIGHT             [m/s]
0037 %       STEFANBOLTZMANN            [J.K-1.m-2.s-1] Total blackbody emission
0038 %                                                  is STEFANBOLTZMANN*T^4
0039 %       SUN_RADIUS                 [m] Sun radius
0040 %
0041 % FORMAT   [const,unit] = constants(name)
0042 %
0043 % OUT   const   Value of the constant.
0044 %       unit    String name of the associated unit.
0045 %
0046 % IN    name    Name of the constant (if empty, the list of constants
0047 %               are shown).
0048   
0049 
0050 % 2002-12-12   Created by Claudia Emde and Patrick Eriksson.
0051 % 2011-12-7    modified by Salomon Eliasson
0052 % 2014-02-12   miodified by Carlos Jimenez
0053 %               'GAS_CONST_DRY_AIR' from 287.040 to 287.058
0054 
0055 % $Id: constants.m 8778 2014-02-12 13:27:55Z carlos $
0056 
0057 % constants that changed values since 2011-12-7
0058 %
0059 %Boltzmann_const
0060 %1.380662e-23 -> 1.3806488e-23
0061 % Planck constant
0062 % 6.626180e-34 -> 6.62606957e-34
0063 % Avogadro constant
0064 % 6.0225e23 -> 6.02214129e23
0065 % CBGR
0066 % 2.735 -> 2.725
0067 % EARTH_RADIUS
0068 % 6.378e6 -> 6.3781e6 (and write that this is the equatorial radius)
0069 % EARTHORBIT_AXIS
0070 % 1.495e11 -> 1.49598261e11 (aplies to the semi-maxis axis of the
0071 %                            orbit (1.00000261AU)
0072 % SUN_RADIUS
0073 % 6.960e8 -> 6.955e8
0074 % DEG2RAD
0075 % 0.01745329251994 -> pi/180
0076 % RAD2DEG
0077 % 57.2957795130823 -> 180/pi
0078 % GAS_CONST_DRY_AIR
0079 % 287-> 287.04
0080 % SPECIFIC_HEAT_CONST_PRES
0081 % 1005 -> 1003.5
0082 % LATENT_HEAT_VAPORIZATION
0083 % This is not a constant, but depends on the temperature
0084 
0085 function [const,unit] = constants(name)
0086 
0087 % You can add new constants here. The names should be self-explanatory
0088 % and the constants are sorted alphabetically. You also have to add the
0089 % name of the constant in the help section above, so that the help command
0090 % gives out a complete list of constants. Aslo add their name to the
0091 % subfunction below so they will be included in the output structure of all
0092 % available constants (if nargin ==0). In the switch case, remember to also
0093 % list along with the constant's value, its unit, and a reference.
0094 
0095 if nargin ==0
0096     const = ifnargin0;
0097     return
0098 end
0099    
0100 switch name
0101 
0102 case 'AVOGADRO'
0103     %ref: http://physics.nist.gov/cgi-bin/cuu/Value?na|search_for=avogadro
0104     const = 6.02214129e23;
0105     unit  = 'mol^{-1}';
0106     
0107 case 'BOLTZMANN_CONST'
0108     %ref: http://en.wikipedia.org/wiki/Boltzmann_constant
0109     const = 1.3806488e-23;
0110     unit  = 'JK^{-1}';
0111     
0112 case 'CBGR'
0113     %ref: http://en.wikipedia.org/w/index.php?title=Cosmic_background_radiation&oldid=480943337
0114     const = 2.725;
0115     unit = 'K';
0116     
0117 case 'DEG2RAD'
0118     const = pi/180;
0119     unit = 'rad';
0120     
0121 case 'EARTH_MASS'
0122     %ref: http://en.wikipedia.org/wiki/Earth_mass
0123     const = 5.97219e24;
0124     unit  = 'kg';
0125  
0126  case 'EARTH_RADIUS'
0127     %ref: http://en.wikipedia.org/wiki/Earth (equatorial radius)
0128     const = 6.3781e6;
0129     unit  = 'm';
0130     
0131 case 'EARTH_RADIUS_MEAN'
0132     %ref: http://en.wikipedia.org/wiki/Earth (mean radius)
0133     const = 6.371e6;
0134     unit  = 'm';
0135     
0136 case 'EARTH_STANDARD_GRAVITY'
0137     % ref: http://en.wikipedia.org/wiki/Standard_gravity
0138     const = 9.80665;
0139     unit  = 'ms^{-2}';
0140         
0141 case 'EARTHORBIT_RADIUS'
0142     % ref: http://en.wikipedia.org/wiki/Earth (Semi-major axis)
0143     const = 1.49598261e11;
0144     unit  = 'm';
0145     
0146 case 'GAS_CONST'
0147     %ref: http://en.wikipedia.org/wiki/Gas_constant
0148     const = 8.3144621;
0149     unit  = 'JK^{-1}mol{-1}';
0150     
0151 case 'GAS_CONST_DRY_AIR'
0152     %ref: http://en.wikipedia.org/wiki/Gas_constant
0153     const = 287.058;
0154     unit  = 'Jkg^{-1}K^{-1}';
0155     
0156 case 'GAS_CONST_WATER_VAPOR'
0157     % ref: http://en.wikipedia.org/wiki/Water_vapor
0158     const = 461.5; 
0159     unit  = 'Jkg^{-1}K^{-1}';
0160     
0161  case 'GRAVITATIONAL_CONSTANT'
0162     % ref: http://prl.aps.org/abstract/PRL/v111/i10/e101102
0163     % (This value is slightly higher than te ne given by eg. Wikipedia, but
0164     % is a new measurement (2013) that should be more accurate.)
0165     const = 6.67545e-11;
0166     unit  = 'm^3kg^{-1}s^{-2}';
0167  
0168  case 'LATENT_HEAT_VAPORIZATION'
0169     % ref: http://en.wikipedia.org/wiki/Enthalpy_of_vaporization
0170     error(['atmlab:' mfilename ':notConstant'],....
0171         ['The latent heat vaporization is a strong function of temperature.\n',...
0172         'Use ''LATENT_HEAT_VAPORIZATION_273'' for the correct value at 273.15 degress celcius'])
0173     const = 2257e3;
0174     unit  = 'Jkg^{-1}';
0175  
0176 case 'LATENT_HEAT_VAPORIZATION_273'
0177     %http://en.wikipedia.org/w/index.php?title=Water_%28data_page%29&oldid=487536389
0178     const = 2496.5e3;
0179     unit  = 'Jkg^{-1}';
0180     
0181 case 'NAUTICAL_MILE'
0182     % ref: http://en.wikipedia.org/wiki/Nautical_mile
0183     const = 1852;
0184     unit  = 'm';
0185     
0186 case 'PLANCK_CONST'
0187     %ref: http://en.wikipedia.org/wiki/Planck_constant
0188     const = 6.62606957e-34;
0189     unit  = 'Js';
0190     
0191 case 'RAD2DEG'
0192     const = 180/pi;
0193     unit = 'deg';
0194 
0195 case 'SPECIFIC_HEAT_CP_DRY_AIR'
0196     %ref: 56
0197     const = 1003.5; 
0198     unit  = 'Jkg^{-1}K^{-1}';
0199     
0200 case 'SPECIFIC_HEAT_CV_DRY_AIR'
0201     % ref:
0202     const = 718;
0203     unit  = 'Jkg^{-1}K^{-1}';
0204     
0205 case 'SPEED_OF_LIGHT'
0206     %ref: http://en.wikipedia.org/wiki/Speed_of_light
0207     const = 2.99792458e8;
0208     unit  = 'ms^{-1}';
0209     
0210 case 'STEFANBOLTZMANN'
0211     const = 2*pi^5*constants('BOLTZMANN_CONST')^4 / ...
0212                 (15*constants('PLANCK_CONST')^3*constants('SPEED_OF_LIGHT')^2);
0213     unit = 'JK^{-4}m^{-2}s^{-1}';
0214 
0215 case 'SUN_RADIUS'
0216     % ref: http://en.wikipedia.org/wiki/Sun
0217     const = 6.955e8;
0218     unit  = 'm';
0219 
0220 otherwise
0221     error(['atmlab:' mfilename ':badInput'],['Unknown constant: ', name])
0222 end      
0223 
0224 % make sure there's something for unit
0225 if ~exist('unit','var'), unit = ''; end
0226 
0227 
0228 
0229 
0230 function const_struct = get_constants_struct
0231 % A structure with the same information as the switch case (+units)
0232 
0233 name  = { ...
0234     'AVOGADRO', 'BOLTZMANN_CONST', 'CBGR', 'DEG2RAD', ...
0235     'EARTH_MASS', 'EARTH_RADIUS', 'EARTH_RADIUS_MEAN', ...
0236     'EARTH_STANDARD_GRAVITY', 'EARTHORBIT_RADIUS',...
0237     'GAS_CONST', 'GAS_CONST_DRY_AIR', 'GAS_CONST_WATER_VAPOR', ...
0238     'GRAVITATIONAL_CONSTANT', ...
0239     'LATENT_HEAT_VAPORIZATION_273', 'NAUTICAL_MILE', 'PLANCK_CONST', 'RAD2DEG',...
0240     'SPECIFIC_HEAT_CP_DRY_AIR', 'SPECIFIC_HEAT_CV_DRY_AIR', ...
0241     'SPEED_OF_LIGHT', 'STEFANBOLTZMANN', 'SUN_RADIUS' ...
0242 };
0243 
0244 value = cell(1,length(name));
0245 unit  = cell(1,length(name));
0246 
0247 for i = 1:length(name)
0248     [value{i},unit{i}] = constants(name{i});
0249 end
0250 
0251 const_struct = struct('name',name,'value',value,'unit',unit);
0252 
0253 
0254 
0255 
0256 function const_struct = ifnargin0
0257 % if you only want to see what constants there are
0258 
0259 const_struct = get_constants_struct;
0260 fprintf('The constants listed in this function are:\n\n')
0261 for i = 1:length(const_struct),
0262     fprintf('%s = %d [%s]\n',...
0263         const_struct(i).name,const_struct(i).value,const_struct(i).unit);
0264 end
0265 fprintf('\nUSAGE: e.g. 6378000 = constants(''EARTH_RADIUS'') or\n')
0266 fprintf('USAGE: e.g. [6378000,''m''] = constants(''EARTH_RADIUS'')\n')

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005