• No results found

Scalar and vector attributes

In document DEVICE Reference Guide (Page 148-200)

It is possible to add both scalar and vector attributes to datasets.

Scalar

The command

R.addattribute("R",reflection); # add reflection attribute adds a scalar quantity 'R' to a dataset with the same name. To access the 'R' raw data, use:

R.R;

Vector

The command

E.addattribute("E",Ex_raw,Ey_raw,Ez_raw); # add vector E field attribute

adds a vector quantity 'E' to a dataset with the same name. In this case, we can access the raw 'E' data in the following ways:

E.Ex; # get Ex component E.Ey; # get Ey component E.Ez; # get Ez component E.E2; # get |E|^2

E.E; # get all components in a single matrix. An extra dimension of length 3 will be added to the matrix, for each vector component.

See Also

rectilineardataset , addattribute , addparameter , visualize , datasets ,

getparameter , getattribute , matrixdataset , struct

7.2.29 struct

The script command struct adds an unstructured dataset. Any data type (such as matrix, string, dataset) can be added to struct objects.

139 140 140 203 141

Syntax Description

a = struct; Creates an unstructured dataset. a.a = "string"; Adds a string field to the structure.

a.b = matrix(5,5); Adds a field of matrix of 5x5 to the structure.

See Also

Datasets , matrixdataset , rectilineardataset , cell

7.2.30 cell

The script command cell creates a cell array variable with specified number of elements. The cell array element can be any data type, such as matrix, string, and dataset.

Syntax Description

a = cell(n); Creates a cell array with n elements.

a{n} = "string"; Adds a string to the specified element of the cell array. a{n} = matrix(5,5); Adds a field of matrix of 5x5 to the specified element of the

cell array.

See Also

Datasets , matrixdataset , rectilineardataset , struct , splitstring

7.2.31 unstructureddataset

Unstructureddataset script command creates an empty dataset that is associated with arbitrary x/y/z coordinate in space, and with additional matrix, a connectivity matrix to connect them. The connectivity matrix comes after x, y, and z. Like rectilinear datasets, unstructured datasets can be parameterized, and can contain an arbitrary number of attributes (see addattribute) and parameters (see addparameter) .

See Dataset introduction for more information.

For datasets that are not associated with the x/y/z coordinates (ex. transmission as a function of frequency), see matrixdataset .

Syntax Description

unstructureddataset(x,y,z, C);

Creates a empty rectilinear dataset associated with the coordinates x/y/z and a connectivity matrix to connect

141 139 139 147

141 139 139 146 178

140 140

141

them.

See Also

rectilineardataset , addattribute , addparameter , visualize , datasets ,

getparameter , getattribute , matrixdataset , struct

7.3

Operators

Standard mathematical and string operators.

Algebraic operators Command Description * Multiplication. Ex: y = x * z; / Division. Ex: y = x / z; + Addition. Ex: y = x + z; - Subtraction. Ex: y = x – z; - Negative. Ex: y = -x; ^ Power. Ex: y = x^3;

In expression A^B, if B is complex, the phase of A is evaluated from - to .

Logical and relational operators

Command Description

== Comparison.

almostequal Almost equal comparison operator.

!= Not equal.

<= Less than or equal to.

>= Greater than or equal to.

< Less than. > Greater than. & AND. and AND. | OR. 139 140 140 203 141 140 141 139 146 150 150 150 150 150 151 151 151 152 152 152 153 153 153 153 154

or OR.

! NOT.

~ NOT.

Dataset operators

Command

Description

. Retrieve the parameters and attributes of datasets.

String operators

Command

Description

" Create a string variable.

' Create a string variable.

+ Add strings

endl end of line character.

Output to screen

Command Description

? Display output on screen.

# script file comments Comment script files with #

7.3.1 .

The dot operator can be used to retrieve the parameters and attributes of datasets.

Syntax Description

result = A.result; Retrieves the parameter or attribute "result" from the existing dataset A. The result is a scalar matrix.

See Also

matrixdataset , rectilineardataset , getparameter , getattribute , visualize

154 154 155 149 155 156 150 157 157 157 139 139 140 141 203

7.3.2 *

Multiplication. When applied to matrices, this operator does simple element by element multiplication, not matrix multiplication.

Syntax Description y = x * z; Multiply x and z. See Also Operators , * , / , + , - , ^ , mult

7.3.3 /

Division. Syntax Description y = x / z; Divide x by z. See Also Operators , * , / , + , - , ^

7.3.4 +

Addition. Syntax Description y = x + z; Add x and z.

y = string1 + string2; Concatenate strings together.

See Also Operators , * , / , + , - , ^

7.3.5 -

Subtraction, or negative. Syntax Description y = x - z; Subtract z from x. y = -x; Negative 148 150 150 150 150 151 169 148 150 150 150 150 151 148 150 150 150 150 151

See Also

Operators , * , / , + , - , ^

7.3.6 ^

Power. In expression A^B, if B is complex, the phase of A is evaluated from - to .

Syntax Description

y = x^3; x cubed.

See Also

Operators , * , / , + , - , ^

7.3.7 ==

Logical comparison. This operators can be used with complex numbers and strings.

Syntax Description

out = y == x; Returns 1 if x and y are equal. Returns 0 otherwise.

See Also

Operators , = , almostequal , != , <= , >= , < , > , & , and , |

, or , ! , ~

7.3.8 almostequal

Almost equal comparison operator. When using floating point numbers (rather than integers), two values that are meant to be equal may not be exactly equal due to rounding errors that are always present in floating point calculations. In such cases, the almost equal function can be useful.

Syntax Description

out = almostequal(A, B); Returns 1 if A - B is less than or equal to A + B /2*1e- 15. Returns 0 otherwise.

out = almostequal(A, B, relative diff);

Returns 1 if A - B is less than or equal to A + B /2 times relative diff. Returns 0 otherwise.

out = almostequal(A, B, relative diff, absolute diff);

Returns 1 if A - B is less than or equal to A + B /2 times relative diff or if A - B is less than or equal to absolute diff. Returns 0 otherwise.

148 150 150 150 150 151

148 150 150 150 150 151

148 132 151 152 152 152 153 153 153 153 154

See Also

Operators , = , == , != , <= , >= , < , > , & , and , | , or , !

, ~

7.3.9 !=

Not equal to comparison operator. Returns 1 if values are not equal. Returns 0 if values are equal. This operator can be used in matrix operations. This operators can be used with complex numbers.

Syntax Description

out = a!=b; If a is not equal to b, then out equals 1. Otherwise out equals 0.

See Also

Operators , == , almostequal , <= , >= , < , > , & , and , | , or

, ! , ~

7.3.10 <=

Logical less than or equal to. Imaginary components of x and y are ignored.

Syntax Description

out = y <= x; Less than or equal to.

See Also

Operators , == , != , almostequal , >= , < , > , & , and , | , or

, ! , ~

7.3.11 >=

Logical greater than or equal to. Imaginary components of x and y are ignored.

Syntax Description

out = y >= x; Greater than or equal to.

See Also

Operators , == , != , <= , almostequal , < , > , & , and , | , or

, ! , ~ 148 132 151 152 152 152 153 153 153 153 154 154 154 155 148 151 151 152 152 153 153 153 153 154 154 154 155 148 151 152 151 152 153 153 153 153 154 154 154 155 148 151 152 152 151 153 153 153 153 154 154 154 155

7.3.12 <

Logical less than. Imaginary components of x and y are ignored.

Syntax Description

out = y < x; Less than.

See Also

Operators , == , != , <= , >= , almostequal , > , & , and , | , or

, ! , ~

7.3.13 >

Logical greater than. Imaginary components of x and y are ignored.

Syntax Description

out = y > x; Greater than.

See Also

Operators , == , != , <= , >= , < , almostequal , & , and , | , or

, ! , ~

7.3.14 &

Logical AND. Imaginary components of x and y are ignored.

Syntax Description

out = y & x; If the real part of either or both of x,y are zero, then return 0. Otherwise return 1.

y and x; Same as &.

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.15 and

Logical AND. Imaginary components of x and y are ignored.

Syntax Description 148 151 152 152 152 151 153 153 153 154 154 154 155 148 151 152 152 152 153 151 153 153 154 154 154 155 148 151 152 152 152 153 153 153 153 154 154 154 155

out = y & x; If the real part of either or both of x,y are zero, then return 0. Otherwise return 1.

y and x; Same as &.

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.16 |

Logical OR. Imaginary components of x and y are ignored.

Syntax Description

out = y | x; If the real part of either or both of x,y is non-zero, then return 1. Otherwise return 0.

y or x; Same as |.

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.17 or

Logical OR. Imaginary components of x and y are ignored.

Syntax Description

out = y | x; If the real part of either or both of x,y is non-zero, then return 1. Otherwise return 0.

y or x; Same as |.

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.18 !

Logical NOT operator. If a value is 0, then NOT returns 1. For all other values, NOT returns 0. NOT(A) is equivalent to A==0, where == is the comparison operator.

