Solving ternary first-time equations (c + +)

Source: Internet
Author: User

/** * Author:johnny Zen * date:2017-09-20 11:19 * function:calculate ternary system of equations * Notice: Time rush, just realize the function, square  Then use, code quality is not reference!!! */#include<iostream>using namespacestd;template<classT>voidInput (T matrix[4][5]) {cout<<"Please input matrix element ' s data"<<Endl;  for(inti =1;i<4; i++){         for(intj=1;j<5; j + +) {cin>>Matrix[i][j]; }} cout<<"input OK";} Template<classT>voidCalc (T matrix[4][5]) {T base_d= matrix[1][1]*matrix[2][2]*matrix[3][3] + matrix[2][1]*matrix[3][2]*matrix[1][3] + matrix[3][1]*matrix[1][2]*matrix[2][3];//Calculate determinantBase_d = base_d-(matrix[1][3]*matrix[2][2]*matrix[3][1] + matrix[1][1]*matrix[2][3]*matrix[3][2] + matrix[1][2]*matrix[2][1]*matrix[3][3]); if(Base_d! =0) {T x_d= matrix[1][4]*matrix[2][2]*matrix[3][3] + matrix[2][4]*matrix[3][2]*matrix[1][3] + matrix[3][4]*matrix[1][2]*matrix[2][3]; X_d= x_d-(matrix[1][3]*matrix[2][2]*matrix[3][4] + matrix[1][4]*matrix[2][3]*matrix[3][2] + matrix[1][2]*matrix[2][4]*matrix[3][3]); T Y_d= matrix[1][1]*matrix[2][4]*matrix[3][3] + matrix[2][1]*matrix[3][4]*matrix[1][3] + matrix[3][1]*matrix[1][4]*matrix[2][3]; Y_d= y_d-(matrix[1][3]*matrix[2][4]*matrix[3][1] + matrix[1][1]*matrix[2][3]*matrix[3][4] + matrix[1][4]*matrix[2][1]*matrix[3][3]); T Z_d= matrix[1][1]*matrix[2][2]*matrix[3][4] + matrix[2][1]*matrix[3][2]*matrix[1][4] + matrix[3][1]*matrix[1][2]*matrix[2][4]; Z_d= z_d-(matrix[1][4]*matrix[2][2]*matrix[3][1] + matrix[1][1]*matrix[2][4]*matrix[3][2] + matrix[1][2]*matrix[2][1]*matrix[3][4]); T x= x_d/base_d; T y= y_d/base_d; T Z= z_d/base_d; cout<<"[x:"<<x<<"; y:"<<y<<"; Z:"<<z<<" ]"<<Endl; }Else{cout<<""no Solution"";//return dbl_min;    }}intMain () {Doublematrix[4][5] ;//ternary one-time equation groupinput<Double>(matrix); Calc<Double>(matrix); System ("Pause"); return 0;}/*
Demo
2x-y+z=10;3x+2y-z=16;x+6y-z=28; 2-1 1 103 2-1 161 6-1 28output:input ok[x:4.18182; y:5.09091; z:6.72727]*/

Solving ternary first-time equations (c + +)

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.