From: lrmsx AT my-deja DOT com Newsgroups: comp.os.msdos.djgpp Subject: Re: multidimensional arrays and math inaccuracy Date: Sun, 30 May 1999 20:09:51 GMT Organization: Deja.com - Share what you know. Learn what you don't. Lines: 51 Message-ID: <7is5uf$7u5$1@nnrp1.deja.com> References: <374edbb4 DOT 18530235 AT news DOT ndh DOT net> NNTP-Posting-Host: 200.248.54.9 X-Article-Creation-Date: Sun May 30 20:01:58 1999 GMT X-Http-User-Agent: Mozilla/4.6 [en] (Win95; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <374edbb4 DOT 18530235 AT news DOT ndh DOT net>, fnatter AT gmx DOT net wrote: > is this 100% correct when I then access the elements via elems[x][y]? I see no problem in the memory acessing or allocation. (This is really not DJGPP realted it's numerical math but anyway...) > the reason I'm asking is because I use gaussian elimination to > transform the matrix to "diagonal" form (for solving a linear system > of equations), and when I do so, on a system where there is a unique > solution (in this code it's .2, .4, .2), there will be a math > inaccuracy: where an entry should have been reduced to 0.0, it becomes > something*10^(-15), resulting in the algorithm continuing and giving a > wrong result! After making the matrix diagonal you should only use the elements at the diagonal itself to calculate the result. Supposing you are really using (or want to) a full maxtrix multiply to get the solution that's what you should do: ( that's what I learned in the numerical methods) in the Gauss Elimination algorithm where some element is supposed to be eleminated (zeroed) simply put a zero (0.0) there, don't really calculate it's value as every single machine in the world will have limited precision and result will not be accurate for all digitis. Simply zeroing the elements will also make the calculation faster, as the number of calculated columns will decrease after each line is calculated. Remember also that to get 7 digiti precision after doing some operations with floating point numbers you will need more than 7 digitis (in the floating point operations). Double precision has about 15 digitis (53 bits in the mantissa if a remember correctly). So it's expected to have some 10^-15 (or smaller) result where it really should be zero. LRMS Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.