Catch-up Method for Solving Equations

Source: Internet
Author: User
//  Catch-up method for solving the equation group pursue. cpp # Include <iostream> # Include <Vector> # Include <Algorithm> Using   Namespace  STD;  Class  Solutionequations {  Private  : Vector < Double > A; vector < Double > B; vector < Double > C; vector < Double > F; vector < Double > X;  Public  :  Void Setabcf (vector < Double > In_a, vector < Double > In_ B, vector < Double > In_c, vector < Double > In_f) { = In_a; B = In_ B; c = In_c; f = In_f ;}  //  Catch-up Method for Solving Equations Vector < Double > & Pursue () {Vector < Double > Bita; vector <Double > Y;  Int N = F. Size (); bita. push_back (C. (  0 )/B. ( 0  ); Y. push_back (F. (  0 )/B. ( 0  ));  For ( Int I = 1 ; I <n- 1 ; I ++){  Double Alpha = B. at (I)-A. at (I) * bita. At (I- 1  );  Double TMP = C. at (I )/ Alpha; bita. push_back (TMP); TMP = (F. at (I)-A. at (I) * Y. At (I- 1 ))/ Alpha; Y. push_back (TMP );}  Double Alpha = B. At (n- 1 )-A. At (n- 1 ) * Bita. At (n- 2 );  Double TMP = (F. At (n- 1 )-A. At (n- 1 ) * Y. At (n- 2 ))/ Alpha; Y. push_back (TMP); X. push_back (Y. At (n - 1  ));  For ( Int I = N- 2 , K = 0 ; I> = 0 ; I --, K ++){  Double TMP = Y. at (I)-bita. at (I )* X. At (k); X. push_back (TMP);} reverse (X. Begin (), X. End ());  Return  X ;}};  Int  Main () {solutionequations solution; vector < Double > A; vector < Double > B; vector < Double >C; vector < Double > F; A. push_back (  0  ); A. push_back ( - 1  ); A. push_back ( - 2  ); A. push_back ( - 3  ); B. push_back (  2  ); B. push_back (  3 ); B. push_back (  4  ); B. push_back (  5  ); C. push_back ( - 1  ); C. push_back ( - 2  ); C. push_back ( - 3  ); F. push_back (  6  ); F. push_back (  1  ); F. push_back ( -2  ); F. push_back (  1  ); Solution. setabcf (A, B, C, F); vector < Double > X = Solution. Pursue ();  For ( Int I = 0 ; I <X. Size (); I ++ ) {Cout < "  X =  " <X. at (I) <Endl ;}}


 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.