944,111 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4760
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 27th, 2007
0

Problem with Gauss Matrix Code

Expand Post »
I got this code from a book I bought. I wanted to see if it words but it gives me errors.

Here is the source code.

C++ Syntax (Toggle Plain Text)
  1. #include<math.h>
  2. #define NRANSI
  3. #include"nrutil.h"
  4. #define SWAP(a,b)
  5. {
  6. temp=(a);(a)=(b);(b)=temp;
  7. }
  8.  
  9. void gaussj(float **a, int n, float **b, int m)
  10.  
  11. {
  12.  
  13. int *indxc,*indxr,*ipiv;
  14. int i,icol,irow,j,k,l,ll;
  15. float big,dum,pivinv,temp;
  16. indxc=ivector(1,n);
  17. indxr=ivector(1,n);
  18. ipiv=ivector(1,n);
  19. for (j=1;j<=n;j++) ipiv[j]=0;
  20. for (i=1;i<=n;i++)
  21. {
  22.  
  23. big=0.0;
  24. for (j=1;j<=n;j++)
  25. if (ipiv[j] != 1)
  26. for (k=1;k<=n;k++)
  27. {
  28.  
  29. if (ipiv[k] == 0)
  30. {
  31.  
  32. if (fabs(a[j][k]) >= big)
  33. {
  34.  
  35. big=fabs(a[j][k]);
  36. irow=j;
  37. icol=k;
  38.  
  39. }
  40.  
  41.  
  42. }
  43. else if (ipiv[k] > 1) nrerror("gaussj: Singular Matrix-1");
  44.  
  45. }
  46.  
  47. ++(ipiv[icol]);
  48. if (irow != icol)
  49. {
  50.  
  51. for (l=1;l<=n;l++) SWAP(a[irow][l],a[icol][l])
  52. for (l=1;l<=m;l++) SWAP(b[irow][l],b[icol][l])
  53.  
  54. }
  55.  
  56. indxr[i]=irow;
  57. indxc[i]=icol;
  58. if (a[icol][icol] == 0.0) nrerror("gaussj: Singular Matrix-2");
  59. pivinv=1.0/a[icol][icol];
  60. a[icol][icol]=1.0;
  61. for (l=1;l<=n;l++) a[icol][l] *= pivinv;
  62. for (l=1;l<=m;l++) b[icol][l] *= pivinv;
  63. for (ll=1;ll<=n;ll++)
  64. if (ll != icol)
  65. {
  66.  
  67. dum=a[ll][icol];
  68. a[ll][icol]=0.0;
  69. for (l=1;l<=n;l++) a[ll][l] -= a[icol][l]*dum;
  70. for (l=1;l<=m;l++) b[ll][l] -= b[icol][l]*dum;
  71.  
  72. }
  73.  
  74.  
  75. }
  76.  
  77. for (l=n;l>=1;l--)
  78. {
  79.  
  80. if (indxr[l] != indxc[l])
  81. for (k=1;k<=n;k++)
  82. SWAP(a[k][indxr[l]],a[k][indxc[l]]);
  83.  
  84. }
  85.  
  86. free_ivector(ipiv,1,n);
  87. free_ivector(indxr,1,n);
  88. free_ivector(indxc,1,n);
  89.  
  90. }
  91.  
  92. #undef SWAP
  93. #undef NRANSI



and the header file:



