⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nm11.htm

📁 非常好用的用C编写的矩阵类,可在不同编译器下编译使用.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  causing a problem comment out the line defining <i>TypeDefException</i> in <i>
  include.h</i>.</li>
  <li>Newmat11 does not support the TEMP_DESTROYED_QUICKLY options so won't work 
	with very old versions of Gnu G++</li>
  <li>Old AT&amp;T work-arounds are removed</li>
  <li>The simulated Booleans class is now stored at the end of include.h. In 
  general, I am not testing with compilers that don't support <b>bool</b>.</li>
  <li>QRZ and QRZT no longer throw an exception if they generate a singular 
	triangular matrix</li>
  <li>Converting functions to lower case. Both the old and new names will work. See the list of <a href="#function">
  functions</a> for new and old names</li>
	<li><i>nm_i5.mak</i>, <i>nm_il5.mak</i> replaced by <i>nm_i8.mak</i>, <i>
	nm_il8.mak</i></li>
	<li>extra file <i>nm_misc.cpp</i> to be included in compilation</li>
</ul>
<P><B>Newmat10</B> includes new <A HREF="#scalar2">maxima, minima</A>,
<A HREF="#scalar3">determinant, dot product and Frobenius norm</A> functions, a
faster <A HREF="#fft">FFT</A>, revised <A HREF="#make">make</A> files for GCC
and CC compilers, several corrections, new <A HREF="#dimen">ReSize</A> function, <a href="#constr">IdentityMatrix</a> 
and <a href="#binary">Kronecker Product</a>. Singular values from <a href="#svd">
SVD</a> are sorted. The program files include a new file, <TT>newfft.cpp</TT>, so you
will need to include this in the list of files in your IDE and make files. There 
is also a new test file tmtm.cpp.
<A HREF="#pointer">Pointer arithmetic</A> now mostly meets requirements of
standard. You can use <A HREF="#entering">&lt;&lt;</A> to load data into rows
of a matrix. The <A HREF="#custom">default options</A> in include.h have been
changed. If you are updating from a beta version of newmat09 look through the
next section as there were some late changes to newmat09. </P>
<P>If you are upgrading from <B>newmat08</B> note the following:
</P>
<UL>
<LI>Boolean, TRUE, FALSE are now bool, true, false. See
<A HREF="#custom">customising</A> if your compiler supports the bool class.
</LI>
<LI>ReDimension is now <A HREF="#dimen">ReSize</A>.  
</LI>
<LI>The <A HREF="#except">simulated exception</A> package has
been updated. </LI>
<LI>Operators <TT>==</TT>, <TT>!=</TT>, <TT>+=</TT>,
<TT>-=</TT>, <TT>*=</TT>, <TT>|=</TT>, <TT>&amp;=</TT> are now supported as
<A HREF="#binary">binary</A> matrix operators. </LI>
<LI><TT>A+=f</TT>, <TT>A-=f</TT>, <TT>A*=f</TT>, <TT>A/=f</TT>,
<TT>f+A</TT>, <TT>f-A</TT>, <TT>f*A</TT> are supported for <A HREF="#matscal">A
matrix, f scalar</A>. </LI>
<LI><A HREF="#trigtran">Fast trigonometric transforms</A>.
</LI>
<LI><A HREF="#unary">Reverse</A> function for reversing order of
elements in a vector or matrix. </LI>
<LI><A HREF="#scalar3">IsSingular</A> function. </LI>
<LI>An option is included for defining <A
HREF="#namesp">namespaces</A>. </LI>
<LI>Dummy inequality operators are defined for compatibility
with the STL. </LI>
<LI>The row/column classes in newmat3.cpp have been modified to
improve efficiency and correct an invalid use of pointer arithmetic. Most users
won't be using these classes explicitly; if you are, please contact me for
details of the changes. </LI>
<LI>Matrix LU decomposition rewritten (faster for large arrays).
</LI>
<LI>The sort function rewritten (faster). </LI>
<LI>The documentation files newmata.txt and newmatb.txt have
been amalgamated and both are included in the hypertext version. </LI>
<LI>Some of the <A HREF="#make">make</A> files reorganised
again. </LI>
</UL>
<P>If you are upgrading from <B>newmat07</B> note the following:
</P>
<UL>
<LI>.cxx files are now .cpp files. Some versions of won't accept
.cpp. The <I>make</I> files for Gnu and AT&amp;T link the .cpp files to .cxx
files before compilation and delete the links after compilation.  </LI>
<LI>An <A HREF="#custom">option</A> in include.h allows you to
use compiler supported exceptions, simulated exceptions or disable exceptions.
Edit the file include.h to select one of these three options. Don't simulate
exceptions if you have set your compiler's option to implement exceptions.
</LI>
<LI>New <A HREF="#qr">QR decomposition</A> functions.  
</LI>
<LI>A <A HREF="#nonlin">non-linear least squares</A> class.
</LI>
<LI>No need to explicitly set the AT&amp;T option in include.h.
</LI>
<LI><A HREF="#binary">Concatenation and elementwise
multiplication</A>. </LI>
<LI>A new <A HREF="#unspec">GenericMatrix</A> class.  
</LI>
<LI><A HREF="#scalar3">Sum</A> function. </LI>
<LI>Some of the <A HREF="#make">make</A> files reorganised.
</LI>
</UL>
<P>If you are upgrading from <B>newmat06</B> note the following:
</P>
<UL>
<LI>If you are using &lt;&lt; to load a Real into a submatrix
change this to =. </LI>
</UL>
<P>If you are upgrading from <B>newmat03</B> or <B>newmat04</B>
note the following </P>
<UL>
<LI>.hxx files are now .h files </LI>
<LI>real changed to Real </LI>
<LI>BOOL changed to Boolean </LI>
<LI>CopyToMatrix changed to AsMatrix, etc </LI>
<LI>real(A) changed to A.AsScalar() </LI>
</UL>
<P>The current version is quite a bit longer that newmat04, so
if you are almost out of space with newmat04, don't throw newmat04 away until
you have checked your program will work under this version. </P>
<P>See the <A HREF="#changes">change history</A> for other changes. </P>
<h2><a name="except_1"></a>2.6 Catching exceptions</h2>
<P CLASS="small"><A HREF="#example">next</A> - <A HREF="#example">skip</A> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A></P>
<P>This section applies particularly to people using <i>compiler supported</i>
exceptions rather than my <i>simulated</i> exceptions. </P>
<hr>
<P><b>If newmat detects an error it will throw an exception. It is important that
you catch this exception and print the error message</b>. <b>Otherwise you will get an
unhelpful message like <i>abnormal termination</i>.</b></P>
<hr>
<P>I suggest you set up your
main program like&nbsp; </P>
<pre>#define WANT_STREAM             // or #include &lt;iostream&gt;
#include &quot;newmat.h&quot;             // or #include &quot;newmatap.h&quot;
#include &quot;newmatio.h&quot;           // if you are using my matrix output functions

