2015年7月11日 星期六

第六週課程----gradient()、quiver()、bar()、barh()、pie()、hist()、comet()、contour()、contourc()、contourf()、polar()、stairs()

11.梯度向量場的gradient()及quiver()


gradient()函數命令格式如下:
                                     [Ax,Ay,Az, ...] = gradient(A,hx,hy,hz, ...)
         其中 A 為 N-dimension 陣列,而hx、hy、hz, ...,分別為沿第一維度、第二維度、第三維度、...,方向變數的間格。


quiver()為繪製箭頭函數,其命令格式如下:
                                     quiver(X,Y)
         依據X、Y陣列中的X(i,j)、Y(i,j)數值,以類似複數 z = X(i,j)+jY(i,j)在座標(i,j)上繪製一具有方向與長度的箭頭。gradient()函數必須配合quiver()函數方可繪出梯度向量場圖形。
例如:

          >> [x, y] = meshgrid(-2:.2:2, -2:.2:2);                        %建立繪製x,y網格陣列
          >> A = x.^2.*y + x;
          >> [Ax, Ay] = gradient(A,.2,.2);
          >> contour(A), hold on, quiver(Ax,Ay), hold off      % contour為繪製等高線圖函數

12.長條圖bar()
bar()函數命令格式如下:
格式一:
                                     bar(Y,width)
         其中Y為一向量,其內容為每個長條圖形的高,而width為每個長條圖形的寬,預設值為0.8。width的數值建議小於、等於1,以避免條狀圖形互相重疊。
例如:
          >> y=[1 3 5 2];
          >> bar(y,1);      %長條圖形的寬為1
       


例如:
          >> y=[1 3 5 2];
          >> bar(y), colormap(hot)      %設定暖色系顏色


格式二: 
                                     bar(Y,width)
其中Y為一陣列,以Y的列為一群組,分別繪製以Y的行數的長條狀圖形。
例如:
          >> y=magic(4)
          y =
              16     2     3    13
               5    11    10     8
               9     7     6    12
               4    14    15     1
          >> bar(y)


格式三: 
                                     bar(X,Y,width)
其中X為一向量,Y可為向量或陣列,以X的內容指定水平軸的座標位置,若無X參數,則以1:size(Y,1)為水平軸的座標位置。
例如:
          >> y=magic(4)
          >> x = [2 6 8 11];
          >> bar(x,y)

格式四: 
                                     bar(X,Y,width,'type')
其中type可以為 'grouped' ,也可以是'stacked'。grouped可將Y的每列內容以同一群組長條狀圖形來繪製;stacked則可將同一群組長條狀圖形以堆疊方式繪製,內定值為grouped。
例如:
          >> y=magic(4)
          >> x = [2 6 8 11];
          >> bar(x,y,'stacked')
 

13.橫向長條圖barh()
barh()為bar()相似的函數,差別在於圖形以水平軸方式呈現。
          例如:
          >> y=magic(4)
          >> x = [2 6 8 11];
          >> barh(x,y,'stacked')

14.派形圖pie()
pie()函數命令格式如下:
                                     pie(X,explode,labels)
         其中X可為向量或陣列,而explode亦為向量或陣列,其維數或元素個數必須與X相同,當explode內容若不為0,則表示相對於X位置的圖示部分會與其他部分分開呈現。而labels是一個cell陣列,其大小須與X相同,且只能包含字串,主要是提供描述扇形的意義。若無labels則會顯示各扇形所佔面積的百分比。
例如:
          >> x = [20 60 10; 30 15 50; 10 35 30; 40 20 10];
          >> explode = [0 0 0 1 0 0 0 0 0 0 0 0];
          >> labels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
          >> pie(x,explode,labels)



15.直方圖(histogram)hist()
hist()函數與bar()函數相似,但hist()函數可自行定義區間數。hist()函數命令格式如下:
                                     N = hist(X,n)
         其中X可為向量或陣列,而 n 為區間數,內定值為10。hist()函數會依X內容大小分成  n 個區間,若設有回傳參數 N,則 N 為 n 個區間內資料的個數;若無回傳參數,則會繪出各區間統計個數的直方圖。
例如:
          >> x = randn(100,1);
          >> N = hist(x,15)
          N =
            Columns 1 through 12
               2     1     4     5     6    11     6    16    20    14     8     1
            Columns 13 through 15
               4     0     2
          >> hist(x,15)

例如:
          >> x = randn(100,3);     %以行為群組
          >> hist(x,20)                  %回傳20*3的陣列, 並以深藍色表示每組第一筆統計值



