使用matlab在3D中绘制函数

时间:2014-09-10 04:23:11

标签: matlab plot 3d

我想在MATLAB中将此函数绘制为三维绘图,两种情况,任何人都可以帮助我吗?谢谢。

f(x,y) = (1-x) + ((2x - 1) y / k)

其中

案例1)

x = [0,1]  // closed unit interval with real values
y = [0,1]  // closed unit interval with real values
k = 10 is a constant

案例2)

x has domain [0,1] // closed unit interval with real values
y has domain [0,1] // closed unit interval with real values
k has domain [0,1] // closed unit interval with real values

2 个答案:

答案 0 :(得分:1)

这可能会有所帮助

[X,Y] = meshgrid(0:.1:1);
K = 10;
F = (ones(11) - X) + ((2*X - ones(11)) * Y / K);
figure
mesh(F);

enter image description here

案例2的

figure
for K 0:.1:1
    F = (ones(11) - X) + ((2*X - ones(11)) * Y / K);
    hold on
    mesh(F);
end

enter image description here

答案 1 :(得分:0)

尝试以下内容:

%Case 1:
x = 0:.05:1;
n = numel(x);
y = x';
X = repmat(x,n,1);
Y = repmat(y,1,n);
f = @(x,y) (1-x)+((2*x-1).*y)/10;
v = f(X,Y);
figure;mesh(x,y,v);

%Case 2:
x = 0:.05:1;
n = numel(x);
y = x';
X = repmat(x,n,1);
Y = repmat(y,1,n);
figure;
for k = x
    f = @(x,y) (1-x)+((2*x-1).*y)/k;
    v = f(X,Y);
    hold on;
    mesh(x,y,v);
end

如果要绘制曲面而不是网格,请将mesh替换为surf,如果您想要更精细的网格(在案例2中绘制更多细节和更多函数),请更改{的中间数字{ {1}}更小的内容,如x = 0:.05:1;,如果你想要更粗糙的网格(在案例2中绘制更少的细节和更少的函数),将x = 0:.01:1;的中间数字更改为更大的x = 0:.05:1; }。

我希望这能解决你的问题!