C++ Syntax (Toggle Plain Text)
  1. #ifndef _NR_UTILS_H_
  2. #define _NR_UTILS_H_
  3. staticfloat sqrarg;
  4. #define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
  5. staticdouble dsqrarg;
  6. #define DSQR(a) ((dsqrarg=(a)) == 0.0 ? 0.0 : dsqrarg*dsqrarg)
  7. staticdouble dmaxarg1,dmaxarg2;
  8. #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1) > (dmaxarg2) ?\
  9. (dmaxarg1) : (dmaxarg2))
  10. staticdouble dminarg1,dminarg2;
  11. #define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1) < (dminarg2) ?\
  12. (dminarg1) : (dminarg2))
  13. staticfloat maxarg1,maxarg2;
  14. #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\
  15. (maxarg1) : (maxarg2))
  16. staticfloat minarg1,minarg2;
  17. #define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1) < (minarg2) ?\
  18. (minarg1) : (minarg2))
  19. staticlong lmaxarg1,lmaxarg2;
  20. #define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1) > (lmaxarg2) ?\
  21. (lmaxarg1) : (lmaxarg2))
  22. staticlong lminarg1,lminarg2;
  23. #define LMIN(a,b) (lminarg1=(a),lminarg2=(b),(lminarg1) < (lminarg2) ?\
  24. (lminarg1) : (lminarg2))
  25. staticint imaxarg1,imaxarg2;
  26. #define IMAX(a,b) (imaxarg1=(a),imaxarg2=(b),(imaxarg1) > (imaxarg2) ?\
  27. (imaxarg1) : (imaxarg2))
  28. staticint iminarg1,iminarg2;
  29. #define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1) < (iminarg2) ?\
  30. (iminarg1) : (iminarg2))
  31. #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
  32. #ifdefined(__STDC__) || defined(ANSI) || defined(NRANSI) /* ANSI */
  33. void nrerror(char error_text[]);
  34. float *vector(long nl, long nh);
  35. int *ivector(long nl, long nh);
  36. unsignedchar *cvector(long nl, long nh);
  37. unsignedlong *lvector(long nl, long nh);
  38. double *dvector(long nl, long nh);
  39. float **matrix(long nrl, long nrh, long ncl, long nch);
  40. double **dmatrix(long nrl, long nrh, long ncl, long nch);
  41. int **imatrix(long nrl, long nrh, long ncl, long nch);
  42. float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
  43. long newrl, long newcl);
  44. float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch);
  45. float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh);
  46. void free_vector(float *v, long nl, long nh);
  47. void free_ivector(int *v, long nl, long nh);
  48. void free_cvector(unsignedchar *v, long nl, long nh);
  49. void free_lvector(unsignedlong *v, long nl, long nh);
  50. void free_dvector(double *v, long nl, long nh);
  51. void free_matrix(float **m, long nrl, long nrh, long ncl, long nch);
  52. void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
  53. void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch);
  54. void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch);
  55. void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch);
  56. void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
  57. long ndl, long ndh);
  58. #else/* ANSI */
  59. /* traditional - K&R */
  60. void nrerror();
  61. float *vector();
  62. float **matrix();
  63. float **submatrix();
  64. float **convert_matrix();
  65. float ***f3tensor();
  66. double *dvector();
  67. double **dmatrix();
  68. int *ivector();
  69. int **imatrix();
  70. unsignedchar *cvector();
  71. unsignedlong *lvector();
  72. void free_vector();
  73. void free_dvector();
  74. void free_ivector();
  75. void free_cvector();
  76. void free_lvector();
  77. void free_matrix();
  78. void free_submatrix();
  79. void free_convert_matrix();
  80. void free_dmatrix();
  81. void free_imatrix();
  82. void free_f3tensor();
  83. #endif/* ANSI */
  84. #endif/* _NR_UTILS_H_ */

The errors I keep on getting is:

1>Linking...
1>gaussj.obj : error LNK2019: unresolved external symbol _free_ivector referenced in function _gaussj
1>gaussj.obj : error LNK2019: unresolved external symbol _nrerror referenced in function _gaussj
1>gaussj.obj : error LNK2019: unresolved external symbol _ivector referenced in function _gaussj
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents\Visual Studio 2005\Projects\Linear Equation\Debug\Linear Equation.exe : fatal error LNK1120: 4 unresolved externals
Last edited by Ancient Dragon; Jul 27th, 2007 at 7:32 pm. Reason: remove color codes, correct code tags, and beautify code (whew!)
Reputation Points: 21
Solved Threads: 1
Junior Poster in Training
tformed is offline Offline
58 posts
since May 2007
Jul 27th, 2007
0

Re: Problem with Gauss Matrix Code

Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 27th, 2007
0

Re: Problem with Gauss Matrix Code

>> for (j=1;j&lt;=n;j++)

I think you misquoted the code (lines 19 and 20) because that is just so much nonsense. Proofread the code you have to make sure you did not make typing errors. If its really like that in the book then go to the publishers web site to see if they have a list of book corrections or electronic copy of the code, which sometimes has corrected code.
Last edited by Ancient Dragon; Jul 27th, 2007 at 7:39 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 27th, 2007
0

Re: Problem with Gauss Matrix Code

actually that is the actual code, it came with cd in which i opened and copied pasted. thanks for editing my post.
Reputation Points: 21
Solved Threads: 1
Junior Poster in Training
tformed is offline Offline
58 posts
since May 2007
Jul 27th, 2007
1

Re: Problem with Gauss Matrix Code

Click to Expand / Collapse  Quote originally posted by tformed ...
actually that is the actual code, it came with cd in which i opened and copied pasted. thanks for editing my post.
Looks to me like Daniweb parsed the greater and less than into html entities or you accidentally copied and pasted from a html document on the CD.
Last edited by ShawnCplus; Jul 27th, 2007 at 9:05 pm.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Jul 28th, 2007
0

