User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,272 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,435 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 332 | Replies: 3
Reply
Join Date: Aug 2008
Posts: 36
Reputation: shamila08 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
shamila08 shamila08 is offline Offline
Light Poster

computing determinant by upper triangular decomposition

  #1  
Sep 17th, 2008
Hello, dear all. My algorithm as follows. my input is in Code2D.h file. actually i have to put in file 'Code2D.in'. but i dont know have to create it. By the way, my algorithm have no problem with N <= 4. but when i change N = 5, 6 , or 7, so on. the output is trouble. is it something is not right?
  1. #include <fstream>
  2. #include <iostream>
  3. #define N 5
  4. using namespace std;
  5. void main()
  6. {
  7. int i,j,k;
  8. double A[N+1][N+1];
  9.  
  10. cout.setf(ios::fixed);
  11. cout.precision(5);
  12. cout << "Input matrix A: " << endl;
  13. ifstream InFile("Code2D.h");
  14. for (i=1;i<=N;i++)
  15. {
  16. for (j=1;j<=N;j++)
  17. {
  18. InFile >> A[i][j];
  19. cout << A[i][j] << " ";
  20. }
  21. cout << endl;
  22. }
  23. InFile.close();
  24.  
  25. // row operations
  26. double Product,m;
  27. for (k=1;k<=N-1;k++)
  28. for (i=k+1;i<=N;i++)
  29. {
  30. m=A[i][k]/A[k][k];
  31. for (j=1;j<=N;j++)
  32. A[i][j]-=m*A[k][j];
  33. }
  34.  
  35. cout << endl << "matrix U:" << endl;
  36. for (i=1;i<=N;i++)
  37. {
  38. for (j=1;j<=N;j++)
  39. cout << A[i][j] << " ";
  40. cout << endl;
  41. }
  42.  
  43. Product=1;
  44. for (i=1;i<=N;i++)
  45. Product *= A[i][i]; // determinant
  46.  
  47. // display results
  48. cout << endl << "det(A)=" << Product << endl;
  49. }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,539
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: computing determinant by upper triangular decomposition

  #2  
Sep 17th, 2008
>>for (i=1;i<=N;i++)
That's a problem. Arrays indices always, always begin with 0, never with 1. So what you want there is this: for(i = 0; i < N; i++) The same with the other loops.

>>my algorithm have no problem with N <= 4.
Only because you were lucky, not because your code is right.
Last edited by Ancient Dragon : Sep 17th, 2008 at 7:27 am.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Jul 2008
Posts: 884
Reputation: ArkM is just really nice ArkM is just really nice ArkM is just really nice ArkM is just really nice ArkM is just really nice 
Rep Power: 6
Solved Threads: 121
ArkM's Avatar
ArkM ArkM is online now Online
Practically a Posting Shark

Re: computing determinant by upper triangular decomposition

  #3  
Sep 17th, 2008
It seems this function had its Fortran prototype, so indicies started from 1 to N (and right corrected dimension bound N+1): typical ad hoc porting solution.
Better give us a reference to this alg method and source (present data file contents too).
I have some doubts about the algorithm. It looks like some kind of LU decomposition but it's not LU decomposition...
Reply With Quote  
Join Date: Aug 2008
Posts: 36
Reputation: shamila08 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
shamila08 shamila08 is offline Offline
Light Poster

Re: computing determinant by upper triangular decomposition

  #4  
Sep 17th, 2008
thanks. its work.
i got the source from the book title: Computing numerical methods using visual c++. (2008)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC