2014-10-28 157 views

回答

3

这是你在找什么?

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 

其中给出这样的:

enter image description here

你可以玩的当然是 'FaceAlpha' 属性,以使事情更清晰。看看surf函数获取更多选项。

编辑: 或者到@rayryeng方案来解决对于x,y和z可以使用mldivide

A = [1 1 4;-2 -1 1;3 -2 3]; 
B = [-1;-5;-4]; 

X = mldivide(A,B) 

X = 

    1.0000 
    2.0000 
    -1.0000 
+0

+1 - Magnifique! – rayryeng 2014-10-28 19:49:02

+0

Merci beaucoup! – 2014-10-28 19:51:29

2

这是我怎么会画出这些飞机。 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') 

enter image description here

2

虽然这不是阴谋,或许这也是东西,你可以使用。如果你想确定同时解决这些方程,可以考虑使用solve

syms x y z 
A = solve('x + y + 4*z == -1', '-2*x - y + z == -5', '3*x - 2*y + 3*z == -4') 
disp([A.x A.y A.z]); 

[ 1, 2, -1] 

这将检查您的高斯 - 约旦消是否正确。如果你不喜欢使用solve,你可以使用线性代数来帮助你解决这个问题。只需将您系统的系数放在矩阵和向量中,然后找到矩阵的逆矩阵并乘以向量。

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

x = 

1.0000 
2.0000 
-1.0000 

...甚至另一种方法是使用rref到你的系统减少到行减少梯队形式。这将是您成功将Gauss-Jordan消除应用于线性系统后的结果。因此:

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 = 1y = 2z = -1。这表示增强系统,其中前3列表示系统的系数,第四列表示线性方程组的右侧。

+1

不错,我不知道解决!小调:在第一个等式中,右边是-1而不是1 :) – 2014-10-28 19:56:59

+1

@ Benoit_11 - Merci :) Je viens de correcter。 – rayryeng 2014-10-28 19:57:49

相关问题