Re: Problem with Gauss Matrix Code

>> for (j=1;j&lt;=n;j++)

I think you misquoted the code (lines 19 and 20) because that is just so much nonsense. Proofread the code you have to make sure you did not make typing errors. If its really like that in the book then go to the publishers web site to see if they have a list of book corrections or electronic copy of the code, which sometimes has corrected code.
Um, it is fairly obvious that your online parser has a flaw and it not converting &lt (html syntax into plain text ">"). You shouldn't blame the OP for your mistakes Ancient Dragon. And why is my infraction that you mistakenly gave me still there, did I not ask you to get rid of it

I did say this before!
Last edited by iamthwee; Jul 28th, 2007 at 4:41 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 28th, 2007
0

Re: Problem with Gauss Matrix Code

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Um, it is fairly obvious that your online parser has a flaw and it not converting &lt (html syntax into plain text ">"). You shouldn't blame the OP for your mistakes Ancient Dragon.
Its not an error -- to my knowledge (and I could be wrong) the only markup codes recognized are code tags. People are supposed to post ONLY code -- this is not a place to test html code. If someone wants to post C or C++ code that contains html markup code then its his respoinsibility to remove it.

Click to Expand / Collapse  Quote originally posted by iamthwee ...
And why is my infraction that you mistakenly gave me still there, did I not ask you to get rid of it
That was no mistake -- it was intentional.

Click to Expand / Collapse  Quote originally posted by iamthwee ...
I did say this before!
Oh. I didn't realize Dani made you Super Mod.
Last edited by Ancient Dragon; Jul 28th, 2007 at 8:22 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 28th, 2007
0

Re: Problem with Gauss Matrix Code

Does anyone bother to actually read my posts these days, cos I find I am just repeating myself.

Ancient Dragon, your online code beautifier is flawed!


It changes all the "< >" symbols to &lt and &gt respectively! So telling the op of for experimenting with html is silly, It is YOUR fault.
.

>That was no mistake -- it was intential.
I already told you, it was a mistake, I forgot to add the code tags and then was cut off the internet so I was unable to edit my post in time. Why should I be punished for a mistake?



You promised me you would tell the supermods, but you never did
Last edited by Ancient Dragon; Jul 28th, 2007 at 8:53 am. Reason: post edited in error.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 28th, 2007
0

Re: Problem with Gauss Matrix Code

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Does anyone bother to actually read my posts these days, cos I find I am just repeating myself.

Ancient Dragon, your online code beautifier is flawed!


It changes all the "< >" symbols to &lt and &gt respectively! So telling the op of for experimenting with html is silly, It is YOUR fault.
.
Ah, my mistake. I though you meant the other way around. If there is a problem you should report it in the Community Feedback board. But I have not seen that in any other posts.
C++ Syntax (Toggle Plain Text)
  1. this is a test of html markup parsor for < and > symbol also together like this <>

As you can see it works great for me. Sometimes the parser turns things into smiley faces, but there is a check box to turn off smileys in text posts.

Click to Expand / Collapse  Quote originally posted by iamthwee ...
>That was no mistake -- it was intential.
I already told you, it was a mistake, I forgot to add the code tags and then was cut off the internet so I was unable to edit my post in time. Why should I be punished for a mistake?
Another case of miscommunication.

Click to Expand / Collapse  Quote originally posted by iamthwee ...
>You promised me you would tell the supermods, but you never did
Send me the PM or link where I made that statement because I don't remember it. This is something I think would be better discussed via PM instead of here.
Last edited by Ancient Dragon; Jul 28th, 2007 at 9:04 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 28th, 2007
0

Re: Problem with Gauss Matrix Code

>If there is a problem you should report it in the Community Feedback board. But I have not seen that in any other posts.

What has this got to do with the daniweb community feedback? Your online code beautifier is the thing that's broken. (Why am I repeating myself again?)

>As you can see it works great for me.

That's great, we all know the daniweb code tagging works fine. But what has this got to do with the online beautifier you are using which is broken?

>This is something I think would be better discussed via PM instead of here.

What is there to discuss. For the time being I will pretend it didn't happen. Please just don't make these mistakes in the future. Be careful with that infraction button you use. Thanx.

Just in case you didn't get it. I'm going to say it again.

YOUR ONLINE BEAUTIFIER IS BROKE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Last edited by iamthwee; Jul 28th, 2007 at 9:35 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need reference to Random Accessing of Text files
Next Thread in C++ Forum Timeline: C++ Help Anyone





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC