Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中绘制x,y,z?_Matlab_Plot - Fatal编程技术网

如何在matlab中绘制x,y,z?

如何在matlab中绘制x,y,z?,matlab,plot,Matlab,Plot,我在matlab中制作Gauss-Jordan方法,我想画出这些方程 x + y + 4*z = -1 -2*x – y + z= -5 3*x-2*y+3*z=-4 要查看它们在图形的哪个点相交,但我不知道如何在matlab中绘制,这就是您要查找的吗 clc clear close all %// Generate x and y values to plot from. [x,y] = meshgrid(linspace(0,10,100),linspace(0,10,100));

我在matlab中制作Gauss-Jordan方法,我想画出这些方程

x + y + 4*z = -1 
-2*x – y + z= -5 
3*x-2*y+3*z=-4

要查看它们在图形的哪个点相交,但我不知道如何在matlab中绘制,这就是您要查找的吗

clc
clear
close all

%// Generate x and y values to plot from.
[x,y] = meshgrid(linspace(0,10,100),linspace(0,10,100));

%// Get equation for plane; i.e. z position
z1 = 0.25.*(-1-x-y);
z2 = -5+y+2*x;
z3 = (-4-3.*x+2.*y)./3;

%// Use surf to generate surface plots
figure;

surf(x,y,z1,'linestyle','none','facealpha',0.4)
hold on
surf(x,y,z2,'linestyle','none','facealpha',0.4)
surf(x,y,z3,'linestyle','none','facealpha',0.4)
hold off

%// Use to manually rotate the plot
rotate3d on
因此:

当然,您可以使用“FaceAlpha”属性使事情更清楚。查看该函数以了解更多选项

编辑: 除@rayryeng solution外,您还可以使用:


下面是我将如何绘制这些平面。
surf
的第4个参数用于指定颜色

% // create function handles of form z = f(x,y)
f1 = @(X,Y) 1/4*(-1 - X -Y);
f2 = @(X,Y) -5 + 2*X + Y;
f3 = @(X,Y) 1/3*(-4 -3*X + 2*Y);

% // create a 2d-grid to plot the functions over
x = linspace(-5, 5, 10);
y = linspace(-10, 10, 20);
[X,Y] = meshgrid(x,y);

% // plot the planes in different colors (4th argument) and without edges
figure
surf(X, Y, f1(X,Y), ones(size(f1(X,Y))), 'EdgeColor', 'None');
hold on
surf(X, Y, f2(X,Y), ones(size(f2(X,Y)))*2, 'EdgeColor', 'None');
surf(X, Y, f3(X,Y), ones(size(f3(X,Y)))*3, 'EdgeColor', 'None');
legend('plane1', 'plane2', 'plane3')
xlabel('x'), ylabel('y'), zlabel('z')

虽然这不是绘图,但也许这也是您可以使用的。如果要确定这些方程的同时解,考虑使用< /P> 这将检查高斯-乔丹消去法是否正确。如果您不喜欢使用
求解
,可以使用线性代数来帮助您解决此问题。只需将系统的系数放在矩阵和向量中,然后求矩阵的倒数并乘以向量

A = [1 1 4; -2 -1 1; 3 -2 3];
b = [-1;-5;-4];
x = A \ b

x =

1.0000
2.0000
-1.0000
。。。甚至还有另一种方法是将系统缩减为行缩减的梯队形式。这将是成功地将高斯-乔丹消去法应用于线性系统后的结果。因此:

A = [1 1 4; -2 -1 1; 3 -2 3];
b = [-1;-5;-4];
rref([A b])


ans =

 1     0     0     1
 0     1     0     2
 0     0     1    -1

阅读上述答案,
x=1
y=2
z=-1
。这表示增强系统,其中前3列表示系统的系数,第4列表示线性方程组的右侧。

Nice我不知道解!小注:在第1个等式中,右侧为-1,而不是1:)
A = [1 1 4; -2 -1 1; 3 -2 3];
b = [-1;-5;-4];
x = A \ b

x =

1.0000
2.0000
-1.0000
A = [1 1 4; -2 -1 1; 3 -2 3];
b = [-1;-5;-4];
rref([A b])


ans =

 1     0     0     1
 0     1     0     2
 0     0     1    -1