?? 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), :);
y_ind = [-yl:res:yl]'; V2 = y_ind(:, ones(length(y_ind),1));
Jv = rp.Jmin + rp.lam1*V1.^2 + rp.lam2*V2.^2; % calculate error surface wrt v
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)
levsv = rp.lam1*v(1,1:Nlevs).^2 + rp.lam2*v(2,1:Nlevs).^2+rp.Jmin;
% do the plotting
figure(1)
p1_h=plot(v(1,:), v(2,:),'linewidth',2);
xlabel('v_1'); ylabel('v_2'); hold on;
contour(V1(1,:), V2(:,1), flipud(Jv), levsv,'k'); hold off
set(gca,'xlim',[-xlim xlim])
set(gca,'xlim',[-ylim ylim])
set(get(gca,'title'),'string',str1);
figure(2)
p2_h=plot(w(1,:), w(2,:),'linewidth',2);
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,
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 + -