📄 make_plot.m
字号:
function make_plot(v, w, rp, Nlevs, xlim, ylim, str1, str2)
% function make_plot(w, v, rp, Nlevs, xlim, ylim)
r0 = 1;
r1 = -(rp.a1/(1+rp.a2));
R = [r0 r1; r1 r0];
wo = [-rp.a1; -rp.a2];
% set limits on plotting and determine grid
res = 0.1;
xl=max([xlim ylim]); yl=xl;
x_ind = -xl:res:xl; V1 = x_ind(ones(length(x_ind),1), :);%每个点都产生length(x_ind)个构成一列,共length(x_ind)列
y_ind = [-yl:res:yl]'; V2 = y_ind(:, ones(length(y_ind),1));%每个点都产生length(y_ind)个构成一行,共length(y_ind)行
Jv = rp.Jmin + rp.lam1*V1.^2 + rp.lam2*V2.^2; % calculate error surface wrt v,使用V1的一行和V2的一列画一个椭圆,V1和V2都是方阵
for i=1:length(x_ind),
for j=1:length(y_ind),
wb=[x_ind(i); y_ind(j)];
Jw(j,i) = rp.Jmin + (wb-wo)'*R*(wb-wo);
end
end
% determine values for first Nlevs contours (for given n),确定前Nlevs条等高线的值
levsv = rp.lam1*v(1,1:Nlevs).^2 + rp.lam2*v(2,1:Nlevs).^2+rp.Jmin;%前Nlevs条椭圆轨道等高线
% do the plotting
figure(1)
p1_h=plot(v(1,:), v(2,:),'linewidth',2);%式4.34曲线收敛运动轨迹
xlabel('v_1'); ylabel('v_2'); hold on;%hold on 在当前图基础上继续画图,hold off复位画图默认值
contour(V1(1,:), V2(:,1),flipud(Jv), levsv,'k'); hold off;%画前Nlevs条椭圆轨道等高线,flipud对矩阵上下翻转,本例程中要flipud与否无影响,levsv确定了等高线的值,只画Nlevs条
set(gca,'xlim',[-xlim xlim]) %xlim定义坐标轴的极限,set用于设置坐标轴的特性,gca用于返回当前轴的句柄
set(gca,'xlim',[-ylim ylim])
set(get(gca,'title'),'string',str1);%get用于获得已有轴的各种特性,此set用于设置标题
figure(2)
p2_h=plot(w(1,:), w(2,:),'linewidth',2);%式4.37曲线收敛运动轨迹
xlabel('w_1'); ylabel('w_2'); hold on;
contour(x_ind, y_ind, Jw, levsv,'k'); hold off
set(get(gca,'title'),'string',str2);
% note that Jw did not need flipping - this was taken care of by the
% index shuffle in the line that assigns values to Jw in the double
% loop up above
if nargin > 5,%nargin 输入参数的个数
for i=1:2,
figure(i)
set(gca, 'Xlim', [-xlim xlim])
set(gca, 'Ylim', [-ylim ylim])
line([-xlim xlim], [0 0])
line([0 0], [-ylim ylim])
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -