Variables Sheet
(Last modified: June 21, 2009)

The Variables sheet is opened by clicking on the Variables button of the Spreadsheet window. This sheet is where you define variables that you can use elsewhere, such as in the spread sheet or parameters in the other sheets.

Variables are values that you might use often. For example, you could specify a variable called "height," which you can use in multiple places in the spreadsheet. If you want to change the "height" of your antenna, all you need to do is to change the value of "height" in the Variables table and every spreadsheet cell that uses the "height" variable will change with it.

vars

The name of a variable must begin with either an alphabet or with the underscore character. The rest of the name should consist of alphabets, numbers or the underscore character. Spaces are not allowed inside a variable name. Upper case characters are unique from lower case characters.

The value of a variable is a numerical constant. Formulas (such a 2*pi) are not allowed here. The values are either dimensionless or in meters. However you can modify the meaning of a value by including the inches, feet and AWG designators (see the section on constants in Formulas).

The comment for a variable can be empty or can be some notes that you keep for yourself. cocoaNEC does not use this information, but it will be saved together with the rest of the antenna model and can serve as a reminder of what the variable stands for in the future.

Examples of variables are shown below:

varr

You use the + (plus) below the variables table to add a new variable.

If there is no selection in the table when you click on the + button, a variable will be added to the top of the table. If you have selected a row in the table, the variable will be added below the selected row.

You remove a variable by selecting the row the variable is in and clicking on the - (minus) button.

Click on the Close button to close the Variables sheet.


Reserved words

There are some names that are reserved by cocoNEC and cannot be used as spreadsheet variables. These are the names of NC types (int, real, float, element, vector, transform), NC operators (e.g., if, while, repeat, break) and NC functions (e.g., wire, line, helix_, vect, sqrt, cos, etc).



Formulas

You can use formulas rather than simple numbers in many of cocoaNEC's input fields.

The exception to this are the fields in the Environment window, the Variables window, the Networks window and the Output Control window, where numerical values have to be specified as simple numbers.

A formula consists of constants, variables and functions that are stringed together with arithmetical operators.

The simplest formula is just a simple numerical constant, such as 2 or 3.1415926.

You can use a unary minus ahead of a formula to negate the value of the constant, e.g., -5 would evaluate to a negative 5.

The following operations can be used in a formula:

+ (add)
- (subtract)
* (multiply)
/ (divide)
% (mod -- the integer parts of the two operands are first taken before computing the mod function).

Furthermore, you can use parentheses to nest formulas, e.g.,

(1-3)*(2+2)

You can use variables anywhere that you can use a constant. For example

(height-3)*(length+width)

You can also use functions anywhere that you can use constants and variables. For example, the formula

cos(theta)*(halfwidth + (#10)*2 )

takes the cosine of the variable theta and multiplies it by the sum of the halfwidth variable and the diameter of a #10 AWG wire.

The expression analyzer in cocoaNEC takes a formula, looks up the values for the variables that are used in the formula, evaluates the formula and returns a simple number.


Constants

Constants can either be integers or numbers with decimals, e.g.

3
2.71828

For numbers that are very large or very small, you can use the standard floating point with exponent representation, for example 0.35E+2 is 0.35 times 10 to the power of 2, or 35.

0.56E-2 is 0.56 times ten to the power of -2, or 0.0056.

In cocoaNEC, you can use a ' (the single quote character) after a number to apply a feet-to-meters conversion of the constant. 6' will evaluate to a value of 1.8288 (6 feet in meters).

A " (the double quote character) after a number is used to apply an inch-to-meters conversion. 1" will evaluate to 0.0254 (meters).

You cannot mix feet and inches, so 1'6" is not allowed, but 1.5' and 18" are allowed. You can mix constants with the feet conversion and the inches conversion in a nested formula. (1'+6") will have the same value as 18", and both will evaluate to a value to 0.4572 (meters).

In addition, you can use a # (the pound or octathorp character) as the prefix to an integer to indicate the radius of an American Wire Gauge (AWG) wire size. #12 will evaluate to 0.00010261 (meters).


Variables

A variable in cocoaNEC is a placeholder for a constant. A variable allows you to use the same constant in multiple places and allow to change all instances of the constant by changing the variable definition. A variable is defined in the Variables table.

The name of a variable must either begin with an alphabet or begin with the underscore character. The rest of the name consists of alphabets, numbers or the underscore character. Spaces are not allowed inside a variable name. Upper case characters are unique from lower case characters. width, Width and _Width are all different variables.


Predefined Variables

There are some predefined variables in cocoaNEC. These "variables" are

g_frequency
g_wavelength
g_dielectric
g_conductivity

They represent these values: frequency in MHz, its corresponding wavelength in meters, ground dielectric constant and ground conductivity. You can use these predefined variables any place where you can use regular variables.

In addition, there are a couple of constants,

g_pi
g_c

g_pi is the value of pi (3.1415926...) and g_c is the speed of light in millions of meters per second (298.792...). You can use g_c to convert between wavelength in meters and frequency in MHz.


Functions

The following trigonometric functions are implemented in cocoaNEC:

sin
cos
tan
asin
acos
atan
atan2

asin, acos, atan are the arcsine, arccosine and arctangent. All of the trigonometric functions (except for the atan2 function) take a single argument in parantheses.

The atan2 function takes the arctangent of two arguments. atan2( y,x ) is the same as atan( y/x ) if x is not zero and when the vector (x,y) falls in the first quadrant.

The argument of the trigonometric functions, and the result of the inverses are expressed in radians. If you want to use degrees, there is a corresponding set of functions that work in units of degrees:

sind
cosd
tand
atand
atan2d

In addition to the trigonometric functions, cocoaNEC supports the following hyperbolic functions:

sinh
cosh
tanh
asinh
acosh
atanh

cocoaNEC also has functions for taking powers and logarithms:

sqrt
pow
exp
log
log10

sqrt returns the square root of the argument of the function.

pow takes two arguments and raises the first argument to the power of the second argument , pow( x, 0.5 ) is the same as sqrt( x ), for example.

exp is the exponential function and log is the natural logarithms (in cocoaNEC, you can also use the function ln, both log and ln evaluate to the same result). log10 is log to the base 10.

Next: Network Sheet...