为了方便测试立体绘图,MATLAB提供了一个peaks函数,可产生一个凹凸有致的曲面,包含了三个局部极大点及三个局部极小点,其方程式为:
要画出此函数的最快方法即是直接键入
peaks:
z = 3*(1-x).^2.*exp(-(x.^2) – (y+1).^2) …
– 10*(x/5 – x.^3 – y.^5).*exp(-x.^2-y.^2) …
– 1/3*exp(-(x+1).^2 – y.^2)
我们亦可对peaks函数取点,再以各种不同方法进行绘图。
——————————————————————-
MATLAB中的帮助信息:
1 |
<span style="font-family: "Courier New"color: blue;font-size: 10pt" lang="EN-US"></span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<span style="font-family: "Courier New"color: blue;font-size: 10pt" lang="EN-US"></span> <span style="font-family: "Courier New"color: blue;font-size: 10pt" lang="EN-US"><span style="color: #000000"><span style="font-family: 宋体">PEAKS A sample function of two variables. PEAKS is a function of two variables, obtained by translating and scaling Gaussian distributions, which is useful for demonstrating MESH, SURF, PCOLOR, CONTOUR, etc. There are several variants of the calling sequence: Z = PEAKS; Z = PEAKS(N); Z = PEAKS(V); Z = PEAKS(X,Y); PEAKS; PEAKS(N); PEAKS(V); PEAKS(X,Y); [X,Y,Z] = PEAKS; [X,Y,Z] = PEAKS(N); [X,Y,Z] = PEAKS(V); The first variant produces a 49-by-49 matrix. The second variant produces an N-by-N matrix. The third variant produces an N-by-N matrix where N = length(V). The fourth variant evaluates the function at the given X and Y, which must be the same size. The resulting Z is also that size. The next four variants, with no output arguments, do a SURF plot of the result. The last three variants also produce two matrices, X and Y, for use in commands such as PCOLOR(X,Y,Z) or SURF(X,Y,Z,DEL2(Z)). If not given as input, the underlying matrices X and Y are [X,Y] = MESHGRID(V,V) where V is a given vector, or V is a vector of length N with elements equally spaced from -3 to 3. If no input argument is given, the default N is 49.</span></span></span> |
1 2 |
<span style="font-family: "Courier New"color: blue;font-size: 10pt" lang="EN-US"><span style="color: #000000"><span style="font-family: 宋体"> Reference page in Help browser doc peaks</span></span></span> |
1 2 3 4 |
<span style="font-family: "Courier New"color: blue;font-size: 10pt" lang="EN-US"><span style="color: #000000"><span style="font-family: 宋体"> z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... - 1/3*exp(-(x+1).^2 - y.^2) </span></span></span> |