轮廓线和曲面Matlab

时间:2016-11-15 08:48:19

标签: matlab contour surface

我想在Matlab中生成表面上具有预定义轮廓线的曲面图。我已经在Mathematica中制作了这个情节,并希望在Matlab中创建相应的数字。

通过以下功能,我定义了一个表面

k2[G_, V_] = Sqrt[G]*Exp[-V];
k1[G_] = Sqrt[G]*Exp[-10];
L1[G_, V_] = -0.5*(k1[G_] + 2*k2[G, V]) + 0.5*Sqrt[k1[G_]^2 + 4*k2[G, V]^2];

和表面上的参数曲线

hike=ParametricPlot3D[{10, 0, 0} + {x^2, x, -(1/L1[10 + x^2, x])}, {x, 0, 12},PlotStyle -> Directive[Thick, Red]];
hikeHeight=ParametricPlot3D[{10, 0, 0} + {x^2,x, -z*(1/L1[10 + x^2, x])}, {x, 0, 12}, {z, 0, 1},PlotStyle -> Directive[Gray], Mesh -> None];

然后我将曲面和轮廓线一起绘制:

surf= Plot3D[-1/L1[G, V], {G, 10, 100}, {V, 0, 12}];
Show[surf, hike, hikeHeight, AxesLabel -> {G, V,Z}, Boxed -> False]

enter image description here

在Matlab中评估函数和生成相同图的过程是什么?

这与我的matlab尝试相比有多远

[X,Y,Z] = peaks(25);
curvX=diag(X);
curvY=diag(Y);
curvZ=diag(Z);

nn = 401;
xi = linspace(-3.0, 3.0, nn);
yi = xi;
[xi, yi] = meshgrid(xi, yi);
zi = interp2(X, Y, Z, xi, yi, 'spline');

figure()
surf(xi, yi, zi,'LineStyle', 'none', 'FaceColor', 'interp')
colormap(parula)
alpha 0.7
hold on
surf(diag(curvX),diag(curvY),diag(curvZ),'LineStyle', 'none')

enter image description here

表面和参数曲线显然不一样,但绘制表面切片的想法是相同的

1 个答案:

答案 0 :(得分:2)

让我们从定义函数开始,如内联向量化函数句柄:

k2 = @(g, v)sqrt(g).*exp(-v);
k1 = @(g)sqrt(g).*exp(-10);
l1 = @(g, v) -.5 .* (k1(g) + 2.*k2(g, v)) + 0.5 * sqrt(k1(g).^2 + 4.*k2(g, v).^2);

现在我们需要定义一个网格,因为Matlab不够聪明,不能像Mathematica那样进行自动离散:

nMeshPoints = 50;

vfG = linspace(10, 100, nMeshPoints);
vfV = linspace(0, 12, nMeshPoints);
[mfG, mfV] = ndgrid(vfG, vfV);

好的,现在我们可以评估网格上的表面,并制作表面图:

hSurf = surf(mfG, mfV, -1./l1(mfG, mfV));
shading interp;
hold on;
hSurf.FaceAlpha = 0.5;

现在我们需要构建和绘制参数线,也可以通过明确的离散化来实现:

vfX = linspace(0, 12, nMeshPoints);
vfZ = linspace(0, 1, nMeshPoints);

vfLX = 10 + vfX.^2;
vfLY = vfX;
vfLZ = -(1 ./ l1(10 + vfX.^2, vfX));

vfLHeight = vfLZ .* vfZ;

plot3(vfLX, vfLY, vfLZ, 'r-');
plot3(vfLX, vfLY, vfLHeight, 'k-');

现在我们可以让情节变得更漂亮了:

xlim([10 100]);
ylim([0 12]);
zlim([0 20000]);
caxis([0 20000]); 
xlabel('G');
ylabel('V');
zlabel('Z');
view([60, 30]);

结果:不像Mathematica那么漂亮,但至少相当于。

Surface plot with contour

相关问题