main()
{
   try
   {
      ... your program here
   }
   // catch exceptions thrown by my programs
   catch(BaseException) { cout &lt;&lt; BaseException::what() &lt;&lt; endl; }
   // catch exceptions thrown by other people's programs
   catch(...) { cout &lt;&lt; &quot;exception caught in main program&quot; &lt;&lt; endl; }
   return 0;
}</pre>
<P>Or see my file <i>nm_ex1.cpp</i> for an easy way of organising this.</P>
<P>If you are using a GUI version rather a console version of the program you 
will need to catch the exception and display the error message in a pop-up 
window.</P>
<P>If you are using my simulated exceptions or have set the disable exceptions
option in <i>include.h</i> then uncaught exceptions automatically print the
error message generated by the exception so you can ignore this section.
Alternatively use <i>Try</i>, <i>Catch</i> and <i>CatchAll</i> in place of <i>try</i>, <i>catch</i>
and <i>catch(...)</i> in the preceding code.</P>
<P>See the <a href="#except">section on exceptions</a> for more information on
the exception structure. </P>
<H2><A NAME="example"></A>2.7 Examples</H2>
<P CLASS="small"><A HREF="#testing">next</A> - <A HREF="#testing">skip</A> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A></P>
<P>I include a number of example files. See the sections on <a href="#make">make</a> 
files and on <a href="#compiler">compilers</a> for information about compiling 
them.</P>
<P><b>Invert matrix:</b> <tt>nm_ex1.cpp</tt>. Load values into a 4x4 matrix; invert it 
and check the result. The output is in <tt>nm_ex1.txt</tt>.</P>
<P><b>Eigenvalues and eigenvectors of Hilbert matrix:</b> <tt>nm_ex2.cpp</tt>. Calculate the 
eigenvalues and eigenvectors of a 7x7 Hilbert matrix. The output is in 
<tt>nm_ex2.txt</tt>.</P>
<P><b>Linear regression example</b>: <TT>example.cpp</TT>. This gives a  linear
regression example using five different algorithms. The correct output is given
in <TT>example.txt</TT>. The program carries out a rough check that no memory
is left allocated on the heap when it terminates. See the section on
<A HREF="#testing">testing</A> for a comment on the reliability of this check
and the use of the DO_FREE_CHECK option. </P>
<P>Other example files are <TT>nl_ex.cpp</TT> and <TT>garch.cpp</TT> for
demonstrating the non-linear fitting routines, <TT>sl_ex</TT> for demonstrating
the solve function and <TT>test_exc</TT> for demonstrating and testing exception 
handling. </P>
<H2><A NAME="testing"></A>2.8 Testing</H2>
<P CLASS="small"><A HREF="#bugs">next</A> - <A HREF="#bugs">skip</A> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A></P>
<P>The library package contains a comprehensive test program in the form of a
series of files with names of the form tmt?.cxx. The files consist of a large
number of matrix formulae all of which evaluate to zero (except the first one
which is used to check that we are detecting non-zero matrices). The printout
should state that it has found just one non-zero matrix. </P>
<P>The test program should be run with <I>Real</I> typedefed to <I>double</I>
rather than <I>float</I> in <A HREF="#custom">include.h</A>. </P>
<P>Make sure the <A HREF="#elements">C subscripts</A> are enabled if you want
to test these. </P>
<P>If you are carrying out some form of bounds checking, for example, with
Borland's <I>CodeGuard</I>, then disable the testing of the <A
HREF="#nric">Numerical Recipes in C</A> interface. Activate the statement
<TT>#define DONT_DO_NRIC</TT> in tmt.h. </P>
<P>Various versions of the make file (extension .mak) are included with the
package. See the section on <A HREF="#make">make files</A>. </P>
<P>The program also allocates and deletes a large block and small block of
memory before it starts the main testing and then at the end of the test. It
then checks that the blocks of memory were allocated in the same place. If not,
then one suspects that there has been a memory leak. i.e. a piece of memory has
been allocated and not deleted.</P>
<P>This is not  foolproof. For example, programs may allocate extra print buffers
while the program is running. I have tried to overcome this by doing a print
before I allocate the first memory block. Programs may allocate memory for
different sized items in different places, or might not allocate items
consecutively. Or they might mix the items with memory blocks from other
programs. Nevertheless, I seem to get consistent answers from <i>some</i> of the
compilers I work with, so I think this is a worthwhile test. The compilers that 
the test seems to work for include the Borland compilers, Microsoft VC++ 6 , 
Watcom, and Gnu 2.96 for Linux.</P>
<P>If the <A HREF="#custom">DO_FREE_CHECK</A> option in include.h is activated,
the program checks that each <TT>new</TT> is balanced with exactly one
<TT>delete</TT>. This provides a more definitive test of no memory leaks. There
are additional statements in myexcept.cpp which can be activated to print out
details of the memory being allocated and released. </P>
<P>I have included a facility for checking that each piece of code in the
library is really exercised by the test routines. Each block of code in the
main part of the library contains a word <TT>REPORT</TT>. <TT>newmat.h</TT> has
a line defining <TT>REPORT</TT> that can be activated (deactivate the dummy
version). This gives a printout of the number of times each of the
<TT>REPORT</TT> statements in the <TT>.cpp</TT> files is accessed. Use a grep
with line numbers to locate the lines on which <TT>REPORT</TT> occurs and
compare these with the lines that the printout shows were actually accessed.
One can then see which lines of code were not accessed. </P>
<H2><A NAME="bugs"></A>2.9 Bugs</H2>
<P CLASS="small"><a href="#problemareas">next</a> - <a href="#problemareas">skip</a> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A> </P>
<UL>
<LI>Small memory leaks may occur when an exception is thrown and caught. </LI>
<LI>My exception scheme may not be not properly linked in with the standard
library exceptions. In particular, my scheme may fail to catch out-of-memory
exceptions.</LI>
</UL>
<h2><a name="problemareas"></a>2.10 Problem areas</h2>
<P CLASS="small"><A HREF="#files">next</A> - <A HREF="#files">skip</A> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A> </P>
<p>This section lists parts of <i>Newmat</i> which users (including me) have found 
difficult or unnatural. Also see the <a href="nmfaq.htm">newmat FAQ list</a> on 
my <a href="#where">website</a>.</p>
<p><b>Invert, element access, matrix multiply etc causes the program to crash</b></p>
<blockquote>
<p CLASS="small">Newmat throws an exception when it detects an error. This can cause a program 
crash unless the exception is caught with a <i>catch</i> statement. See
<a href="#except_1">catching exceptions</a>.</p>
</blockquote>
<p><b><tt>1x1</tt> matrix not automatically converted to a Real</b></p>
<blockquote>
<p CLASS="small">Use the <a href="#ch_type">as_scalar()</a> member function or the
<a href="#scalar3">dotproduct()</a> function to take the dot 
product of two vectors.</p>
</blockquote>
<p><b>Constructors do not initialise elements</b></p>
<blockquote>
<p CLASS="small">For example, <tt>Matrix A(4,5);</tt> does not initialise the elements of <tt>A</tt>. Use the 
statement <tt>A=0.0</tt> to set the values to zero.</p>
</blockquote>
<p><b><i>resize</i> does not initialise elements</b></p>
<blockquote>
<p CLASS="small">For example, <tt>A.resize(5,6);</tt> does not set the elements of <tt>A</tt>. 
If you want to keep values use <tt>resize_keep</tt>. See <a href="#dimen">resize</a>.</p>
</blockquote>
<p><b>Setting Matrix to a scalar sets all the values</b></p>
<blockquote>
<p CLASS="small"><tt>A(1,3) = 0.0;</tt> sets one element of a Matrix to zero. <tt>A = 0.0;</tt> sets all the 
elements to zero. This is very convenient but also a source of error that is 
 
