•
•
•
•
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
![]() |
•
•
Join Date: Aug 2008
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 0
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?
cplusplus Syntax (Toggle Plain Text)
#include <fstream> #include <iostream> #define N 5 using namespace std; void main() { int i,j,k; double A[N+1][N+1]; cout.setf(ios::fixed); cout.precision(5); cout << "Input matrix A: " << endl; ifstream InFile("Code2D.h"); for (i=1;i<=N;i++) { for (j=1;j<=N;j++) { InFile >> A[i][j]; cout << A[i][j] << " "; } cout << endl; } InFile.close(); // row operations double Product,m; for (k=1;k<=N-1;k++) for (i=k+1;i<=N;i++) { m=A[i][k]/A[k][k]; for (j=1;j<=N;j++) A[i][j]-=m*A[k][j]; } cout << endl << "matrix U:" << endl; for (i=1;i<=N;i++) { for (j=1;j<=N;j++) cout << A[i][j] << " "; cout << endl; } Product=1; for (i=1;i<=N;i++) Product *= A[i][i]; // determinant // display results cout << endl << "det(A)=" << Product << endl; }
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,539
Reputation:
Rep Power: 40
Solved Threads: 972
>>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:
>>my algorithm have no problem with N <= 4.
Only because you were lucky, not because your code is right.
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.
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...
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...
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: Create "Help" in application
- Next Thread: whats a cout?



Linear Mode