16.極座標統計圖rose()
rose()與hist()函數相似,但rose()函數是以極座標方式呈現,但只針對向量內容做統計,也不能有輸出參數。rose()函數命令格式如下:
                                     rose(X,n)
         其中X為向量,而 n 為區間數,內定值為20。rose()函數也會依X內容大小分成  n 個區間,並繪出各區間統計個數的直方圖。
例如:
          >> x = randn(100,1);
          >> rose(x,30)
       


17.彗星圖comet()---俱動態畫的繪製圖形
comet()函數命令格式如下:
                                     comet(x,y,p)
         其中x、y皆為向量,而 p為彗星尾參數,內定值為0.1。彗星尾長定義為 p*length(y)。
例如:
          >> t = linspace(0,4*pi,10000); comet(t, sin(4*t)+cos(log(t/100)))     %綠色為彗星尾



18.等高線圖contour()、contourc()、contourf()
contour()函數命令格式如下:
         格式一:
                                     contour(z,n)
         其中 z 為(m*n)陣列,而 n 為等高線個數,若無 n 參數,Matlab會自動調整等高線數。等高線圖之水平軸座標為1~size(z,2),即1~n;垂直軸座標為1~size(z,1),即1~m。
例如:
          >> z=[70 2 12 52 38 48; 8 28 33 17 10 15; 65 6 40 38 33 40; 4 36 29 13 18 11]
          z =
              70     2    12    52    38    48
               8    28    33    17    10    15
              65     6    40    38    33    40
               4    36    29    13    18    11
          >> contour(z,5)

格式二:
                                     contour(x,y,z,n)
         其中 x 與 y 分別為水平軸座標、垂直軸座標陣列。
例如:
         >> [x,y,z] = peaks(50);
         >> contour(x,y,z,15)

格式三:
                                     C=contour(x,y,z,[z1,z2,...,zn])
         其中 z1,z2,...,zn為指定的等高線值,而C為等高線回傳陣列。若只要繪出單一數值的等高線,必須指定兩個相同的等高線值,e.g.  contour(x,y,z,[2, 2])就只繪出數值2的等高線。
例如:
         >> [x,y,z] = peaks(50);
         >> C=contour(x,y,z,[-2, 0, 2, 10]);
         >> clabel(C)                           % clabel()函數可標示出等高線數值
contourf()函數與contourc()函數的用法與contour()函數相似,主要差異是contourf()函數會在等高圍線中填滿顏色;而contourc()函數只回傳計算等高線的陣列不會繪圖,並且x與y皆要為向量,不可為陣列。
例如:
         >> [x,y,z] = peaks(50);
         >> C=contourf(x,y,z,[-2, 0, 2, 10]);
         >> clabel(C)

註:
clabel()函數格式如下:
格式一:
                                     clabel(C,[z1,z2,...,zn])
         其中 C 為等高線陣列,可在等高線圖上標記高度數值。其中 z1,z2,...,zn為指定的等高線值,此參數必須配合等高線計算函數contour()、contourf()或contourc,此參數可以省略。

          格式二:
                                     clabel(C,'manual')
其中 'manual' 是指可配合滑鼠控制,在欲標示的等高線上標註數值。回返可按下 "Enter" 鍵。

19.極座標曲線圖polar()
polar()函數可加入線條規範語法(Line specification syntax)來指定繪圖曲線的樣式。polar()函數命令格式如下:
                                              polar(theta,r)
         其中 theta 為角度向量,而 r 為半徑。
例如:
         >> t=0:0.01:2*pi;
         >> polar(t,3*sin(5*t)+1, '--r');

2015年6月13日 星期六

MuPAD基本運算


使用MuPAD繪製Inverse Trigonometric Function


f1 := plot::Function2d(sin(x), x = -PI/2..PI/2, Color = RGB::Blue);
f2 := plot::Function2d(arcsin(x), x = -1..1, Color = RGB::Green)

plot(f1, f2)




