Wednesday, 23 April 2014

Systems of Linear Equation in 2 Variable

How many can systems of linear equation have?

  1. 1 Solution
  2. Infinite Solutions
  3. No Solution


A) 
If (a1 / a2 != b1 / b2), it involves lines that intersect exactly 1 time.
-- Situation 1

B) 
If (a1 / a2 == b1 / b2 == c1 / c2), it's a same line.
-- Situation 2


C)
If (a1 / a2 == b1 / b2 != c1 / c2), lines are parallel.
-- Situation 3


[Cramer's Rule]



where  A_i  is the matrix formed by replacing the ith column of  A  by the column vector  b .

 




to solve:http://zerojudge.tw/ShowProblem?problemid=a410
Code:

/**********************************************************************************/
/* Problem: a410 "解方程" from TYVJ */
/* Language: C (552 Bytes) */
/* Result: AC(0ms, 328KB) judge by this@ZeroJudge */
/* Author: birdca at 2014-04-24 14:12:05 */
/**********************************************************************************/
#include <stdio.h>
int main()
{
int a, b, c, d, e, f;
while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF)
{
double tmp = a * e - b * d;
if (tmp == 0)
{
if (c * e == b * f)
printf("Too many\n");
else
printf("No answer\n");
}
else
{
printf("x=%.2lf\n", (double) (c * e - b * f) / tmp);
printf("y=%.2lf\n", (double) (a * f - c * d) / tmp);
}
}
return 0;
}


Ref. http://en.wikipedia.org/wiki/Cramer%27s_rule

No comments:

Post a Comment