使用Matlab绘制三维图像步骤 不要敷衍 如果可以 请绘制Rosenbrock函数
2个回答
展开全部
把这个文件存到一个createfigure.m文件中,运行一下就行了。这个注释挺全的吧?而且画出来的就是rosenbrock函数。有不明白的再问吧~
function createfigure
% Create figure
figure1 = figure('Position',[10 40 1200 600]);
colormap('gray');
axis square;
R=0:.002:1;
TH=2*pi*(0:.002:1);
X=R'*cos(TH);
Y=R'*sin(TH);
Z=log(1+vrosenbrock(X,Y));
% Create subplot
subplot1 = subplot(1,2,1,'Parent',figure1);
view([124 34]);
grid('on');
hold('all');
% Create surface
surf(X,Y,Z,'Parent',subplot1,'LineStyle','none');
% Create contour
contour(X,Y,Z,'Parent',subplot1);
% Create subplot
subplot2 = subplot(1,2,2,'Parent',figure1);
view([234 34]);
grid('on');
hold('all');
% Create surface
surf(X,Y,Z,'Parent',subplot2,'LineStyle','none');
% Create contour
contour(X,Y,Z,'Parent',subplot2);
% The function vrosenbrock, used in createfigure, calculates Rosenbrock's function at a whole vector of points:
function z=vrosenbrock(x,y)
z=100*(y - x.^2).^2 + (1-x).^2;
function createfigure
% Create figure
figure1 = figure('Position',[10 40 1200 600]);
colormap('gray');
axis square;
R=0:.002:1;
TH=2*pi*(0:.002:1);
X=R'*cos(TH);
Y=R'*sin(TH);
Z=log(1+vrosenbrock(X,Y));
% Create subplot
subplot1 = subplot(1,2,1,'Parent',figure1);
view([124 34]);
grid('on');
hold('all');
% Create surface
surf(X,Y,Z,'Parent',subplot1,'LineStyle','none');
% Create contour
contour(X,Y,Z,'Parent',subplot1);
% Create subplot
subplot2 = subplot(1,2,2,'Parent',figure1);
view([234 34]);
grid('on');
hold('all');
% Create surface
surf(X,Y,Z,'Parent',subplot2,'LineStyle','none');
% Create contour
contour(X,Y,Z,'Parent',subplot2);
% The function vrosenbrock, used in createfigure, calculates Rosenbrock's function at a whole vector of points:
function z=vrosenbrock(x,y)
z=100*(y - x.^2).^2 + (1-x).^2;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询