f1 := plot::Function2d(cos(x), x = 0..PI, Color = RGB::Blue);
f2 := plot::Function2d(arccos(x), x = -1..1, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(tan(x), x = -PI/2..PI/2, Color = RGB::Blue);
f2 := plot::Function2d(arctan(x), x = -10..10, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(cot(x), x = -PI/2..PI/2, Color = RGB::Blue);
f2 := plot::Function2d(arccot(x), x = -5..5, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(sec(x), x = 0..PI, Color = RGB::Blue);
f2 := plot::Function2d(arcsec(x), x = -5..5, Color = RGB::Green)

plot(f1, f2)


f1 := plot::Function2d(csc(x), x = -PI/2..PI/2, Color = RGB::Blue);
f2 := plot::Function2d(arccsc(x), x = -5..5, Color = RGB::Green)

plot(f1, f2)

MuPAD--linalg函數庫(linear algebra package)中的函數

可鍵入info(linalg)觀察在linalg(linear algebra package)函數庫中的函數; 也可以由MuPAD 的Help查詢更詳細的使用說明

[[From MuPAD Help]]

linalg::addCol – linear combination of matrix columns
linalg::addRow – linear combination of matrix rows
linalg::adjoint – Adjoint of a matrix
linalg::angle – The angle between two vectors
linalg::basis – basis for a vector space
linalg::charmat – characteristic matrix
linalg::charpoly – characteristic polynomial of a matrix
linalg::col – extract columns of a matrix
linalg::companion – Companion matrix of a univariate polynomial
linalg::concatMatrix – join matrices horizontally
linalg::cond – Condition number of a matrix
linalg::crossProduct – cross product of three-dimensional vectors
linalg::curl – curl of a vector field
linalg::delCol – delete matrix columns
linalg::delRow – delete matrix rows
linalg::det – determinant of a matrix
linalg::divergence – divergence of a vector field
linalg::eigenvalues – eigenvalues of a matrix
linalg::eigenvectors – eigenvectors of a matrix
linalg::expr2Matrix – construct a matrix from equations
linalg::factorCholesky – the Cholesky decomposition of a matrix
linalg::factorLU – LU-decomposition of a matrix
linalg::factorQR – QR-decomposition of a matrix
linalg::frobeniusForm – Frobenius form of a matrix
linalg::gaussElim – Gaussian elimination
linalg::gaussJordan – Gauss-Jordan elimination
linalg::gradient, linalg::grad – vector gradient
linalg::hermiteForm – Hermite normal form of a matrix
linalg::hessenberg – Hessenberg matrix
linalg::hessian – Hessian matrix of a scalar function
linalg::hilbert – Hilbert matrix
linalg::htranspose – Hermitean transpose of a matrix
linalg::intBasis – basis for the intersection of vector spaces
linalg::inverseLU – computing the inverse of a matrix using LU-decomposition
linalg::invhilbert – inverse of a Hilbert matrix
linalg::invpascal – inverse of a Pascal matrix
linalg::isHermitean – checks whether a matrix is Hermitean
linalg::isPosDef – test a matrix for positive definiteness
linalg::isUnitary – test whether a matrix is unitary
linalg::jacobian – Jacobian matrix of a vector function
linalg::jordanForm – Jordan normal form of a matrix
linalg::kroneckerProduct – Kronecker product of matrices
linalg::laplacian – the Laplacian
linalg::matdim – dimension of a matrix
linalg::matlinsolve – solving systems of linear equations
linalg::matlinsolveLU – solving the linear system given by an LU decomposition
linalg::minpoly – minimal polynomial of a matrix
linalg::multCol – multiply columns with a scalar
linalg::multRow – multiply rows with a scalar
linalg::ncols – number of columns of a matrix
linalg::nonZeros – number of non-zero elements of a matrix
linalg::normalize – normalize a vector
linalg::nrows – number of rows of a matrix
linalg::nullspace – basis for the null space of a matrix
linalg::ogCoordTab – table of orthogonal coordinate transformations
linalg::orthog – orthogonalization of vectors
linalg::pascal – Pascal matrix
linalg::permanent – permanent of a matrix
linalg::potential – the (scalar) potential of a gradient field
linalg::pseudoInverse – Moore-Penrose inverse of a matrix
linalg::randomMatrix – generate a random matrix
linalg::rank – rank of a matrix
linalg::row – extract rows of a matrix
linalg::scalarProduct – scalar product of vectors
linalg::setCol – change a column of a matrix
linalg::setRow – change a row of a matrix
linalg::smithForm – Smith canonical form of a matrix
linalg::sqrtMatrix – square root of a matrix
linalg::stackMatrix – join matrices vertically
linalg::submatrix – extract a submatrix or a subvector from a matrix or a vector, respectively
linalg::substitute – replace a part of a matrix by another matrix
linalg::sumBasis – basis for the sum of vector spaces
linalg::swapCol – swap two columns in a matrix
linalg::swapRow – swap two rows in a matrix
linalg::sylvester – Sylvester matrix of two polynomials
linalg::tr – trace of a matrix
linalg::toeplitz – Toeplitz matrix
linalg::toeplitzSolve – solve a linear Toeplitz system
linalg::transpose – transpose of a matrix
linalg::vandermonde, linalg::invvandermonde – Vandermonde matrices and their inverses
linalg::vandermondeSolve – solve a linear Vandermonde system
linalg::vecdim – number of components of a vector
linalg::vectorOf – type specifier for vectors
linalg::vectorPotential – vector potential of a three-dimensional vector field
linalg::wiedemann – solving linear systems by Wiedemann's algorithm

MuPAD--linopt函數庫(linear optimization package)中的函數

可鍵入info(linopt)觀察在linopt(linear optimization package, 線性規劃)函數庫中的函數; 也可以由MuPAD 的Help查詢更詳細的使用說明

[[From MuPAD Help]]

linopt::corners – return the feasible corners of a linear program
linopt::maximize – maximize a linear or mixed-integer program
linopt::minimize – minimize a linear or mixed-integer program
linopt::plot_data – plot the feasible region of a linear program
linopt::Transparent – return the ordinary simplex tableau of a linear program
linopt::Transparent::autostep – perform the next simplex step
linopt::Transparent::clean_basis – delete all slack variables of the first phase from the basis
linopt::Transparent::convert – transform the given tableau into a structure printable on screen
linopt::Transparent::dual_prices – get the dual solution belonging to the given tableau
linopt::Transparent::phaseI_tableau – start an ordinary phase one of a 2-phase simplex algorithm
linopt::Transparent::phaseII_tableau – start phase two of a 2-phase simplex algorithm
linopt::Transparent::result – get the basic feasible solution belonging to the given simplex tableau
linopt::Transparent::simplex – finish the current phase of the 2-phase simplex algorithm
linopt::Transparent::suggest – suggest the next step in the simplex algorithm
linopt::Transparent::userstep – perform a user defined simplex step

MuPAD--numeric函數庫中的函數

可鍵入info(numeric)觀察在numeric函數庫中的函數; 也可以由MuPAD 的Help查詢更詳細的使用說明

[[From MuPAD Help]]

numeric::butcher – Butcher parameters of Runge-Kutta schemes
numeric::complexRound – round a complex number towards the real or imaginary axis
numeric::cubicSpline – interpolation by cubic splines
numeric::cubicSpline2d – interpolation by 2-dimensional bi-cubic splines
numeric::det – determinant of a matrix
numeric::eigenvalues – numerical eigenvalues of a matrix
numeric::eigenvectors – numerical eigenvalues and eigenvectors of a matrix
numeric::expMatrix – the exponential of a matrix
numeric::factorCholesky – Cholesky factorization of a matrix
numeric::factorLU – LU factorization of a matrix
numeric::factorQR – QR factorization of a matrix
numeric::fft, numeric::invfft – Fast Fourier Transform
numeric::fMatrix – functional calculus for numerical square matrices
numeric::fsolve – search for a numerical root of a system of equations
numeric::gaussAGM – Gauss' arithmetic geometric mean
numeric::gldata – weights and abscissae of Gauss-Legendre quadrature
numeric::gtdata – weights and abscissae of Gauss-Tschebyscheff quadrature
numeric::indets – search for indeterminates
numeric::int – numerical integration (the float attribute of int)
numeric::inverse – the inverse of a matrix
numeric::leastSquares – least squares solution of linear equations
numeric::linsolve – solve a system of linear equations
numeric::matlinsolve – solve a linear matrix equation
numeric::ncdata – weights and abscissae of Newton-Cotes quadrature
numeric::odesolve – numerical solution of an ordinary differential equation
numeric::odesolve2 – numerical solution of an ordinary differential equation 
numeric::odesolveGeometric – numerical solution of an ordinary differential equation on a homogeneous manifold
numeric::ode2vectorfield – convert an ode system to vectorfield notation
numeric::polyrootbound – a bound for the roots of a univariate polynomial
numeric::polyroots – numerical roots of a univariate polynomial
numeric::polysysroots – numerical roots of a system of polynomial equations
numeric::product – numerical approximation of products
numeric::quadrature – numerical integration (“quadrature”)
numeric::rank – numerical estimate of the rank of a matrix
numeric::rationalize – approximate a floating point number by a rational number
numeric::realroot – numerical search for a real root of a real univariate function
numeric::realroots – isolate intervals containing real roots of a univariate function
numeric::rotationMatrix – the orthogonal matrix of the rotation about an axis
numeric::singularvalues – numerical singular values of a matrix
numeric::singularvectors, numeric::svd – numerical singular value decomposition of a matrix
numeric::solve – numerical solution of equations (the float attribute of solve)
numeric::sort – sort a numerical list
numeric::spectralradius, numeric::spectralRadius – the spectral radius of a matrix
numeric::sum – numerical approximation of sums (the float attribute of sum)