delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/28/14:48:14

From: f DOT natter AT ndh DOT net (Felix Natter)
Newsgroups: comp.os.msdos.djgpp
Subject: multidimensional arrays and math inaccuracy
Date: Fri, 28 May 1999 18:22:17 GMT
Organization: Customer of NDH Netzwerkdienste Hoeger GmbH
Lines: 31
Message-ID: <374edbb4.18530235@news.ndh.net>
NNTP-Posting-Host: port209.bonn.ndh.net
X-Trace: public.ndh.net 927915641 22626 195.94.93.209 (28 May 1999 18:20:41 GMT)
X-Complaints-To: abuse AT ndh DOT net
NNTP-Posting-Date: 28 May 1999 18:20:41 GMT
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,
I've written a Matrix class, which uses a double** to hold the nxm
elements. The constructor looks like this:

elems = (double**)malloc(sizeof(double*) * rows);
for (i = 0; i < rows; i++)
      elems[i] = (double*)malloc(sizeof(double) * columns);
is this 100% correct when I then access the elements via elems[x][y]?
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!
I really don't have a clue why this could be!
I didn't want to send attachments to a newsgroup, so I've uploaded the
code on my web site:
http://www.ndh.net/home/natter/MATRIX.CPP
http://www.ndh.net/home/natter/MATRIX.HPP

Matrix.cpp has a main() function so you can just compile it - probably
on any platform. It will output several steps on the way to
transforming the matrix to form which I think americans call "row
echelon form (REF)"

Thanks,
Felix Natter



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019