peaks
peaks 函数
说明
返回坐标
创建曲面图
peaks(___)
将 peaks 函数绘制为一个三维曲面图。您可以使用以前语法中的任意输入参数组合。
示例
绘制峰值曲面
创建一个由峰值组成的 5×5 矩阵并显示该曲面。
figure peaks(5)
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)
基于向量中的点绘图
在一个由区间 [-1,1] 中的均匀间隔值定义的二维网格上计算 peaks 函数。
n = -1:0.25:1; Z = peaks(n)
Z = 9×9
1.8559 2.4537 2.2247 0.9965 -0.7239 -2.0151 -2.2222 -1.4251 -0.2729
1.7829 3.0862 3.6265 2.9423 1.3962 -0.0048 -0.4134 0.2037 1.1760
0.7969 2.4879 3.5507 3.3044 1.9975 0.7001 0.3896 1.1388 2.1978
-0.5659 1.2281 2.5614 2.6254 1.5850 0.5256 0.4756 1.4962 2.7556
-1.6523 0.0636 1.4796 1.7530 0.9810 0.1904 0.3744 1.5728 2.9369
-2.1491 -0.6469 0.6823 1.0566 0.5228 -0.0281 0.2795 1.4682 2.7624
-1.9968 -0.7599 0.3898 0.7963 0.4641 0.0898 0.3754 1.3442 2.3768
-1.1629 -0.0458 1.0400 1.5519 1.4226 1.1205 1.1713 1.6492 2.1708
0.2289 1.5069 2.7942 3.5855 3.6886 3.3404 2.9344 2.6622 2.4338
使用计算的值创建一个三维曲面图。
surf(Z)
基于二维网格中的点绘图
使用向量 x
定义的 x 坐标和向量 y
定义的 y 坐标创建二维网格坐标。
x = -2:0.5:2; y = 1:0.2:2; [X,Y] = meshgrid(x,y);
在二维网格上计算 peaks 函数。
Z = peaks(X,Y)
Z = 6×9
-0.4808 -0.8639 0.2289 2.7942 3.6886 2.9344 2.4338 1.5813 0.5805
-0.2470 -0.1924 1.4275 4.5254 5.8902 4.6339 2.8647 1.3897 0.4382
-0.0730 0.3116 2.3394 5.8525 7.5679 5.9243 3.2006 1.2552 0.3350
0.0320 0.5860 2.7339 6.2839 8.1000 6.3260 3.2091 1.1050 0.2561
0.0764 0.6437 2.5958 5.7476 7.3967 5.7698 2.8374 0.9069 0.1901
0.0797 0.5539 2.0967 4.5569 5.8591 4.5675 2.2099 0.6771 0.1328
使用计算的值创建一个三维曲面图。
surf(Z)
分别返回坐标并绘图
输入参数
n
— 表示二维网格的值
标量 | 向量
表示用于计算函数的二维网格的值,指定为标量或向量。
如果
n
是标量,则 MATLAB 将网格创建为[X,Y] = meshgrid(linspace(-3,3,n))
。n
的值必须为大于 1 的整数。如果
n
是向量,则 MATLAB 将网格创建为[X,Y] = meshgrid(n)
。n
的元素必须为双精度数。
例如,Z = peaks(5)
的作用与使用以下代码相同。
[X,Y] = meshgrid(linspace(-3,3,5)); Z = peaks(X,Y)
示例: n = 5
示例: n = -2:0.1:2
Xm
— 点的 x 坐标
标量 | 向量 | 矩阵
点的 x 坐标,指定为标量、向量或矩阵。Xm
和 Ym
的大小必须相同或兼容。您可以使用 meshgrid
函数创建 Xm
和 Ym
。有关兼容数组的详细信息,请参阅基本运算的兼容数组大小。
示例: Xm = [1 2 3; 1 2 3; 1 2 3]
示例: [Xm,Ym] = meshgrid(-5:0.5:5)
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Ym
— 点的 y 坐标
标量 | 向量 | 矩阵
点的 y 坐标,指定为标量、向量或矩阵。Xm
和 Ym
的大小必须相同或兼容。您可以使用 meshgrid
函数创建 Xm
和 Ym
。有关兼容数组的详细信息,请参阅基本运算的兼容数组大小。
示例: Ym = [1 1 1; 2 2 2; 3 3 3]
示例: [Xm,Ym] = meshgrid(-5:0.5:5)
数据类型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
输出参数
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)