help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to create predefined variables


From: Paul Kienzle
Subject: Re: how to create predefined variables
Date: Thu, 11 Dec 2003 06:33:41 -0500

Note that you can get around the namespace issue by having a function,
e.g., C, which returns a structure:

function ret = C (varargin)
static c = Cinit; # no structure constants so can't populate it directly
  if nargin == 0
    ret = c;
  elseif mod(nargin,2)
    usage('C("name",value,...)');
  else
    for i=1:2:nargin,
       if struct_contains(c,varargin{i})
        warning("Replacing definition of constant %s",varargin{i});
       endif
       c.(varargin{i}) = varargin{i+1};
    endfor
  endif
endfunction

function c = Cinit, c.c = 3e8; c.pi=pi; c.R=8.314510; end

You can reference existing constants easily using
        C.c, C.pi, C.R
and add your own using, e.g,
        C('e',e,'i',i,'tol',1e-8)

Anyone want to take ownership of this and add it to octave-forge?

Some outstanding issues:
* An initial list of constants? (e.g., http://physics.nist.gov/cuu/Constants/)
* Do we need to handle a hierarchy of constants?
* How about propagating uncertainties?
* How about propagating units? (e.g., http://www.gnu.org/software/units/units.html) * Can we store and use a description of the constant (e.g., in the help text)?

Paul Kienzle
address@hidden

On Dec 9, 2003 at 6:59am, Paul Kienzle wrote:

pkienz >Date: Tue, 09 Dec 2003 06:59:58 -0500
pkienz >How about
pkienz >
pkienz >function c=R, c=8.314510; end
pkienz >
pkienz >Global scope and no need to declare it anywhere. Of course, I wouldn't
pkienz >choose the name 'R' unless octave supported namespaces.
pkienz >
pkienz >Paul Kienzle
pkienz >address@hidden
pkienz >
pkienz >On Dec 8, 2003, at 8:41 PM, address@hidden wrote:
pkienz >
pkienz >> Hmmm... I'd recommend initializing them as global variables in the
pkienz >> "main" M-file for your Physical Chemistry toolkit:
pkienz >>
pkienz >> http://www.octave.org/doc/octave_10.html#SEC67
pkienz >>
pkienz >> ~Tomer
pkienz >>
pkienz >>
pkienz >>
pkienz >> On Dec 8, 2003 at 7:16pm, xuhaida wrote:
pkienz >>
pkienz >> xuhaid >Hi:
pkienz >> xuhaid > I meet a quetion now. I want to built a physical chemistry
pkienz >> toolkit by
pkienz >> xuhaid >Octave, but how
pkienz >> xuhaid > can I create the constants such as the gas constant
pkienz >> R(8.314510), the
pkienz >> xuhaid >speed of the light, etc
pkienz >> xuhaid >like pi.If not,I have to create these constants for every
pkienz >> function. Can
pkienz >> xuhaid >anybody help me?
pkienz >
pkienz >




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]