Friday, August 04, 2006
DCT Usages
>> help findResource
findResource Find available distributed computing resources
OUT = findResource('scheduler','type', SCHEDTYPE)
OUT = findResource('worker')
return an array, OUT, containing objects representing all available
distributed computing schedulers of the given type, or workers. SCHEDTYPE
can be 'jobmanager', 'LSF', 'mpiexec', or any string starting with
'generic'. You can use different scheduler types starting with 'generic' to
identify one generic scheduler or configuration from another. For
third-party schedulers, job data is stored in the location specified by the
scheduler object's DataLocation property.
OUT = findResource('scheduler','type','jobmanager','LookupURL','HOST:PORT')
OUT = findResource('worker','LookupURL','HOST:PORT')
use the lookup process of the job manager running at a specific
location. The lookup process is part of a job manager. By default,
findResource uses all the lookup processes that are available to the local
machine via multicast. If you specify 'LookupURL' with a host and port,
findResource uses the job manager lookup process running at that
location. This URL is where the lookup is performed from, it is not
necessarily the host running the job manager or worker. This unicast call is
useful when you want to find resources that might not be available via
multicast or in a network that does not support multicast.
Note: LookupURL is ignored when finding third-party schedulers.
OUT = findResource(... ,'P1', V1, 'P2', V2,...)
returns an array, OUT, of resources whose property names and property values
match those passed as parameter-value pairs, P1, V1, P2, V2.
Note that the property value pairs can be in any format supported by the SET
function.
When a property value is specified, it must use the same exact value that
the GET function returns, including letter case. For example, if GET returns
the Name property value as 'MyJobManager', then findResource will not find
that object if searching for a Name property value of 'myjobmanager'.
Remarks
Note that it is permissible to use parameter-value string pairs, structures,
and parameter-value cell array pairs in the same call to findResource. The
parameter-value pairs can also be specified as a configuration, described in
the "Programming with User Configurations" section in the documentation.
Examples:
Find a particular job manager by its name.
jm1 = findResource('scheduler','type','jobmanager', ...
'Name', 'ClusterQueue1');
Find all job managers. In this example, there are four.
all_job_managers = findResource('scheduler','type','jobmanager')
all_job_managers =
distcomp.jobmanager: 1-by-4
Find all job managers accessible from the lookup service on a particular
host.
jms = findResource('scheduler','type','jobmanager', ...
'LookupURL','MyJobManagerHost');
Find a particular job manager accessible from the lookup service on a
particular host. In this example, subnet2.host_alpha port 6789 is where the
lookup is performed, but the job manager named SN2Jmgr might be running on
another machine.
jm = findResource('scheduler','type','jobmanager', ...
'LookupURL', 'subnet2.host_alpha:6789', ...
'Name', 'SN2JMgr');
Find the LSF scheduler on the network.
lsf_sched = findResource('scheduler','type','LSF')
See also findJob, findTask.
Wednesday, May 17, 2006
plot Usage
v1=linspace(0,2*pi,20); v2=sin(v1); % 建立 v1 及 v2 陣列
plot(v1, v2) % 利用 plot,輸入的變數為 x 軸接著的變數為 y 軸
v3=cos(v1); % 建立 v3 陣列
plot(v1,v2,v1,v3) % 劃二條曲線,一條代表 v1-v2 函數關係, 一條代表 v1-v3 函數關係
plot(v1,v2,v1,v2,'+') % 一樣劃二條曲線,不過第二條曲線以符號 + 標示
plot(v1,v2,v1,v2.*v3,'--') % 劃二條曲線,一條代表 v1-v2 函數關係,一條代表 v1-(v2.*v3) 函數關係且以符號'標示
xlabel('x-axis') % 加上 x 軸的說明,在二個單引號 ' 之間鍵入文字的說明
ylabel('y-axis') % 加上 y 軸的說明
title('2D plot') % 加上圖的說明
plot3(v2,v3,v1), grid % 將 v2-v1-v3 函數關係分別以x軸y軸及z軸劃,並加上格線
Matlab繪圖有幾個基本命令:
* figure: 強制生成一個新的個繪圖窗口;
* syms x y t : 聲明變量;
* fplot(函數表達式,繪圖區間);
* plot(?坐標向量,縱坐標向量,?色/?形等參數)
* ezplot(函數表達式): 簡單的fplot
* axis([xmin xmax ymin ymax ...]): 設置坐標軸顯示範圍。
使用泛函繪圖指令fplot,更為方便。比如畫某個區間的標准正態分布概率密度曲線:
fplot('normpdf(x,0,1)',[-3,3],'b-')
相應分布函數曲線:
fplot('normcdf(x,0,1)',[-3,3],'b-')
數學期望為3,方差為5的正態分布概率密度曲線:
fplot('normpdf(x,3,sqrt(5))',[-3,9],'b-')
SET Set object properties.
SET(H,'PropertyName',PropertyValue) sets the value of the
specified property for the graphics object with handle H.
H can be a vector of handles, in which case SET sets the
properties' values for all the objects.
SET(H,a) where a is a structure whose field names are object
property names, sets the properties named in each field name
with the values contained in the structure.
SET(H,pn,pv) sets the named properties specified in the cell array
of strings pn to the corresponding values in the cell array pv for
all objects specified in H. The cell array pn must be 1-by-N, but
the cell array pv can be M-by-N where M is equal to length(H) so
that each object will be updated with a different set of values
for the list of property names contained in pn.
SET(H,'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,...)
sets multiple property values with a single statement. Note that it
is permissible to use property/value string pairs, structures, and
property/value cell array pairs in the same call to SET.
A = SET(H, 'PropertyName')
SET(H,'PropertyName')
returns or displays the possible values for the specified
property of the object with handle H. The returned array is
a cell array of possible value strings or an empty cell array
if the property does not have a finite set of possible string
values.
A = SET(H)
SET(H)
returns or displays all property names and their possible values for
the object with handle H. The return value is a structure whose
field names are the property names of H, and whose values are
cell arrays of possible property values or empty cell arrays.
The default value for an object property can be set on any of an
object's ancestors by setting the PropertyName formed by
concatenating the string 'Default', the object type, and the
property name. For example, to set the default color of text objects
to red in the current figure window:
set(gcf,'DefaultTextColor','red')
Defaults can not be set on a descendant of the object, or on the
object itself - for example, a value for 'DefaultAxesColor' can not
be set on an axes or an axes child, but can be set on a figure or on
the root.
Three strings have special meaning for PropertyValues:
'default' - use default value (from nearest ancestor)
'factory' - use factory default value
'remove' - remove default value.
See also GET, RESET, DELETE, GCF, GCA, FIGURE, AXES.
PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, length(Y)
disconnected points are plotted.
PLOT(Y) plots the columns of Y versus their index.
If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).
In all other uses of PLOT, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
PLOT(X,Y,S) where S is a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; PLOT(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
the (X,Y,S) triples, where the X's and Y's are vectors or matrices
and the S's are strings.
For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a
solid yellow line interpolating green circles at the data points.
The PLOT command, if no color is specified, makes automatic use of
the colors specified by the axes ColorOrder property. The default
ColorOrder is listed in the table above for color systems where the
default is blue for one line, and for multiple lines, to cycle
through the first six colors in the table. For monochrome systems,
PLOT cycles over the axes LineStyleOrder property.
If you do not specify a marker type, PLOT uses no marker.
If you do not specify a line style, PLOT uses a solid line.
PLOT(AX,...) plots into the axes with handle AX.
PLOT returns a column vector of handles to lineseries objects, one
handle per plotted line.
The X,Y pairs, or X,Y,S triples, can be followed by
parameter/value pairs to specify additional properties
of the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0])
will create a plot with a dark red line width of 2 points.
Backwards compatibility
PLOT('v6',...) creates line objects instead of lineseries
objects for compatibility with MATLAB 6.5 and earlier.
See also plottools, semilogx, semilogy, loglog, plotyy, plot3, grid,
title, xlabel, ylabel, axis, axes, hold, legend, subplot, scatter.
Reference page in Help browser
doc plot
Saturday, March 04, 2006
Eigen Values --- eigs
EIGS Find a few eigenvalues and eigenvectors of a matrix using ARPACK.
D = EIGS(A) returns a vector of A's 6 largest magnitude eigenvalues.
A must be square and should be large and sparse.
[V,D] = EIGS(A) returns a diagonal matrix D of A's 6 largest magnitude
eigenvalues and a matrix V whose columns are the corresponding eigenvectors.
[V,D,FLAG] = EIGS(A) also returns a convergence flag. If FLAG is 0
then all the eigenvalues converged; otherwise not all converged.
EIGS(A,B) solves the generalized eigenvalue problem A*V == B*V*D. B must
be symmetric (or Hermitian) positive definite and the same size as A.
EIGS(A,[],...) indicates the standard eigenvalue problem A*V == V*D.
EIGS(A,K) and EIGS(A,B,K) return the K largest magnitude eigenvalues.
EIGS(A,K,SIGMA) and EIGS(A,B,K,SIGMA) return K eigenvalues based on SIGMA:
'LM' or 'SM' - Largest or Smallest Magnitude
For real symmetric problems, SIGMA may also be:
'LA' or 'SA' - Largest or Smallest Algebraic
'BE' - Both Ends, one more from high end if K is odd
For nonsymmetric and complex problems, SIGMA may also be:
'LR' or 'SR' - Largest or Smallest Real part
'LI' or 'SI' - Largest or Smallest Imaginary part
If SIGMA is a real or complex scalar including 0, EIGS finds the eigenvalues
closest to SIGMA. For scalar SIGMA, and also when SIGMA = 'SM' which uses
the same algorithm as SIGMA = 0, B need only be symmetric (or Hermitian)
positive semi-definite since it is not Cholesky factored as in the other cases.
EIGS(A,K,SIGMA,OPTS) and EIGS(A,B,K,SIGMA,OPTS) specify options:
OPTS.issym: symmetry of A or A-SIGMA*B represented by AFUN [{0} | 1]
OPTS.isreal: complexity of A or A-SIGMA*B represented by AFUN [0 | {1}]
OPTS.tol: convergence: Ritz estimate residual <= tol*NORM(A) [scalar | {eps}]
OPTS.maxit: maximum number of iterations [integer | {300}]
OPTS.p: number of Lanczos vectors: K+1 &less; p ≤ N [integer | {2K}]
OPTS.v0: starting vector [N-by-1 vector | {randomly generated by ARPACK}]
OPTS.disp: diagnostic information display level [0 | {1} | 2]
OPTS.cholB: B is actually its Cholesky factor CHOL(B) [{0} | 1]
OPTS.permB: sparse B is actually CHOL(B(permB,permB)) [permB | {1:N}]
EIGS(AFUN,N) accepts the function AFUN instead of the matrix A.
Y = AFUN(X) should return
A*X if SIGMA is not specified, or is a string other than 'SM'
A\X if SIGMA is 0 or 'SM'
(A-SIGMA*I)\X if SIGMA is a nonzero scalar (standard eigenvalue problem)
(A-SIGMA*B)\X if SIGMA is a nonzero scalar (generalized eigenvalue problem)
N is the size of A. The matrix A, A-SIGMA*I or A-SIGMA*B represented by AFUN is
assumed to be real and nonsymmetric unless specified otherwise by OPTS.isreal
and OPTS.issym. In all these EIGS syntaxes, EIGS(A,...) may be replaced by
EIGS(AFUN,N,...).
EIGS(AFUN,N,K,SIGMA,OPTS,P1,P2,...) and EIGS(AFUN,N,B,K,SIGMA,OPTS,P1,P2,...)
provide for additional arguments which are passed to AFUN(X,P1,P2,...).
Examples:
A = delsq(numgrid('C',15)); d1 = eigs(A,5,'SM');
Equivalently, if dnRk is the following one-line function:
function y = dnRk(x,R,k)
y = (delsq(numgrid(R,k))) \ x;
then pass dnRk's additional arguments, 'C' and 15, to EIGS:
n = size(A,1); opts.issym = 1; d2 = eigs(@dnRk,n,5,'SM',opts,'C',15);
See also EIG, SVDS, ARPACKC.
Wednesday, March 01, 2006
Tridiagnal@Schroding Equation
使用Periodic Potential的模型,直接解Schroding方程,最終會得到一個3對角化的矩陣,使用Matlab來求解,可能是最好的方式了。
http://www.mit.edu/~persson/mltrid/index.html
* TRIDEIG computes all the eigenvalues of a symmetric tridiagonal matrix.
* BIDSVD computes all the singular values of a bidiagonal matrix.
* MAXEIG computes the largest eigenvalue of a symmetric tridiagonal matrix.
Thursday, February 23, 2006
Random Generator
>> help spdiags
SPDIAGS Sparse matrix formed from diagonals.
SPDIAGS, which generalizes the function "diag", deals with three
matrices, in various combinations, as both input and output.
[B,d] = SPDIAGS(A) extracts all nonzero diagonals from the m-by-n
matrix A. B is a min(m,n)-by-p matrix whose columns are the p
nonzero diagonals of A. d is a vector of length p whose integer
components specify the diagonals in A.
B = SPDIAGS(A,d) extracts the diagonals specified by d.
A = SPDIAGS(B,d,A) replaces the diagonals of A specified by d with
the columns of B. The output is sparse.
A = SPDIAGS(B,d,m,n) creates an m-by-n sparse matrix from the
columns of B and places them along the diagonals specified by d.
Roughly, A, B and d are related by
for k = 1:p
B(:,k) = diag(A,d(k))
end
Example: These commands generate a sparse tridiagonal representation
of the classic second difference operator on n points.
e = ones(n,1);
A = spdiags([e -2*e e], -1:1, n, n)
Some elements of B, corresponding to positions "outside" of A, are
not actually used. They are not referenced when B is an input and
are set to zero when B is an output. If a column of B is longer than
the diagonal it's representing, elements of super-diagonals of A
correspond to the lower part of the column of B, while elements of
sub-diagonals of A correspond to the upper part of the column of B.
Example: This uses the top of the first column of B for the second
sub-diagonal and the bottom of the third column of B for the first
super-diagonal.
B = repmat((1:n)',1,3);
S = spdiags(B,[-2 0 1],n,n);
See also DIAG.
ode文件
ode文件是一种函数M文件,即:在m-file编辑器中,文件必须以function开头,后面跟的函数名必须与将来保存的M文件名一致。函数文件第一句的具体形式为:function y=average(x)
其中为y输出变量名,x为变量,average为函数名,保存时文件名必须是average.m。当函数有一个以上的输出函数时,输出参数包含在方括号里,变参包含在圆括号里,即函数文件的第一行的具体形式为:
function [out1,out2,…]=average(in1,in2,…)
例:计算数组元素的平均值
解:function y=average(x)
y=sum(x)/length(x) 注:上下两式等号前的符号"y"必须相同
為了要有隨機的數值,使用c內部的rand函式,是個不錯的選擇,但是以前沒有用過,所以重新來整理一下。
RAND_MAX: 是個非常大的數值,所以隨機函式庫所產生的數值,都會小、等於RAND_MAX。 rand(): 產生0至RAND_MAX的整數值。
所以(rand()+1.)/(RAND_MAX+2.)就會產生介於0與1的隨機實數。
Wednesday, February 22, 2006
conversion format
textread('Value.txt', 'N= %f\n', 1)
TEXTREAD Read formatted data from text file.
A = TEXTREAD('FILENAME')
A = TEXTREAD('FILENAME','',N)
A = TEXTREAD('FILENAME','',param,value, ...)
A = TEXTREAD('FILENAME','',N,param,value, ...) reads numeric data from
the file FILENAME into a single variable. If the file contains any
text data, an error is produced.
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT')
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',N)
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',param,value, ...)
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',N,param,value, ...) reads
data from the file FILENAME into the variables A,B,C,etc. The type of
each return argument is given by the FORMAT string. The number of
return arguments must match the number of conversion specifiers in the
FORMAT string. If there are fewer fields in the file than in the
format string, an error is produced. See FORMAT STRINGS below for
more information.
If N is specified, the format string is reused N times. If N is -1 (or
not specified) TEXTREAD reads the entire file.
If param,value pairs are supplied, user configurable options customize
the behavior of TEXTREAD. See USER CONFIGURABLE OPTIONS below.
TEXTREAD works by matching and converting groups of characters from the
file. An input field is defined as a string of non-whitespace
characters extending to the next whitespace or delimiter character
or until the field width is exhausted. Repeated delimiter characters
are significant while repeated whitespace characters are treated as
one.
FORMAT STRINGS
If the FORMAT string is empty, TEXTREAD will only numeric data.
The FORMAT string can contain whitespace characters (which are
ignored), ordinary characters (which are expected to match the next
non-whitespace character in the input), or conversion specifications.
If whitespace is set to '' and format types are %s,%q,%[...] and %[^...].
Else whitespace characters are ignored.
Supported conversion specifications:
%n - read a number - float or integer (returns double array)
%5n reads up to 5 digits or until next delimiter
%d - read a signed integer value (returns double array)
%5d reads up to 5 digits or until next delimiter
%u - read an integer value (returns double array)
%5u reads up to 5 digits or until next delimiter
%f - read a floating point value (returns double array)
%5f reads up to 5 digits or until next delimiter
%s - read a whitespace separated string (returns cellstr)
%5s reads up to 5 characters or until whitespace
%q - read a (possibly double quoted) string (returns cellstr)
%5q reads up to 5 non-quote characters or until whitespace
%c - read character or whitespace (returns char array)
%5c reads up to 5 characters including whitespace
%[...] - reads characters matching characters between the
brackets until first non-matching character or
whitespace (returns cellstr)
use %[]...] to include ]
%5[...] reads up to 5 characters
%[^...] - reads characters not matching characters between the
brackets until first matching character or whitespace
(returns cellstr)
use %[^]...] to exclude ]
%5[^...] reads up to 5 characters
Note: Format strings are interpreted as with sprintf before parsing.
For example, textread('mydata.dat','%s\t') will search for a tab not
the character '\' followed by the character 't'. See the Language
Reference Guide or a C manual for complete details.
Using %* instead of % in a conversion causes TEXTREAD to skip the
matching characters in the input (and no output is created for this
conversion). The % can be followed by an optional field width to
handle fixed width fields. For example %5d reads a 5 digit integer. In
addition the %f format supports the form %.f.
USER CONFIGURABLE OPTIONS
Possible param/value options are:
'bufsize' - maximum string length in bytes (default is 4095)
'commentstyle' - one of
'matlab' -- characters after % are ignored
'shell' -- characters after # are ignored
'c' -- characters between /* and */ are ignored
'c++' -- characters after // are ignored
'delimiter' - delimiter characters (default is none)
'emptyvalue' - empty cell value in delimited files (default is 0)
'endofline' - end of line character (default determined from file)
'expchars' - exponent characters (default is 'eEdD')
'headerlines' - number of lines at beginning of file to skip
'whitespace' - whitespace characters (default is ' \b\t')
TEXTREAD is useful for reading text files with a known format. Both
fixed and free format files can be handled.
Examples:
Suppose the text file mydata.dat contains data in the following form:
Sally Type1 12.34 45 Yes
Joe Type2 23.54 60 No
Bill Type1 34.90 12 No
Read each column into a variable
[names,types,x,y,answer] = textread('mydata.dat','%s%s%f%d%s');
Read first column into a cell array (skipping rest of line)
[names]=textread('mydata.dat','%s%*[^\n]')
Read first character into char array (skipping rest of line)
[initials]=textread('mydata.dat','%c%*[^\n]')
Read file as a fixed format file while skipping the doubles
[names,types,y,answer] = textread('mydata.dat','%9c%5s%*f%2d%3s');
Read file and match Type literal
[names,typenum,x,y,answer]=textread('mydata.dat','%sType%d%f%d%s');
Read m-file into cell array of strings
file = textread('fft.m','%s','delimiter','\n','whitespace','');
To read all numeric data from a delimited text file, use a single output
argument, empty format string, and the appropriate delimiter. For
example, suppose data.csv contains:
1,2,3,4
5,6,7,8
9,10,11,12
Read the whole matrix into a single variable:
[data] = textread('data.csv','','delimiter',',');
Read the first two columns into two variables:
[col1, col2] = textread('data.csv','%n%n%*[^\n]','delimiter',',');
For files with empty cells, use the emptyvalue parameter. Suppose
data.csv contains:
1,2,3,4,,6
7,8,9,,11,12
Read the file like this, using NaN in empty cells:
[data] = textread('data.csv','','delimiter',',','emptyvalue',NaN);
See also DLMREAD, LOAD, STRREAD, SSCANF, XLSREAD.
d, i, o, u, x, e, f, g, s, c,
>> help fscanf
FSCANF Read formatted data from file.
[A,COUNT] = FSCANF(FID,FORMAT,SIZE) reads data from the file specified
by file identifier FID, converts it according to the specified FORMAT
string, and returns it in matrix A. COUNT is an optional output
argument that returns the number of elements successfully read.
FID is an integer file identifier obtained from FOPEN.
SIZE is optional; it puts a limit on the number of elements that
can be read from the file; if not specified, the entire file
is considered; if specified, valid entries are:
N read at most N elements into a column vector.
inf read at most to the end of the file.
[M,N] read at most M * N elements filling at least an
M-by-N matrix, in column order. N can be inf, but not M.
If the matrix A results from using character conversions only and
SIZE is not of the form [M,N] then a row vector is returned.
FORMAT is a string containing C language conversion specifications.
Conversion specifications involve the character %, optional
assignment-suppressing asterisk and width field, and conversion
characters d, i, o, u, x, e, f, g, s, c, and [. . .] (scanset).
Complete ANSI C support for these conversion characters is
provided consistent with 'expected' MATLAB behavior. For a complete
conversion character specification, see the Language Reference
Guide or a C manual.
If %s is used an element read may cause several MATLAB matrix
elements to be used, each holding one character. Use %c to read
space characters; the format %s skips all white space.
Mixing character and numeric conversion specifications will cause
the resulting matrix to be numeric and any characters read to show
up as their ASCII values one character per MATLAB matrix element.
FSCANF differs from its C language namesake in an important respect -
it is "vectorized" in order to return a matrix argument. The format
string is recycled through the file until an end-of-file is reached
or the amount of data specified by SIZE is read in.
Examples:
S = fscanf(fid,'%s') reads (and returns) a character string.
A = fscanf(fid,'%5d') reads 5-digit decimal integers.
See also FPRINTF, SSCANF, TEXTREAD, FGETL, FGETS, FREAD, INPUT.Wednesday, February 08, 2006
Matlab Syntax Usage
Logical Operator
Operator Operation Priority ~ NOT Highest & Elementwise AND | Elementwise OR && Short-circuit AND || Short-circuit OR Lowest Logical operators, short-circuit, &&, || Relational operators <, <=, >, >=, ==, ~=