Syntax Description 148 151 152 152 152 153 153 153 153 154 154 154 155 148 151 152 152 152 153 153 153 153 154 154 154 155 148 151 152 152 152 153 153 153 153 154 154 154 155

out = !a; applies logical not operator to a out = ~a; applies logical not operator to a

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.19 ~

Logical NOT operator. If a value is 0, then NOT returns 1. For all other values, NOT returns 0. NOT(A) is equivalent to A==0, where == is the comparison operator.

Syntax Description

out = !a; applies logical not operator to a out = ~a; applies logical not operator to a

See Also

Operators , == , != , <= , >= , < , > , & , and , | , or , ! , ~

7.3.20 "

String operator. Strings can be created with single or double quotes.

The following escape sequences are recognized when creating strings with double quotes: \" double quotes in string

\n newline (linefeed) character in string \\ backslash in string

Syntax Description

out="my string"; use double quotes to create strings

NOTE: Literal back slashes and double quotes

It is always possible to create a literal backslash in a string with \\. However, \ also results in a literal backslash, IF it it will not be interpreted as part of an escape sequence (\n, \", \\). This note is important when storing paths in strings.

Suppose we want to create the string C:\Program Files\Lumerical. The following three commands are valid and equivalent:

mystring = 'C:\Program Files\Lumerical'; # use single quotes

148 151 152 152 152 153 153 153 153 154 154 154

155

148 151 152 152 152 153 153 153 153 154 154 154

mystring = "C:\Program Files\Lumerical"; # use double quotes mystring = "C:\\Program Files\\Lumerical"; # use double quotes and \\ escape character

However, suppose we want to create the string C:\Program Files\Lumerical\. The only difference is the additional backslash at the end of the string. The following two commands are valid and equivalent:

mystring = 'C:\Program Files\Lumerical\'; # use single quotes

mystring = "C:\\Program Files\\Lumerical\\"; # use double quotes and \\ escape character

The other potential command, where we use a single backslash, is not valid syntax and will result in an error.

mystring = "C:\Program Files\Lumerical\"; # use double quotes

The problem is that the script interpreter will interpret the final \" as an escape character for a literal double quote, rather than as a single backslash and a closing double quote. When interpreted this way, the command results in a syntax error because there is no double quote character closing the string.

See Also

Operators , ' , num2str , + , endl , write , eval

7.3.21 '

String operator. Strings can be created with single or double quotes.

The following escape sequences are recognized when creating strings with single quotes: '' single quote in string (two single quote characters)

Syntax Description

out='my string'; use single quotes to create strings

See Also

Operators , " , num2str , + , endl , write , eval

148 156 175 150 157 123 176

7.3.22 endl

Add an end of line character to a string

Syntax Description

out = "line1"+endl+"line2"; Add an end of line character to the string.

See Also

Operators , num2str , + , " , write

7.3.23 ?

Print output to the screen. Use the format script command to change the precision of the output.

Syntax Description

?command; Displays the output of the command on the screen This function does not return any data.

See Also

System level , write , format , #

7.3.24 comments

Use the # character to comment script files. Anything after the # character is ignored. The comments are not displayed when the script file is run. Comments can not be used when typing commands directly into the script prompt.

Syntax Description

x=1; # set x to 1 Anything after the # character is ignored.

See Also System level

7.4

Functions

Standard mathematical and matrix functions.

Trigonometric and complex

Command Description

sin Trigonometric sin function.

148 175 150 155 123

109 123 121 157

109

cos Trigonometric cos function.

tan Trigonometric tan function.

asin Inverse trigonometric sin function.

acos Inverse trigonometric cos function.

atan Inverse trigonometric tan function.

atan2 Same as atan, but returns angle in correct quadrant.

real Returns the real part of variable

imag Returns the imaginary part of variable

conj Complex conjugate

abs Absolute value

angle Phase of a complex number.

unwrap Removes phase difference of more than 2

Logarithmic, exponential and power

Command Description

log The natural logarithm. Input can be complex or negative.

log10 The log, base 10. Input can be complex or negative.

sqrt The square root.

exp The exponential.

Matrix functions

Command Description

size Returns the dimensions of a matrix.

length Returns the total number of elements in a matrix.

pinch Remove singleton dimensions from a matrix.

sum The sum of a matrix.

max The max value in a matrix.

min The min value in a matrix.

162 162 162 163 163 163 164 164 164 164 165 165 165 165 166 166 166 166 167 167 168 168

dot The dot product of two vectors.

cross The cross product of two vectors.

flip Flip a matrix in one dimension.

interp Linear interpolation function.

spline Cubic spline interpolation.

integrate Integrate a matrix.

integrate2 Integrate a matrix, ignore singleton dimensions.

find Find values that satisfy a condition in a matrix.

findpeaks Find peaks in a matrix.

transpose Transpose a matrix.

ctranspose Transpose a matrix, and do complex conjugate.

mult Perform matrix multiplication of two or more matrices.

reshape Reshape the matrix to have different dimensions

conserving the overall product of the dimensions.

eig Calculate the eigenvalues and/or eigenvectors of a matrix.

permute Rearrange the dimensions of a matrix.

inv Calculate the inverse of a matrix.

mean Return the mean value of a matrix

var Returns the variance

std Returns the standard deviance

mapfind Returns a string value associated to specified point, given a file containing a map of values to a string

See also

Manipulating variables String functions

Command Description

num2str Convert number to a string.

168 168 170 171 172 173 173 174 174 175 175 169 170 169 170 171 192 193 194 194 130 175

str2num Convert a string into a floating point number.

eval Execute string containing Lumerical scripting language.

feval Run a Lumerical script file.

length Returns the total length of the string.

substring Returns a substring of a string, as a specified position and length.

findstring Returns the position of a substring in a string.

replace Replaces a part of a string with another, at a

specified position.

replacestring Replaces all instances of a substring with another string.

splitstring Split a single long string into a cell (string) array based on a delimiting character.

Frequency and time-domain

Command Description

fft Fast Fourier transform.

fftw Returns the angular frequency vector.

fftk Returns the spatial wavevector kx.

invfft Inverse fft.

czt Chirped z-transform.

Line and polygon functions

Command Description

polyarea Returns the area of a polygon.

centroid Returns the center of mass of a polygon.

polyintersect Determines if two polygons intersect.

inpoly Determines if a series of points are inside our outside a polygon.

polygrow Grows or shrinks a polygon by a specified amount.

polyand Combines two polygons into one with an and

176 176 176 166 176 177 177 178 178 178 180 181 182 183 183 184 184 185 185 186

operation.

polyor Combines two polygons into one with an or

operation.

polyxor Combines two polygons into one with a xor

operation.

lineintersect Returns the intersection of line segments.

linecross Determines if line segments cross each other.

Miscellaneous

Command Description

ceil Round up.

floor Round down.

mod Modulus after division.

round Rounds to the nearest integer.

rand Returns a uniformly distributed random number between 0 and 1.

lognrnd Returns a lognormal distributed random number.

randn Returns a normally distributed random number.

randreset Resets the random number seed.

finite Determines if a number is finite or NaN.

solar Returns the solar power spectrum

stackrt Calculates reflection and transmission of multi-layer stacks

all Returns 1 if all of the specified matrix entries are nonzero and returns 0 otherwise.

any Returns 1 if any of the specified matrix entries are nonzero and returns 0 otherwise.

quadtri Returns approximated integration (first order

quadrature) of data on a 2D finite element mesh. precision Returns truncated value to a user specified precision.

186 187 187 188 188 188 189 189 190 190 190 191 191 191 192 192 193 195

7.4.1 sin

Trigonometric sine function. Angle units are in radians. Function is defined for complex angles. Phase of a complex number is evaluated between - and .

Syntax Description

out = sin(x); Returns the complex sine of x.

See Also

Functions , asin

7.4.2 cos

Trigonometric cosine function. Angle units are in radians. Function is defined for complex angles. Phase of a complex number is evaluated between - and .

Syntax Description

out = cos(x); Returns the complex cosine of x.

See Also

Functions , acos

7.4.3 tan

Trigonometric tangent function. Angle units are in radians. Function is defined for complex angles. Phase of a complex number is evaluated between - and .

Syntax Description

out = tan(x); Returns the complex tangent of x.

See Also

Functions , atan , atan2

7.4.4 asin

Inverse trigonometric sine function. Angle units are in radians. Function is defined for complex values. Phase of a complex number is evaluated between - and . If x is complex, or abs(x) > 1, the following equation is used:

asin(x) = -i ln( ix + sqrt(1-x^2))

Syntax Description

157 162

157 163

out = asin(x); Returns the complex arcsine of x.

See Also Functions , sin

7.4.5 acos

Inverse trigonometric cosine function. Angle units are in radians. Function is defined for complex values. Phase of a complex number is evaluated between - and . If x is complex, or abs(x) > 1, the following equation is used:

acos(x) = -i ln( x + i sqrt( 1-x^2))

Syntax Description

out = acos(x); Returns the complex arccosine of x.

See Also

Functions , cos

7.4.6 atan

Inverse trigonometric tangent function. Angle units are in radians. Function is defined for complex values. Phase of a complex number is evaluated between - and . If x is complex, or abs(x) > 1, the following equation is used:

atan(x) = 0.5 i ln( (i+x)/(i-x) )

Syntax Description

out = atan(x); Returns the complex arctangent of x.

See Also

Functions , atan2 , tan

7.4.7 atan2

Inverse trigonometric tangent function, calculates the arctangent of y/x, but returns the angle in the correct quadrant. Angle units are in radians. Function is defined for real values only.

Syntax Description

out = atan2(y,x); x,y must be real.

See Also

157 162

157 162

Functions , atan , tan

7.4.8 real

Returns the real part of a number or matrix.

Syntax Description

out = real(x); Returns the real part of x.

See Also

Functions , imag

7.4.9 imag

Returns the imaginary part of a number or matrix.

Syntax Description

out = imag(x); Returns the imaginary part of x.

See Also

Functions , real , conj

7.4.10 conj

Returns the complex conjugate of a number or matrix.

Syntax Description

out = conj(x); Returns the complex conjugate of x.

See Also

Functions , real , imag

7.4.11 abs

Returns the absolute value of a number or matrix.

Syntax Description

out = abs(x); Returns the absolute value of x.

See Also

Functions , real , imag

157 163 162

157 164

157 164 164

157 164 164

7.4.12 angle

Returns the angle or phase of a complex number or matrix in radians.

Syntax Description

out = angle(x); Returns the phase of x.

See Also

Functions , real , imag , unwrap

7.4.13 unwrap

Removes changes of more than 2 from a 1D array. It can be useful after angle(x) to see phase without discontinuities.

The unwrap function is primarily intended for 1D arrays. Care must be taken when applying it to matrices with more than one dimension.

Syntax Description

out = unwrap(x); Return the values of x without discontinuities.

See Also

Functions , real , imag , angle

7.4.14 log

The natural logarithm. Input can be complex or negative.

Syntax Description

out = log(x); The natural logarithm. Input can be complex or negative.

See Also

Functions , log10

7.4.15 log10

The log, base 10. Input can be complex or negative.

Syntax Description

out = log10(x); The log, base 10. Input can be complex or negative.

See Also Functions , log 157 164 164 165 157 164 164 165 157 165 157 165

7.4.16 sqrt

The square root.

Syntax Description

out = sqrt(x); The square root.

See Also Functions , ^

7.4.17 exp

The exponential.

Syntax Description

out = exp(x); The exponential.

See Also

Functions , log , ^

7.4.18 size

Returns the size of a matrix.

Syntax Description

y = size(x); y is a matrix which shows the dimensions of x.

See Also

Functions , length , flip , transpose

7.4.19 length

Returns the number of elements in a matrix. If the argument is a string, it will return the length of the string.

Syntax Description

y = length(x); y the number of elements in a matrix. For example, if x is an n by m matrix, y = length( x ) = n * m.

See Also

Functions , size , transpose , flip , substring , findstring , replace ,

157 151

157 165 151

157 166 170 175

replacestring

7.4.20 pinch

Removes all singleton dimensions from a matrix.

Syntax Description

out = pinch(x); Removes all singleton dimensions. For example, if x is a matrix of dimension 1x1x1xM, then

y=pinch(x);

will return a Mx1 matrix where y(i) = x(1,1,1,i);

pinch(x,i); Removes a specified dimension. If x is an NxMxKxP matrix then

y=pinch(x,2);

will return an NxKxP matrix where y(i,j,k) = x(i,1,j,k)

pinch(x,I,j); Removes a specified dimension but keeps a specific index for the dimension being removed. If x is an NxMxKxP matrix then

y=pinch(x,2,4);

will return an NxKxP matrix where y(i,j,k) = x(i,4,j,k)

See Also

Functions , find , size , flip

7.4.21 sum

Sum of elements in a matrix.

Syntax Description

out = sum(x); Sum of all the elements in a matrix, over all dimensions. out = sum(x,2); Sum x over the specified dimension.

See Also

Functions , integrate , mean

178

157 174 166 170

7.4.22 max

The maximum value in a matrix. For complex numbers, only the real part is considered.

Syntax Description

out = max(x); The maximum value in a matrix.

See Also

Functions , min , abs , mean

7.4.23 min

The minimum value in a matrix. For complex numbers, only the real part is considered.

Syntax Description

out = min(x); The minimum value in a matrix.

See Also

Functions , max , abs , mean

7.4.24 dot

Dot product.

Matrix A, B must have the same number of elements. The dot product will be calculated

In document DEVICE Reference Guide (Page 148-200)

Related documents