By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

how to do the matrix 5x5..i already have the non diagonal.but,how to get the diagonal

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <complex>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14. int a,b,nbr=0,nbus;
  15. float c,d,e;
  16. vector<int> nl;
  17. vector<int> nr;
  18. vector<float> R;
  19. vector<float> X;
  20. vector<float> Bc;
  21. complex<float>* Z=NULL;
  22. complex<float>* y=NULL;
  23. vector<vector<complex<float>>> ybus;
  24.  
  25. // First, get the number of line
  26. ifstream mydata("load flow.txt");
  27. string t3;
  28. nbr=0;
  29. while ( !mydata.eof())
  30. {
  31. while(getline(mydata, t3, '\n'))
  32. ++nbr;
  33. }mydata.close();
  34. // then read and get all the data in power flow data.txt
  35. ifstream input ("load flow.txt");
  36. for(int w=0;w<nbr;++w)
  37. {
  38. input >> a >>b >> c >>d >> e;
  39. nl.push_back(a);
  40. nr.push_back(b);
  41. R.push_back(c);
  42. X.push_back(d);
  43. Bc.push_back(e);
  44.  
  45. cout<< a <<'\t' << b <<'\t'<< c <<'\t'<< d <<'\t'<< e<<'\t' <<endl;
  46.  
  47. complex <double> Z( c , d );
  48. cout << "Z = " << Z << endl;
  49. complex <double> y=1./Z;
  50. cout<<y<<endl;
  51.  
  52.  
  53.  
  54.  
  55. }mydata.close();
  56.  
  57. return 0;
  58. }

my data is:
1 2 0.02 0.06 0.03
1 4 0.08 0.24 0.025
2 4 0.06 0.24 0.020
2 3 0.06 0.18 0.020
3 4 0.04 0.12 0.010
3 5 0.01 0.03 0.015
4 5 0.08 0.24 0.025
Aug 29 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.