hard to see if you wanted <tt>A(1,3) = 0.0;</tt> but left out the element details.</p>
</blockquote>
<p><b>Symmetry not detected automatically</b></p>
<blockquote>
<p CLASS="small">For example, <tt>SymmetricMatrix SM = A.t() * A;</tt> will fail. Use <tt>SymmetricMatrix 
SM; SM &lt;&lt; A.t() * A;</tt></p>
</blockquote>
<p><b><tt>&lt;&lt;</tt> does not work with constructors</b></p>
<blockquote>
<p CLASS="small">For example, <tt>SymmetricMatrix SM &lt;&lt; A.t() * A;</tt> does not work. </p>
</blockquote>
<p><b>Multiple multiplication may be inefficient</b></p>
<blockquote>
<p CLASS="small">For example, <tt>A * B * X</tt> where <tt>A</tt> and <tt>B</tt> are matrices and <tt>X</tt> is a column vector is 
likely to be much slower than <tt>A * (B * X)</tt>.</p>
</blockquote>
<p>&nbsp;</p>
<H2><A NAME="files"></A>2.11 List of files</H2>
<P CLASS="small"><a href="#refer">next</a> - <a href="#refer">skip</a> -
<A HREF="#starting">up</A> - <A HREF="#top">start</A></P>
<TABLE WIDTH="100%" BORDER="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0">
<TR>
<TD width="25%"><B>Documentation</B></TD>
<TD width="25%">readme.txt</TD>
<TD width="50%">readme file</TD>
</TR>
<TR>
<TD width="25%">&nbsp;</TD>
<TD width="25%">nm11.htm</TD>
<TD width="50%">documentation file</TD>
</TR>
<TR>
<TD width="25%">&nbsp;</TD>
<TD width="25%">add_time.pgn</TD>
<TD width="50%">image used by nm11.htm</TD>
</TR>
<TR>
<TD width="25%">&nbsp;</TD>
<TD width="25%">rbd.css</TD>
<TD width="50%">style sheet for nm11.htm</TD>
</TR>
<TR>
<TD width="25%">&nbsp;</TD>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -