This section contains detailed descriptions of the MathViews functions. Each function description contains a synopsis of the calling sequence, a description of how the function operates, an example of usage, and a list of related functions.
Synopsis:
abs(expr)
Description:
The abs function computes the absolute value of its argument.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument. If the argument has complex elements, the complex modulus:
is used to compute the result.
If the argument is a text string, the function converts the text string into its integer equivalent.
Example:
|
INPUT |
OUTPUT |
| a = -5 |
abs(a)
ans = 5 |
| A =
1 -2 -3 3 -1 -3 |
abs(A)
ans = 1 2 3 3 1 3 |
| t = 'MathViews' |
abs(t)
ans = 77 97 116 104 86 105 101 119 115 |
| z = 2 + 3j |
abs(z)
ans = 3.6056 |
Related Topics:
Synopsis:
acos(expr)
Description:
The acos function computes the arccosine (inverse cosine) of its argument, returning a value in radians.
If the argument is a real scalar and the absolute value of the argument is 1.0, the result is a real scalar in the range of [0,]. If the absolute value of the argument is 1.0, the result is a complex scalar.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
If the argument has complex element(s), the complex arccosine:
![]()
is used to compute the result.
Example:
|
INPUT |
OUTPUT |
| A =
1 -2 3 -1 |
acos(A)
ans = 0 3.1416 - 1.317 j 1.7627 j 3.1416 |
| z = 2 + 3 j |
acos(z)
ans = 1.0001 - 1.9834 j |
Related Topics:
cos, cosh, sin, exp, log, log10
Synopsis:
acosh(expr)
Description:
The acosh function computes the hyperbolic inverse cosine of its argument.
Example:
|
INPUT |
OUTPUT |
| acosh([0:0.5:2]) |
ans =
0 + 1.571 j 0 + 1.047 j 0 0.9624 1.317 |
| x=1:0.2:10;
plot(x,acosh(x)),grid |
|
Related Topics:
Synopsis:
all(expr)
Description:
The all function tests whether all the elements of its argument are 1.
If the argument is a vector, then the function returns a 1, providing that all the elements of the argument are nonzero; otherwise a 0 is returned.
If the argument is a matrix, the function operates on each column. The function returns a row vector with elements in the set {0,1} pertaining to the condition of the columns.
Example:
|
INPUT |
OUTPUT |
| x = 1 2 3 4 |
all(x)
ans = 1 |
| y = 1 2 3 0 |
all(x)
ans = 1 |
| A =
1 -2 3 3 -1 0 |
all(A)
ans = 1 1 0 |
Related Topics:
Synopsis:
angle(expr)
Description:
The angle function computes the phase of its argument in radians.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
This function is meaningful for complex arguments as well as real arguments, and it returns a real value in either case.
The phase of real numbers is 0.
Example:
|
INPUT |
OUTPUT |
| z = 3 + 5i |
angle(z)
ans = 1.03038 |
| A = [z,z;z,z] |
angle(A)
ans = 1.03038 1.03038 1.03038 1.03038 |
Related Topics:
Synopsis:
any(expr)
Description:
The any function tests whether any of the elements of its argument is a 1.
If the argument is a vector, the function returns 1, providing that any of the elements of the argument are nonzero; otherwise a 0 is returned.
If the argument is a matrix, the function operates on each column. The function returns a row vector with elements in the set {0,1} pertaining to the condition of the columns.
Example:
|
INPUT |
OUTPUT |
| x = 1 2 3 4 |
any(x)
ans = 1 |
| y = 1 2 3 0 |
any(x)
ans = 1 |
| A =
1 -2 0 3 -1 0 |
any(A)
ans = 1 1 0 |
Related Topics:
Synopsis:
asin(expr)
Description:
The asin function computes the arcsine (inverse sine) of its argument, returning a value in radians.
If the argument is a real scalar and the absolute value of the argument is 1.0, then the result is a real scalar in the range [/2,/2]. If the absolute value of the argument is 1.0, then the result is a complex scalar.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
If the argument has complex element(s), the complex arcsine:
![]()
is used to compute the result.
Example:
|
INPUT |
OUTPUT |
| A =
1 -2 3 -1 |
asin(A)
ans = 1.5708 -1.571 + 1.317 j 1.5708 - 1.7627 -1.571 |
| z = 2 + 3 j |
asin(z)
ans = 0.5707 + 1.9834 j |
Related Topics:
Synopsis:
asinh(expr)
Description:
The asinh function computes the hyperbolic inverse sine of its argument.
Example:
|
INPUT |
OUTPUT |
| asinh([0:0.5:2]) |
ans =
0 0.4812 0.8814 1.195 1.444 |
| x=1:0.2:10;
plot(x,asinh(x)),grid |
|
Related Topics:
Synopsis:
atan(expr)
Description:
The atan function computes the arctangent (inverse tangent) of its argument, returning a value in radians.
If the argument is a real scalar, the result is a real scalar in the range [/2,/2].
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
If the argument has complex element(s), the complex arctangent:
![]()
is used to compute the result.
Example:
|
INPUT |
OUTPUT |
| A =
1 -2 3 -1 |
atan(A)
ans = 0.7854 -1.107 1.249 -0.7854 |
| z = 2 + 3 j |
atan(z)
ans = 1.4099 + 0.2291 j |
Related Topics:
atan2, tan, sin, cos, exp, log
Synopsis:
atan2(expr1,expr2)
Description:
The atan2 function computes the 4th quadrant arc tangent of expr1 ./ expr2, returning a value in radians.
If the argument is a real scalar, the result is in the range [-,+].
If the arguments are two arrays, the function operates on each element of the corresponding arrays:
.
If the argument has complex element(s), the imaginary parts of the complex element(s) is(are) ignored during the computation. Only the real parts are used in the computation.
Example:
|
INPUT |
OUTPUT |
| x = 1 2 3 4
y = 2 4 6 8 |
atan2(x,y)
ans = 0.4636 0.4636 0.4636 0.4636 |
| xc = x + 5i
yc = y + 4j |
atan2(xc,yc)
ans = 0.4636 0.4636 0.4636 0.4636 |
Notice that although both xc and yc are complex vectors, the atan2 function ignores the imaginary parts when computing the arc tangent.
Synopsis:
atanh(expr)
Description:
The atanh function computes the hyperbolic inverse tangent of its argument.
Example:
|
INPUT |
OUTPUT |
| atanh([0 0.5 1.5 2]) |
ans =
0 0.5493 0.8047 + 1.571 j 0.5493 + 1.571 j |
| x=1.2:0.2:10;
plot(x,atanh(x)),grid |
|
Related Topics:
Synopsis:
axis
axis([xmin, xmax, ymin, ymax])
axis('format') ; format can be either square or normal.
Description:
The axis function is used to manually scale the x-y range of a plot.
If axis is called with no argument, it freezes the current displayed plot's dimension for subsequent plots until it is reset or reassigned. The function returns the previous dimensions before the update. Executing the axis function again without an argument resets the plotting procedure to auto-scaling.
If axis is called with an argument, the argument must be a four element vector, consisting of [xmin, xmax, ymin, ymax]. Axis will manually scale the plot to those dimensions, returning the dimensions of the update. To resume auto-scaling, execute the axis function without an argument.
The format string is used to control the aspect ratio of the graphics images. The parameter normal is used to tell MathViews to use the current display device's aspect ratio. The parameter square is used to tell MathViews to auto-adjust to a square aspect ratio. Using the format functions keeps the current state of the axis; i.e. if the current state is auto-scaling, then executing axis('square') keeps the state auto-scaling.
Example:
|
INPUT |
OUTPUT |
| axis |
ans =
0 1 0 1 |
| axis('normal') |
Axis Fixed (current state)
axis('normal') ans = 1 10 0.01991 0.9788 |
| axis([ 0 10 0 10]) |
ans =
0 10 0 10 |
Related Topics:
Synopsis:
balance(expr)
[T, B] = balance(expr)
Description:
The balance function attempts to improve the conditioning of a matrix.
The argument must be a square matrix. The function attempts to find a similarity transformation T, a diagonal matrix, such that T makes the row and column norms approximately equal. Hence the balanced matrix is inv(T)*expr*T.
When two return arguments are specified, then T is the diagonal transformation matrix, and B is the balanced matrix inv(T)*expr*T.
This function is meaningful for complex arguments as well as real arguments, and it returns a real value in either case.
Example:
|
INPUT |
OUTPUT |
| a=[4 1;8 -4]
[T,A]=balance(a) |
[T,A]=balance(a) T = 0.5 0 0 1 A = 4 2 4 -4 |
| T\a*T % =A |
ans =
4 2 4 -4 |
Related Topics:
Synopsis:
blackman(N)
Description:
The blackman function creates an N-point Blackman window in a column vector.
The Blackman window function is used to reduce leakage in the output of a fast Fourier transform (FFT) to a greater degree than would be obtained from using a rectangular window function.
Leakage is due to the difficulty of capturing exactly one period, or exactly some multiple of periods, of the signal being processed. If the window is rectangular, the resulting truncation causes a great deal of leakage. Leakage can be reduced by using certain nonrectangular window functions, with specific characteristics. Importantly:
1) Side lobes in the Fourier transform of the window function must be significantly smaller than the side lobes in the Fourier transform of a rectangular function.
2) The main lobe of the window-function Fourier transform must be narrow enough to prevent important signal information from being lost.
The Blackman window function possesses these characteristics, as do the Hamming and Hanning window functions, which are also available with MathViews.
These characteristics are necessary because, due to sampling and the accompanying truncation, energy in a DFT output appears at a series of specific frequencies. If fs is the sampling frequency and N is the number of samples, the specific frequencies range from 0 Hz to fs/2 Hz, and they are equally spaced fs/N Hz apart. As long as N contains one period, or multiple periods, of the signal, then all of the series of specific frequencies of the DFT output can pass. If N does not contain one or a multiple of periods, at least one of the series is blocked and its/their energy is distributed to the other components of the spectrum.
(next page)
Example:
|
INPUT |
OUTPUT |
| blackman(5)' |
ans =
0 0.34 1 0.34 0 |
| plot(blackman(100)) |
|
Related Topics:
wmerit, hamming, hanning, wbartlet, wrect, wsina
Synopsis:
casesen
casesen [on/off]
Description:
The function casesen is used to toggle case sensitivity in Mathviews.
Mathviews is always initialized to case sensitive inputs during startup, i.e. Mathviews will distinguish between lowercase and uppercase variables. The command can be used by itself to toggle the case sensitivity state. The command can also be used with the keywords [on/off] to explicitly specify the mode.
Example:
|
INPUT |
OUTPUT |
| casesen on
aa = 1 AA = 9 aa AA |
aa =
1 AA = 9 aa ans = 1 AA ans = 9 |
| casesen off
aa AA |
%starting here, case sensitivity is off aa ans = 1 AA ans = 1 |
| casesen on
aa AA |
%starting here, case sensitivity is on
aa ans = 1 AA ans = 9 |
Synopsis:
ceil(expr)
Description:
The ceil function rounds the element(s) of its argument to the nearest integer towards .
The argument can be a scalar, a vector, or a matrix.
If the argument has complex element(s), the function operates on both the real and the imaginary parts of the element(s).
Example:
|
INPUT |
OUTPUT |
| A =
-0.3 5.6 4.5 -0.02 5.1 5.6 |
ceil(A)
ans = 0 6 5 0 6 6 |
| z = 2.3 + 4.5j |
ceil(z)
ans = 3 + 5j |
Related Topics:
Synopsis:
chdir (directory)
Description:
The chdir command makes the named directory the current working directory. It also modifies the , _MVPWD variable to reflect the new working directory.
NOTE: The search path for m-files always includes the current working directory. Changing the working directory can change availability of script files and functions.
Example:
chdir docs Changes the current working directory to the directory, docs.
Related Topics:
dir, type, delete, who, whos, _MVPWD
Synopsis:
C = chol(A)
Description:
The chol function computes the Cholesky factorization of its argument, a non-singular symmetric matrix, A, and produces a lower triangular matrix, C, as the result.
The upper triangular matrix is the transpose of C. Thus A = C * C', which is known as the Cholesky factorization of A. A must be positive definite (see positive definite discussion in linear algebra books).
Example:
|
INPUT |
OUTPUT |
| A=[1 4 2 3;4 6 2 9;2 2 7 8;3 9 8 9]
B=A'*A C=chol(B) C*C' |
C=chol(B)
C = 5.477 0 0 0 10.77 4.579 0 0 8.764 2.533 6.147 0 14.97 0.3785 3.228 0.5514 |
| C=chol(A) % generates error |
Error: A is not positive definite. |
Related Topics:
Synopsis:
cla
Description:
The cla command clears the Output window
Example:
|
cla |
|
| Clears the output window. |
Related Topics:
Synopsis:
clc
Description:
The clc function clears text from the Output window.
Text can also be moved out of the output window using the scroll arrows.
Example:
clc
Related Topics:
Synopsis:
clear
clear functions
clear variable1 variable2 ...
Description:
The clear function clears variables from MathViews' memory.
Executing the command with no argument(s), will clear all variables and functions currently in memory. Executing the command with multiple arguments will clear those arguments. Multiple arguments must be separated by at least a single space. The command also clears functions residing in memory.
Upon completing execution of the clear function, MathViews will execute the commands contained in the file restart.m. This allows the environment to be reset to a default starting condition.
Example:
clear
clear x1, x2
clear median
Related Topics:
Synopsis:
clock
Description:
The clock function computes the current date and time in a six elements row vector.
The clock vector has the format [year month day hour minute fraction_of_seconds].
Example:
|
INPUT |
OUTPUT |
| t1=clock
z=eye(50); t2=clock etime(t2,t1) |
t1=clock
t1 = 93 1 15 11 0 36.1 t2=clock t2 = 93 1 15 11 0 39.0 etime(t2,t1) ans = 3.1 |
Related Topics:
Synopsis:
cntrlb(data)
Description:
The cntrlb function generates a contour line plot in the same manner as the contour function. In addition, the cntrlb function also plots the contour level numbers.
Example:
|
INPUT |
OUTPUT |
| n=8;
x=(0:n)/n; y=x.*(1.2-x); y /= max(y); z=y'*y; cntrlb(z) |
|
Related Topics:
Synopsis:
compan(expr)
Description:
The compan function computes the companion matrix.
The companion matrix is a square matrix, whose first row is expr(2:n)/expr(1).
Example:
Consider solving the roots for equation: ![]()
|
INPUT |
OUTPUT |
| p := [1 -3 -3 7 6]
eig(compan(p)) |
ans = 3 2 -1 + 6.294e-09 j -1 - 6.294e-09 j |
| angle(ans) |
ans =
0 0 3.142 -3.142 |
Related Topics:
Synopsis:
computer - Operating system
Description:
The computer function is a compatibility function. It returns the string 'WIN', indicating that MathViews is runing in the Microsoft Windows environment.
Example:
|
INPUT |
OUTPUT |
| computer |
computer
ans = WIN |
Related Topics:
none
Synopsis:
cond(A)
Description:
The cond function computes the condition number of matrix A.
The condition number indicates the sensitivity of matrix A to error when solving the problem of the form Ax = b. A must be a square matrix and non-singular. A high condition number is error prone when doing matrix inversions or solving systems of linear equations. The condition number is computed by the ratio of the max and min value of the singular value decomposition of A.
The condition number is computed using the 2-norm.
Example:
|
INPUT |
OUTPUT |
| A =
1 1 2 2 4 -3 3 6 -5 |
cond(A)
ans = 243.226 |
| norm(A)*norm(inv(A))
ans = 243.226 |
Note: the condition number is also defined to be norm(A)*norm(inv(A)). Also, this is a well behaved matrix. The condition number is relatively small as compared to the reciprocal of the machine epsilon.
Related Topics:
Synopsis:
conj(expr)
Description:
The conj function computes the complex conjugate of its argument.
If the argument is a complex scalar, the result is the complex conjugate of the argument. Real scalars are left unchanged.
If the argument is an array, the function operates on each element of the array, and the result is an array with the same dimensions as the argument.
Example:
|
INPUT |
OUTPUT |
| z = 4 - 5 j
conj(z) |
ans = 4 + 5 j |
| expr =
7 5 + 6 j 4 - 2 j -3 - 1 j conj(expr) |
ans = 7 5 - 6 j 4 + 2 j -3 + 1 j |
Related Topics:
Synopsis:
contour(data)
contour(data, [vc,lv])
contour(data, [vc,lv], xrange vector, yrange vector)
Description:
The contour function generates a contour lines plot.
The argument, data, is an array (matrix) containing the data to generate the contour plot. The data argument must be a real 2-dimensional array, i.e. a square matrix.
If the integer value, lv, is included, then the contour plot will include up to lv contour levels. If the vector argument, vc, is included instead of the argument lv, then the contour plot will include only levels specified by the elements of the vc vector.
Also, when specifying the xrange and yrange vectors, their elements must contain values where the contour is to be plotted. For sample, [0 10] will only show contour points at 0 and 10. However, [1:10] will show contour points at 1 through 10.
Example:
|
INPUT |
OUTPUT |
| n=8;
x=(0:n)/n; y=x.*(1.2-x); y /= max(y); z=y'*y; contour(z) |
|
| x = 0:.5:4*pi;
y = 0:.5:4*pi; [XX,YY]=meshdom(x,y); ZZ = 0.5*sin(XX).*cos(YY./4); contour(ZZ, [ 0:.1:1]) |
|
| contour(ZZ,[0:.1:1],[1:20],[1:10]) |
|
Related Topics:
Synopsis:
c = conv(expr1, expr2)
Description:
The conv function performs a convolution of the two vectors, expr1 and expr2. The convolution is expressed as:
![]()
where N is the length of the vectors expr1 and expr2.
Example:
|
INPUT |
OUTPUT |
| x=1:6
y=[1 1 1] z=conv(x,y) |
z =
1 3 6 9 12 15 11 6 |
| subplot(221)
n=64; plot(rand(1,10)) %noisy signal x=sinw(n)+(rand(1,n)-0.5)/4; % moving average y=ones(1,8) plot(x) plot(conv(x,y)) subplot(111) |
|
Related Topics:
Synopsis:
cos(expr)
Description:
The cos function computes the cosine of its argument.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
If the argument has complex element(s), then the complex cosine function:
![]()
is used to compute the result.
Example:
|
INPUT |
OUTPUT |
| z = 3 + 4j |
cos(z)
ans = -27.03 - 3.8512 j |
Related Topics:
Synopsis:
cosh(expr)
Description:
The cosh function computes the hyperbolic cosine of its argument.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
The cosh function is defined as:
.
Example:
|
INPUT |
OUTPUT |
| z = 3 + 4j |
cosh(z)
ans = -6.58066 - 7.58155 j |
Related Topics:
Synopsis:
cosw( points, cycles, freq, phase)
Description:
The cosw function is used to create sinusoidal waveforms.
The arguments are:
|
points |
number of elements of the waveform sequence |
| cycles |
the number of cycles of the waveform |
| freq |
the frequency deviation of the waveform |
| phase |
the initial phase of the waveform |
The cosw function is identical to the sinw function except that the default value of the initial phase is 90 degrees rather than 0.
Example:
|
INPUT |
OUTPUT |
| % half a cycle
plot(cosw(256,0.5)) |
|
| n=128
% two segments of 32 points np=[n n] % 2 cycles and 4 cycles f0=[1 10] % frequency sweep df=[0 -10] % initial phase ph0=[pi/3 0] plot(cosw(np,f0,df,ph0)) |
|
Related Topics:
Synopsis:
cov(A)
cov(a, b)
Description:
The cov function computes the covariance matrix of its argument.
Example:
|
INPUT |
OUTPUT |
| x=1:4
cov(x) |
x =
1 2 3 4 cov(x) ans = 1.25 |
| cov(x'*x) |
cov(x'*x)
ans = 1.25 2.5 3.75 5 2.5 5 7.5 10 3.75 7.5 11.25 15 5 10 15 20 |
Related Topics:
Synopsis:
cumprod(expr)
Description:
The cumprod function computes the cumulative product of its argument.
If the argument is a real scalar, the result is the same as the argument
If the argument is a vector, the result is the cumulative product of the argument's elements.
If the argument is a matrix, the function operates on each column. The function returns a row vector with elements being the cumulative product of each column of the matrix.
Example:
|
INPUT |
OUTPUT |
| a = 4 |
cumprod(a)
ans = 4 |
| A =
2 4 1 3 2 5 3 5 2 |
cumprod(A)
ans = 2 4 1 6 8 5 18 40 10 |
Related Topics:
Synopsis:
cumsum(expr)
Description:
The cumsum function computes the cumulative sum of its argument.
If the argument is a real scalar, the result is the same as the argument
If the argument is a vector, the result is the cumulative sum of the argument's elements.
If the argument is a matrix, the function operates on each column. The function returns a row vector with elements being the cumulative sum of each column of the matrix.
Examples:
|
INPUT |
OUTPUT |
| A = 3 5 7 |
cumsum(A)
ans = 3 8 15 |
| A =
2 4 1 3 2 5 3 5 2 |
cumsum(A)
ans = 2 4 1 5 6 6 8 11 8 |
Related Topics:
Synopsis:
delete (filename)
Description:
The delete command removes the named file from the current directory. Pathnames, wild cards and drive designators may be used.
Example:
delete temp.tmp Deletes the file, temp.tmp from the current directory.
Related Topics:
Synopsis:
det(expr)
Description:
The det function computes the determinant of its argument.
The argument must be a square matrix. The determinant of a complex matrix is also supported.
Example:
|
INPUT |
OUTPUT |
| B =
2 3 4 4 5 6 5 10 7 |
det(B)
ans = 16 |
| B =
2 3 + 3 j 4 4 5 6 + 4 j 5 10 + 6 j 7 |
det(B)
ans = 4 + 10 j |
Related Topics:
Synopsis:
dft(X)
Description:
The dft function computes the discrete Fourier transform of its argument. The discrete Fourier transform (DFT) is the discrete-time equivalent of the continuous-time Fourier transform. Given X(f) as the continuous Fourier transform of a coutinuous time signal x(t), then the DFT of the sampled time signal, x(n), is a sequence of samples of X(f), equally spaced in frequency. The DFT of a signal, x(n), is calculated as:
![]()
where
![]()
Example:
|
INPUT |
OUTPUT |
| dft(1:7)' |
dft(1:7)'
ans = 28 -3.5 - 7.268 j -3.5 - 2.791 j -3.5 - 0.7989 j -3.5 + 0.7989 j -3.5 + 2.791 j -3.5 + 7.268 j |
| x=[0 0 1 zeros(1,50)];
plot(imag(dft(x'))) |
|
Related Topics:
Synopsis:
diag(A)
diag(A, k)
Description:
The diag function returns the diagonal of its argument.
If the argument is a vector, the function is equivalent to diag(A, 0) and will return a diagonal matrix with the elements of A as diagonal elements. If k > 0, then the elements of the argument, will be the k-th diagonal above the main diagonal. If k < 0, the elements of the argument, will be the k-th diagonal below the main diagonal.
If the argument is a matrix, the function returns a column vector consisting of the diagonal elements of A. If k > 0, then a column vector consisting of the k-th diagonal elements above the main diagonal is returned.
Example:
|
INPUT |
OUTPUT |
| A =
1 2 3 4 2 3 5 5 3 10 5 6 4 9 6 7 |
diag(A)
ans = 1 3 5 7 |
| L =
1 1 0 0 |
diag(A(:,L))
ans = 1 3 |
| diag(A,-1)
ans = 2 10 6 |
Related Topics:
Synopsis:
diary
diary filename
diary [on/off]
Description:
The diary command generates a file, filename, containing all subsequent input commands and most outputs (except graphics) from MathViews' Interactive window and Output window.
If filename is not specified, then mathview.dry is generated. The diary function by itself toggles the diary mode. Diary can also be used with keywords [on/off] to explicitly specify the diary mode. MathViews is initialized to diary off during startup.
The name of the diary file cannot be 'on' or 'off'
Example:
|
INPUT |
| diary on
disp('MathViews') x = [ ] A = eye(3,3) diary off |
Related Topics:
Synopsis:
diff(expr)
diff(expr, n)
Description:
The diff function computes the approximate derivative.
The function operates following the rule:
x(i) = x(i+1) - x(i) for 1 <= i <= n,
where n is the number of elements in a vector.
If the argument is a vector with n elements, the function returns a vector representing its difference with n-1 number of elements.
If the argument is a matrix, the function operates on each column of the matrix.
Example:
|
INPUT |
OUTPUT |
| x =
1 2 3 4 5 6 7 8 9 4 7 5 0 6 2 1 |
diff(x)
ans = 8 2 4 1 -5 0 -5 -7 |
| diff(x',2)'
ans = 0 0 0 0 0 0 8 -5 -3 11 -10 3 |
Related Topics:
Synopsis:
dir
dir(</option> <directory>)
Description:
The command dir returns a list of the files in a directory. It is a generic file manipulation command that is analogous to its MS DOS counterpart, dir. Pathnames, wildcards, /p and /w options, and drive designators can be used. If no directory pathname is specified, dir returns a list of the files in the current directory.
Examples:
dir d* Lists all the of the subdirectories and files in the current directory that begin with the letter, D. dir/p A: Lists al of the directories and files in the home directory of the A drive.
Related Topics:
chdir, delete, type, who, whos
Synopsis:
disp(expr)
Description:
The disp function displays the contents of its argument.
If the argument is a text string, the string is displayed in the output window.
If the argument is a variable, the content(s) of the argument is(are) displayed in the output window without displaying the name of the variable.
Example:
|
INPUT |
OUTPUT |
| t = 'MathViews' |
disp(t)
mathviews |
| A =
2 4 1 3 2 5 3 5 2 |
disp(A)
2 4 1 3 2 5 3 5 2 |
Related Topics:
Synopsis:
echo
echo [on/off] [all]
echo function [on/off]
Description:
The echo command tells MathViews to display the statements of an M-file as it executes.
The effect of the echo command depends on whether the M-file currently being executed is a script file or a function file.
With script files, the command toggles the echo [on/off] mode for any currently running script M-file. When the echo mode is on, script M-file statements are displayed before execution. Echo [on/off] explicitly specifies the echo mode.
With function files, when echo is enabled, the function file is interpreted rather than compiled. This permits the statements to be examined as each statement is executed.
When using the command with a specified function M-file name, the command will toggle the echo mode of the M-file function.
The command used with on all will set the echo mode to on for all functions. Similarly for echo off all.
Example:
|
INPUT |
OUTPUT |
| echo on
startup.m echo off |
Every statement of script M-file startup.m will
be display before execution. |
Related Topics:
Synopsis:
edit
Description:
The edit function invokes MathPad for editing sessions.
Example:
edit
|
|
Related Topics:
notepad, MathPad
Synopsis:
eig(A)
[evec, eval] = eig(A)
eig(A, B)
[evec, eval] = eig(A, B)
Description:
The eig function computes the eigenvalues of the matrix, A
The argument must be a square matrix; if not you must use the svd function to find the matrix's singular values instead. If no return variable is specified, the eig function returns a unique vector of the eigenvalues of A. However, the elements may not be distinct, as in repeated eigenvalues. If the eval and evec return variables are specified, then eval is a diagonal matrix containing the eigenvalues of A, and the evec variable containing the corresponding eigenvectors of A.
The eig function can also solve the general eigenvalue problem.
Example:
|
INPUT |
OUTPUT |
| A =
1 -1 -2 1 0 2.44949 1 1 |
eig(A'*A)
ans = 5 10 |
| [V,D] = eig(A)
V = -0.5774 0.6124 -0.8165 -0.8660 D = -0.4142 0.0000 0.0000 2.4142 |
Related Topics:
Synopsis:
error(textstr)
Description:
The error function prints textstr onto the output window and exits the current M-files with an error message.
Example:
|
INPUT |
|
| message = 'My error'
error(message) |
Mathviews will prompt the user to acknowledge
that an error has occurred with message. |
Related Topics:
Synopsis:
etime(t2, t1)
Description:
The etime function computes the time between two clock vectors.
The two input arguments must be clock vectors; i.e. if t = clock, then t is a clock vector.
Example:
|
INPUT |
OUTPUT |
| t1=clock
z=eye(50); t2=clock etime(t2,t1) |
t1=clock
t1 = 93 1 15 11 0 36 t2=clock t2 = 93 1 15 11 0 39 etime(t2,t1) ans = 3 |
Related Topics:
Synopsis:
eval(expr)
Description:
The function eval(expr) executes the text in the argument.
Example:
|
INPUT |
OUTPUT |
| A =
2 4 1 3 2 5 3 5 2 t = 'cumsum(A)' eval(t) |
cumsum(A)
ans = 2 4 1 5 6 6 8 11 8 |
Related Topics:
Incompatibilities with MATLAB:
The eval function cannot be used to return a parameter. For example [m, n] = eval('size(A)') is illegal in MathViews. To get the same effect in MathViews, use eval('[m,n]=size(A)').
Synopsis:
exist(expr)
Description:
The function exist tests for the existence of its argument.
If the argument is currently in memory, the function returns a 1; otherwise a result is a 0.
If the argument is a text string and is the name of a file, and if it is in MathViews' search path, a 2 is returned.
Example:
|
INPUT |
OUTPUT |
| exist('z') |
ans =
1 |
| exist('y') |
ans =
0 |
| exist('startup.m') |
ans =
2 |
Related Topics:
Synopsis:
exit
Description:
The exit command terminates a MathViews session.
Example:
exit
Related Topics:
help
Synopsis:
exp(expr)
Description:
The exp function computes the exponential of its argument.
If the argument is an array, the function operates on each element of the array. The result is an array with the same dimensions as the argument.
If the argument has complex element(s), the complex exponential:
![]()
is used to compute the result.
Example:
|
INPUT |
OUTPUT |
| z = 2 + 3i
exp(z) |
ans =
1.04274 j |
| x = 2
y = 3 exp(x)*exp(3i) |
ans =
1.04274 j |
Related Topics:
Synopsis:
expm(A)
Description:
The expm function computes the matrix exponential.
The function uses the Pade approximation as described in Golub and Van Loan, "Matrix Computations", Algorithm 13.1-3.
Example:
|
INPUT |
OUTPUT |
| x=eye(3) |
expm(x)
ans = 2.718 0 0 0 2.718 0 0 0 2.718 |
| x=[1 1;0 2] |
expm(x)
ans = 2.718 4.671 0 7.389 |
Related Topics:
Synopsis:
expr_sel( condition, true_expr, false_expr)
Description:
The expr_sel function simulates the ternary operator '?' as in the C or C++ languages.
This function returns true_expr if condition is true; otherwise the function returns false_expr.
Example:
x = expr_sel( k > 0, 0, -1)
The above statement implements the following logic:
if k > 0
x = 0
else
x = -1
end
Related Topics:
Synopsis:
eye(expr)
eye(expr1, expr2)
Description:
The eye function generates an identity matrix.
If the argument(s) is(are) an integer(s), the function returns an identity matrix of size expr by expr or expr1 by expr2. Its diagonal elements will be 1's and its nondiagonal elements will be 0's.
If the argument is a matrix, the result is an identity matrix with the dimensions of the matrix.
Example:
|
INPUT |
OUTPUT |
| eye(3) |
ans =
1 0 0 0 1 0 0 0 1 |
| eye(5,3) |
ans =
1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 |
| eye(eye(3)) |
ans =
1 0 0 0 1 0 0 0 1 |
Related Topics:
Synopsis:
fac(expr)
Description:
The fac function computes the factorial of its argument
The argument must be an integer.
Example:
|
INPUT |
OUTPUT |
| x = 4 |
fac(x)
ans = 24 |
Related Topics:
Synopsis:
feval(expr, argin1, argin2, ...)
[arg1, arg2, ...] = feval(expr, argin1, argin2, ...)
Description:
The feval function evaluates the function name passed in as expr and passes it the arguments, arg1 ... argn.
The function can take a variable number of input arguments depending on the function specified in its argument. The function can also return a variable number of output arguments.
Example:
|
INPUT |
OUTPUT |
| feval('sin', pi/4); |
ans =
0.7071 |
| expr = 'sort'
A = [ 6 4; 7 3; 5 6 ; 9 3] [A,I] = feval(expr, A) |
A =
5.0000 3.0000 6.0000 3.0000 7.0000 4.0000 9.0000 6.0000 I = 3.0000 2.0000 1.0000 4.0000 2.0000 1.0000 4.0000 3.0000 |
Related Topics:
Synopsis:
fft(expr,n)
Description:
The fft function computes the Fast Fourier Transform (FFT) of its argument. The FFT is a mathematically efficient means of computing the Discrete Fourier Transform. See the description on the dft function for additional details. The argument n specifies the number of elements on which to compute the FFT. MathViews pads in zeros if the size of expr is less than n.
The fft function is defined for real and complex arrays.
Example:
|
INPUT |
OUTPUT |
| %fft/ifft
subplot(221) x=sinw(16,2)+sinw(16,5)/2 plot(x) y=fft(x) y=abs(fft(x)) plot(y) % should give x y=real(ifft(fft(x))) plot(y) subplot(111) |
|
| y/x |
ans =
16 |
Related Topics:
Synopsis:
[y,zf] = filter(b,a,x,zi)
Description:
The filter function filters data using a digital filter. The filter is implemented as a direct form II filter which implements the poles first and then the zeros. The difference equation for such a filter is described by the following:
![]()
with a rational system function of

The filter function is called with three or four vectors. The x vector is the data to be filtered and the a and b vectors are the zeroes and poles, respectively. An optional fourth vector, zi, is the initial conditions for the filter state. The filter state is set to zero if zi is not specified.
The output from the filter function is one of two vectors. The first vector, y, is the filtered data. The second vector, zf, is the final state of the filter.
Example:
|
% impulse response b=[0 0.909 0]; a=[1 -0.909 0.818]; x=[1 zeros(1,127)]; y=filter(b,a,x); plot(y); |
|
Related Topics:
Synopsis:
find(expr)
Description:
The find function finds nonzero elements of its argument.
The function returns a column vector with elements which are indices to nonzero elements in its argument.
Remember that in MathViews, matrix indices start at 1 and continue columnwise.
Example:
|
INPUT |
OUTPUT |
| V =
1 2 3 0 4 0 7 |
find(V)
ans = 1 2 3 5 7 |
| A =
1 2 0 0 4 0 6 0 7 |
find(A)
ans = 1 3 4 5 9 |
| A(find(A))
ans = 1 6 2 4 7 |
Related Topics:
Synopsis:
fix(expr)
Description:
The fix function rounds the element(s) of its argument to the nearest integer towards 0.
The argument can be a scalar, a vector, or a matrix.
If the argument has complex element(s), the function operates on both the real and the imaginary parts of the element(s).
Example:
|
INPUT |
OUTPUT |
| A =
-0.3 5.6 4.5 -0.02 5.1 5.6 |
fix(A)
ans = 0 5 4 0 5 5 |
| z = 2.3 + 4.5j |
fix(z)
ans = 2 + 4 j |
Related Topics:
Synopsis:
flip(expr)
Description:
The flip function reverses the order of the rows and columns of its argument.
If the argument is a scalar, the argument is left unchanged.
If the argument is a vector, a column vector of the flipped elements is returned.
If the argument is a matrix, a completely flipped matrix is returned.
Example:
|
INPUT |
OUTPUT |
| A =
1 2 0 0 4 0 6 0 7 9 4 7 |
flip(A)
ans = 7 4 9 7 0 6 0 4 0 0 2 1 |
Related Topics:
Synopsis:
fliplr(expr)
fliplr(expr, ncol)
Description:
The fliplr function reverses the order of the columns of its argument.
If the argument is a scalar, the argument is left unchanged.
If the argument is a vector, a column vector of the flipped elements is returned.
If the argument is a matrix, a complete column flip of the matrix is returned.
If the argument ncol is specified, then only the first ncol columns are used in the flip process.
Example:
|
INPUT |
OUTPUT |
| A =
1 2 0 0 4 0 6 0 7 9 4 7 |
fliplr(A)
ans = 0 2 1 0 4 0 7 0 6 7 4 9 |
| fliplr(A, 2)
ans = 2 1 0 4 0 0 0 6 7 4 9 7 |
Related Topics:
Synopsis:
flipud(expr)
flipud(expr, nrow)
Description:
The flipud function reverses the order of the rows of its argument.
If the argument is a scalar, the argument is left unchanged.
If the argument is a vector, a column vector of the flipped elements is returned.
If the argument is a matrix, a complete row flip of the matrix is returned.
If the argument, nrow, is specified, then only the first nrow rows are used in the flip process.
Example:
|
INPUT |
OUTPUT |
| A =
1 2 0 0 4 0 6 0 7 9 4 7 |
flipud(A)
ans = 9 4 7 6 0 7 0 4 0 1 2 0 |
| flipud(A, -2)
ans = 0 4 0 1 2 0 6 0 7 9 4 7 |
Related Topics:
Synopsis:
floor(expr)
Description:
The floor function rounds the element(s) of its argument to the nearest integer towards .
The argument can be a scalar, a vector, or a matrix.
If the argument has complex element(s), the function operates on both the real and the imaginary parts of the element(s).
Example:
|
INPUT |
OUTPUT |
| A =
-0.3 5.6 4.5 -0.02 5.1 5.6 |
floor(A)
ans = -1 5 4 -1 5 5 |
| z = 2.3 + 4.5j |
floor(z)
ans = 2 + 4 j |
Related Topics:
Synopsis:
format type
Description:
The format function operates on the display format of numbers on the output window. By default, real numbers are displayed in short format. The following table lists the available format types in MathViews.
|
short |
4 digits fixed point |
| long |
15 digits fixed point |
| short e |
4 digits floating point |
| long e |
15 digits floating point |
| hex |
hexadecimal display |
| +, - |
+,- display for values > 0 and < 0 |
| bank |
two digits fixed point |
| compact |
suppresses excess line feeds |
| loose |
airy display |
Example:
|
INPUT |
OUTPUT |
| x = 3.141 |
|
| format short
x |
ans =
3.1410 |
| format long
x |
ans =
3.141000000000000 |
| format short e
x |
ans =
3.1410E+00 |
| format bank
x |
ans =
3.14 |
| A = ones(5,5)
A(2:4, 2:4) = zeros(3,3) A(3,3) = -10 format + A |
A =
+ + + + + + 0 0 0 + + 0 - 0 + + 0 0 0 + + + + + + |
Related Topics:
Synopsis:
grid
Description:
Draws grid lines on the currently displayed plot; i.e. the currently active graphics window.
Example:
|
INPUT |
OUTPUT |
| plot(1:8, (1:8).^2)
grid |
|
Related Topics:
plot, hold, title, xlabel, ylabel
Synopsis:
gwclr(win)
Description:
The gwclr function clears a selected graphics window.
If no argument is provided, the command clears the current graphics window.
If an argument is provided, and it is an integer whose value represents the graphics window to be cleared, then the command clears the graphics window indicated by the argument's integer value. The integer value must be less than or equal to the total number of graphics windows selected using gwinit. If an out-of-range window number is referenced, the currently selected graphics window is used for clearing.
Example:
gwclr( 10)
gwclr()
clg
Related Topics:
Synopsis:
gwinit(dimensions, win_titles)
Description:
The gwinit function initializes MathViews accessible windows and their layout on the screen.
The win_titles argument is a array/matrix of N strings, each row represents a title of a MathViews graphics window. The number of rows of win_titles, N, determines the number of preset graphics windows of the current session.
The dimensions argument is an N by 4 matrix, where N is the number of rows in the argument win_titles. Each row of dimensions specifies the location of the graphics window.
The elements of each row must correspond to the following definitions:
The upper left corner of the screen is at location (0,0).
The lower right corner of the screen is at location (1,1)
Each element of a row must be in the range of [0,1] (inclusive).
The elements of each row, [x y wx wy], correspond to the graphical description shown below: