两个方程和两个未知数在matlab中的不同数字

时间:2014-03-25 10:49:37

标签: matlab equation

如何解决为不同数字编写的两个方程和两个未知数代码?

例如:

aX + bY = c * d
x + y = c
c = 3
d = 30

用于ab用于不同的

a = [0:1:30]
b = [60:1:90]

代表a=1 b=60a=1 b=61,..... a=30 b=90

数字ab是常数,XY未知。

1 个答案:

答案 0 :(得分:2)

示例:

%// all a and b you're interested in
As = [(0:30)' (60:90)'];

%// the solution vector is always the same
b  = [90; 3];

%// solve all systems using mldivide
for ii = size(As,1):-1:1
    XY(ii,:) = [As(ii,:); [1 1]]\b; end

但是,如果你更聪明,你就已经认识到了

  x = c - y
⇒ a(c-y) = c·d - by
⇒ y = c·(a-d)/(a-b)

因此,你已编码

a = 0:30;    c = 3;
b = 60:90;   d = 30;

y = c*(a-d)./(a-b);
x = c - y;