RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 2159 | Replies: 12 | Thread Tools  Display Modes
Reply
Join Date: May 2007
Location: USA
Posts: 53
Reputation: tformed is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
tformed's Avatar
tformed tformed is offline Offline
Junior Poster in Training

Question Problem with Gauss Matrix Code

  #1  
Jul 27th, 2007
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.

  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:



  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!)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem with Gauss Matrix Code

  #2  
Jul 27th, 2007
*Voted best profile in the world*
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,865
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: 1013
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Problem with Gauss Matrix Code

  #3  
Jul 27th, 2007
>> 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.
<<Hire Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 53
Reputation: tformed is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
tformed's Avatar
tformed tformed is offline Offline
Junior Poster in Training

Re: Problem with Gauss Matrix Code

  #4  
Jul 27th, 2007
actually that is the actual code, it came with cd in which i opened and copied pasted. thanks for editing my post.
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 525
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 6
Solved Threads: 79
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Problem with Gauss Matrix Code

  #5  
Jul 27th, 2007
Originally Posted by tformed View Post
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h-->++ r z+*
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem with Gauss Matrix Code

  #6  
Jul 28th, 2007
Originally Posted by Ancient Dragon View Post
>> 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.
*Voted best profile in the world*
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,865
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: 1013
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Problem with Gauss Matrix Code

  #7  
Jul 28th, 2007
Originally Posted by iamthwee View Post
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.

Originally Posted by iamthwee View Post
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.

Originally Posted by iamthwee View Post
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.
<<Hire Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem with Gauss Matrix Code

  #8  
Jul 28th, 2007
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.
*Voted best profile in the world*
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,865
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: 1013
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Problem with Gauss Matrix Code

  #9  
Jul 28th, 2007
Originally Posted by iamthwee View Post
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.
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.

Originally Posted by iamthwee View Post
>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.

Originally Posted by iamthwee View Post
>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.
<<Hire Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Aug 2005
Posts: 4,844
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 325
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem with Gauss Matrix Code

  #10  
Jul 28th, 2007
>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.
*Voted best profile in the world*
Reply With Quote  
Reply

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



Other Threads in the C++ Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:46 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC