2013-01-29 5 views
-1

안녕하세요 숙제를위한 솔루션 코드를 작성하는 데 문제가 있습니다. 나는 사용자에게 2 개의 방정식을위한 6 개의 변수를 입력하라고 요구할 필요가있다. 성공적으로 숫자를 가져온 후에는 각 행의 기울기, 각 행의 y 절편, 솔루션이있는 경우 각 행의 두 점 ((2,1)과 같은 순서쌍)을 찾아야합니다. 또한 관계가 무엇인지. 나는 주로 숫자 검사와 방정식을 수색하고 수색했다. 제가 문제가되는 것은 방정식에 대한 요점과 해답을 찾는 것입니다.C++을 사용하는 2 선형 방정식 시스템

#include <iostream> 
#include <limits> 

int main() 
{ 
std::cout<<"This program is designed to test two linear equations. \n"; 
std::cout<<"In order to best solve the system, \n"; 
std::cout<<"equations will be in the form of a*x + b*y = c. \n"; 
std::cout<<"and d*x + e*y =f. \n"; 
std::cout<<"Please enter an integer for a, b, and c. \n"; 
double a, b, c, d, e, f; 

while ((std::cout << "Enter a.") 
    && !(std::cin >> a)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
} 
while ((std::cout << "Enter b.") 
      && !(std::cin >> b)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
} 
while ((std::cout << "Enter c.") 
      && !(std::cin >> c)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
} 
std::cout<<"Equation 1 is "<<a<<"x +"<<b<<"y ="<<c; 

std::cout<<"Please enter an integer for d, e, and f. \n"; 

while ((std::cout << "Enter d.") 
     && !(std::cin >> d)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
} 
while ((std::cout << "Enter e.") 
      && !(std::cin >> e)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
} 
while ((std::cout << "Enter f.") 
      && !(std::cin >> f)) 
{ 
    std::cout << "That's not a number "; 
    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
    } 
    std::cout<<"Equation 2 is "<<d<<"x +"<<e<<"y ="<<f; 

    double slope1, slope2; 
    double x1, x2, y1, y2; 
    slope1 = (b/a); 
    slope2 = (e/d); 
    std::cout<<" Slope of Equation 1 is "<<slope1<<"\n"; 
    std::cout<<" Slope of Equation 2 is "<<slope2<<"\n"; 

    x1 = ((c*e)-(b*f))/ ((a*e)-(b*d)); 
    y1 = ((a*f)-(c*d))/ ((a*e)-(b*d)); 

    return 0; 
} 
+0

구체적인 질문이 무엇인지 명확히 할 수 있습니까? –

+0

나의 구체적인 질문은 어떻게 각 방정식의 선상에 2 점을 얻고 방정식을 풀 수 있는가이다. –

답변

1

뭔가 다른 점은 선형 방정식을 풀기 위해 행렬을 사용하는 것입니다.

많은 계산자가 증가 매트릭스의 제형에 계산을 사용합니다.

즉.

배 + 3Y = 36 X + 9Y = 8

[2 (3) 36] [1-9 8

그래서이 증가되는 행렬 및 다음으로 변환하도록 작동 제대 양식. 선형 대수학 교수는 이것이 프로그래머가 방정식 시스템에 계산을 쓰는 데 사용하는 가장 일반적인 방법이라고 말합니다.

나는 그것을 가르 칠 수있는 자격이 충분하지 않으므로 여기서는 멋진 기사입니다.

http://stattrek.com/matrix-algebra/echelon-form.aspx

+0

저는 이번 학기의 C++에서 행렬을 실제로 다루지 않았습니다. –

0

Solving Systems of Equations Using Determinants

enter image description here

유무 사용자가 A, B, C, and D, E, F를 입력하고 cin를 사용하여 당신이 이미하고있는대로 받아 들일 참조하십시오. (제안 : 각 방정식에 대해 3 요소 배열을 사용하십시오.)

일단 계산식을 사용하면 솔루션을 직접 계산할 수 있습니다.

+2

전체 페이지가 저작권으로 보호됩니다 (제목 참조). 수식은 일반적인 지식이지만, 당신은 아마 자신의 웹 사이트에서 그 사진을 찍을 수있는 권한이 없습니다. – us2012

+0

좋아,이 작업을 시작하겠습니다. –