# Knowledge Base

 Navigation: Scripting Language > Functions var

Returns the variance of all entries of the matrix specified. The variance of a set of N numbers X = [x1,...,xN] is defined as

where μ is the mean of X.

 Supported Product: FDTD, MODE, DEVICE, INTERCONNECT

 Syntax Description out = var(A); Will return variance of all of matrix A, over all dimensions.

Example

These are some simple examples showing how to use this command.

a =[1,2,3,4,5];

?var(a);

result:

b =[1,2,3,4,5; 5,4,3,2,1; 1,4,2,5,8];

?var(b);

?sum((b-mean(b))^2)/length(b); # Compare with equivalent calculation using sum and mean

result:

3.55556

result:

3.55556

d = randmatrix(3,3,3);

?d;

result(i,j,1):

0.345988 0.84698 0.271889

0.471725 0.316874 0.982971

0.374981 0.456099 0.2978

result(i,j,2):

0.739189 0.761315 0.5009

0.567278 0.839442 0.890164

0.19599 0.397656 0.0274667

result(i,j,3):

0.994629 0.531327 0.626759

0.572588 0.194067 0.657613

0.0505081 0.843043 0.197851

?var(d);

result:

0.0753581