使用Matlab绘制三维图像步骤 不要敷衍 如果可以 请绘制Rosenbrock函数
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/07/11 18:09:45
使用Matlab绘制三维图像步骤 不要敷衍 如果可以 请绘制Rosenbrock函数
![使用Matlab绘制三维图像步骤 不要敷衍 如果可以 请绘制Rosenbrock函数](/uploads/image/z/8604796-4-6.jpg?t=%E4%BD%BF%E7%94%A8Matlab%E7%BB%98%E5%88%B6%E4%B8%89%E7%BB%B4%E5%9B%BE%E5%83%8F%E6%AD%A5%E9%AA%A4+%E4%B8%8D%E8%A6%81%E6%95%B7%E8%A1%8D+%E5%A6%82%E6%9E%9C%E5%8F%AF%E4%BB%A5+%E8%AF%B7%E7%BB%98%E5%88%B6Rosenbrock%E5%87%BD%E6%95%B0)
把这个文件存到一个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;