MATLAB程序设计中peaks

 我来答
lhmhz
高粉答主

推荐于2017-07-17 · 专注matlab等在各领域中的应用。
lhmhz
采纳数:7264 获赞数:17013

向TA提问 私信TA
展开全部

peaks是MATLAB自带的双变量的实例函数。使用格式:

Z = peaks   %生成49×49的矩阵

Z = peaks(n)   %生成n×n的矩阵

Z = peaks(X,Y)   %计算给定x和y(必须是相同大小)的峰值,并返回一个大小相同的矩阵。

其他应用,如

>> [X,Y,Z] = peaks(10)

>> surf(X,Y,Z)

dbb627
2011-07-12 · TA获得超过1.2万个赞
知道大有可为答主
回答量:2127
采纳率:88%
帮助的人:1403万
展开全部
为了方便测试立体绘图,MATLAB提供了一个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)
http://cs.nju.edu.cn/yangxc/dcc2003.files/matlab1/matlabsimple/index-1.htm
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
奔放还华丽丶喜鹊6283
2011-07-13 · TA获得超过289个赞
知道答主
回答量:430
采纳率:0%
帮助的人:0
展开全部
看看源程序就明白了。

>> type peaks

function [xz,y,z] = peaks(arg1,arg2)
%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.

% CBM, 2-1-92, 8-11-92, 4-30-94.
% Copyright 1984-2006 The MathWorks, Inc.
% $Revision: 5.10.4.3 $ $Date: 2006/06/27 23:02:56 $

if nargin == 0
dx = 1/8;
[x,y] = meshgrid(-3:dx:3);
elseif nargin == 1
if length(arg1) == 1
[x,y] = meshgrid(linspace(-3,3,arg1));
else
[x,y] = meshgrid(arg1,arg1);
end
else
x = arg1; y = arg2;
end

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);

if nargout > 1
xz = x;
elseif nargout == 1
xz = z;
else
% Self demonstration
disp(' ')
disp('z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... ')
disp(' - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... ')
disp(' - 1/3*exp(-(x+1).^2 - y.^2) ')
disp(' ')
surf(x,y,z)
axis('tight')
xlabel('x'), ylabel('y'), title('Peaks')
end
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式