补全代码 sigma = 1; x = -2:0.01:2; y = -2:0.01:1.5; [X, Y] = meshgrid(x, y); %X = X; %Y = Y; P_E = X + sqrt(3) * Y + sigma/2 * (X.^2+Y.^2-1).^2; figure subplot(121) contour(X, Y, P_E, 80) sigma = 8; x = -2:0.01:2; y = -2:0.01:1.5; [X, Y] = meshgrid(x
时间: 2024-03-27 10:35:56 浏览: 148
sigma-pathfinding-astar:Sigma.js的A *实现
以下是代码的完整版:
```matlab
sigma = 1;
x = -2:0.01:2;
y = -2:0.01:1.5;
[X, Y] = meshgrid(x, y);
P_E = X + sqrt(3) * Y + sigma/2 * (X.^2+Y.^2-1).^2;
figure
subplot(121)
contour(X, Y, P_E, 80)
sigma = 8;
x = -2:0.01:2;
y = -2:0.01:1.5;
[X, Y] = meshgrid(x, y);
P_E = X + sqrt(3) * Y + sigma/2 * (X.^2+Y.^2-1).^2;
subplot(122)
contour(X, Y, P_E, 80)
```
这段代码是用MATLAB实现的,其中包含两个子图,分别对应着不同的惩罚系数sigma。首先,我们在一个二维网格上计算出函数P_E的值,然后通过contour函数绘制出等高线图。其中,sigma=1和sigma=8分别对应着左右两张子图。可以看到,当sigma变大时,等高线图变得更加陡峭,目标函数的极小值也变得更加明显。
阅读全文