线性方程组的几何意义:
>> B1=[2 1 3;3 -1 2];
>> B2=[1 2 -5;3 6 2];
>> B3=[1 2 3;2 4 6];
>> B4=[1 2 -5;3 6 2;1 -2 5];
>> U1=rref(B1)
U1 =
1 0 1
0 1 1
>> U2=rref(B2)
U2 =
1 2 0
0 0 1
>> U3=rref(B3)
U3 =
1 2 3
0 0 0
>> U4=rref(B4)
U4 =
1 0 0
0 1 0
0 0 1
subplot(2,2,1)
h1=ezplot('2*x1+x2-3');
set(h1,'color','b','linewidth',2)
hold on
h2=ezplot('3*x1-x2-2');
set(h2,'color','r','linewidth',2)
title('方程组1')
grid on
subplot(2,2,2)
h1=ezplot('x1+2*x2+5');
set(h1,'color','b','linewidth',2)
hold on
h2=ezplot('3*x1+6*x2-2');
set(h2,'color','r','linewidth',2)
title('方程组2')
grid on
subplot(2,2,3)
h1=ezplot('x1+2*x2-3');
set(h1,'color','b','linewidth',2)
hold on
h2=ezplot('2*x1+4*x2-6');
set(h2,'color','r','linewidth',2)
title('方程组3')
grid on
subplot(2,2,4)
h1=ezplot('2*x1+x2-3');
set(h1,'color','b','linewidth',2)
hold on
h2=ezplot('3*x1-x2-2');
set(h2,'color','r','linewidth',2)
h2=ezplot('x1+x2-2');
set(h2,'color','k','linewidth',2)
title('方程组4')
grid on
close all
A1=[1 5 -1;3 -3 -1;2 1 1];
b1=[8 -6 7]';
U1=rref([A1,b1])
subplot(2,2,1)
ezmesh('x1+5*x2-8');
hold on
ezmesh('3*x1-3*x2+6');
ezmesh('-2*x1-x2+7');
title('方程组1')
A2=[1 1 -1;2 1 -1;5 -2 2];
b2=[0 0 0]';
U2=rref([A2,b2])
subplot(2,2,2)
ezmesh('x1+x2');
hold on
ezmesh('2*x1+x2');
ezmesh('-2.5*x1+x2');
title('方程组2')
A3=[1 -2 -1;1 3 -1;1 3 -1];
b3=[4 6 20]';
U3=rref([A3,b3])
subplot(2,2,3)
ezmesh('x1-2*x2-4');
hold on
ezmesh('x1+3*x2-6');
ezmesh('x1+3*x2-20');
title('方程组3')
A4=[3 -1;5 2;0 1];
b4=[5 10 15]';
U4=rref([A4,b4])
subplot(2,2,4)
ezmesh('3*x2-5');
hold on
ezmesh('-2.5*x2+5');
ezmesh('15');
title('方程组4')
U1 =
1 0 0 1
0 1 0 2
0 0 1 3
U2 =
1 0 0 0
0 1 -1 0
0 0 0 0
U3 =
1 0 -1 0
0 1 0 0
0 0 0 1
U4 =
1 0 0
0 1 0
0 0 1
线性方程组的应用
>> A=[8.3 7.4 20 2.6 1.4;
2.5 3.2 10.2 0.4 0.2;
74.2 2.7 1.7 2.0 8.8;
14 277 7.2 106 32;
2.3 1.9 4.4 1.2 1.5;
1.7 1.2 6.9 0.3 0.3];
>> b=[24.2 9 60.3 389 8.7 5.7]';
>> r=rank(A)
r =
5
>> r1=rank([A,b])
r1 =
6
方程组无解,求最下二乘解:
>> X=A\b
X =
0.5265
0.7069
0.4488
1.1657
1.8442
营养餐配方:
大米:53克
豆腐:71克
牛肉:45克
油菜:117克
萝卜:184克
>> A=[1 0 0 0 0 1;1 -1 0 0 0 0;0 1 -1 0 0 0;0 0 0 0 1 1;0 0 0 1 -1 0;0 0 1 -1 0 0];
>> b=[70 20 -58 44 -5 69]';
>> r=rank(A)
r =
5
>> r1=rank([A,b])
r1 =
5
所以,方程组有无穷多个解