📄 nm10.htm
字号:
<P>If you are using 2.6 or earlier remember to edit include.h to activate my
Boolean class. </P>
<P>For versions earlier than 2.6.0 you must enable the options
TEMPS_DESTROYED_QUICKLY and TEMPS_DESTROYED_QUICKLY_R. You can't use
expressions like <TT>Matrix(X*Y)</TT> in the middle of an expression and
<TT>(Matrix)(X*Y)</TT> is unreliable. If you write a function returning a
matrix, you MUST use the <A HREF="#memory">ReturnMatrix</A> method described in
this documentation. This is because g++ destroys temporaries occurring in an
expression too soon for the two stage way of evaluating expressions that newmat
uses. You will have problems with versions of Gnu earlier than 2.3.1. </P>
<P><B>Linux:</B> It works fine on my copy of G++ (2.96) that came with RedHat
7.3. Use
compiler supported exceptions. You can use <I>namespace</I> but not the
<I>standard</I> option.</P>
<P>In 2.6.?, <TT>fabs(*X++)</TT> causes a problem. You may need to write you
own non-inlined version. </P>
<H2><A NAME="hpux"></A>2.4.4 HP-UX</H2>
<P CLASS="small"><A HREF="#intel">next</A> - <A HREF="#intel">skip</A> -
<A HREF="#compiler">up</A> - <A HREF="#top">start</A></P>
<P>HP 9000 series HP-UX. I no longer have access to this compiler. Newmat09
worked without problems with the simulated exceptions; haven't tried the
built-in exceptions. </P>
<P>With recent versions of the compiler you may get warning messages like
<TT>Unsafe cast between pointers/references to incomplete classes</TT>. At
present, I think these can be ignored. </P>
<P>Here are comments I made in 1997. </P>
<P>I have tried the library on two versions of HP-UX. (I don't know the version
numbers, the older is a clone of AT&T 3, the newer is HP's version with
exceptions). Both worked after the modifications described in this section.
</P>
<P>With the older version of the compiler I needed to edit the math.h library
file to remove a duplicate definition of abs. </P>
<P>With the newer version you can set the +eh option to enable exceptions and
activate the UseExceptions option in include.h. If you are using my make file,
you will need to replace CC with CC +eh where ever CC occurs. I recommend that
you do not do this and either disable exceptions or use my simulated
exceptions. I get core dumps when I use the built-in exceptions and suspect
they are not sufficiently debugged as yet. </P>
<P>If you are using my simulated exceptions you may get a mass of error
messages from the linker about __EH_JMPBUF_TEMP. In this case get file setjmp.h
(in directory /usr/include/CC ?) and put extern in front of the line </P>
<PRE> jmp_buf * __EH_JMPBUF_TEMP;
</PRE>
<P>The file setjmp.h is accessed in my file myexcept.h. You may want to change
the #include statement to access your edited copy of setjmp.h. </P>
<h2><a name="intel"></a>2.4.5 Intel</h2>
<P CLASS="small"><A HREF="#microso">next</A> - <A HREF="#microso">skip</A> -
<A HREF="#compiler">up</A> - <A HREF="#top">start</A></P>
<P>Newmat works correctly with the Intel 5 C++ compiler for Windows and the free
versions 5 and 6 for Linux. Standard is automatically switched on for the Linux
versions.</P>
<H2><A NAME="microso"></A>2.4.6 Microsoft</H2>
<P CLASS="small"><A HREF="#sun">next</A> - <A HREF="#sun">skip</A> -
<A HREF="#compiler">up</A> - <A HREF="#top">start</A></P>
<H3>Newer versions</H3>
<P>See my <A HREF="#where">web site</A> for instructions how to work
Microsoft's IDE.</P>
<P><b>Microsoft Visual C++ 7:</b> This works OK. Note that all my tests have
been in console mode. You can turn on my standard option but I am still a bit
wary about the namespace option.</P>
<P><B>Microsoft Visual C++ 6:</B> <b>Get the latest service pack</b>. I have tried this
in console mode and it seems to work satisfactorily. Use the compiler supported exceptions. You
<i>may</i> be able to
use the namespace and standard options but I suggest not using namespace. If you want to work under MFC
you may need to <TT>#include "stdafx.h"</TT> at the beginning of each .cpp file. </P>
<P><B>Microsoft Visual C++ 5</B>: I have tried this in console mode and it
seems to work satisfactorily. There may be a problem with <A
HREF="#namesp">namespace</A> (fixed by Service Pack 3?). <B>Turn optimisation
off</B>. Use the compiler supported exceptions. If
you want to work under MFC
you may need to <TT>#include "stdafx.h"</TT> at the
beginning of each .cpp file.</P>
<H3>Older versions</H3>
<P>Microsoft Visual C++ 2.0: This used to work OK. I haven't tried it with
recent versions of newmat.</P>
<P>You must <TT>#define TEMPS_DESTROYED_QUICKLY</TT> owing to a bug in version
7 (at least) of MSC. There are some notes in the file <TT>include.h</TT> on
changes to run under version 7. I haven't tried newmat10 on version 7. </P>
<P>Microsoft Visual C++ 1.51. Disable exceptions, comment out the line in
include.h <TT>#define TEMPS_DESTROYED_QUICKLY_R</TT>. In <TT>tmt.cpp</TT>,
comment out the <TT>Try</TT> and <TT>CatchAll</TT> lines at the beginning of
<TT>main()</TT> and the line <TT>trymati()</TT>. You can use the makefile
<TT>ms.mak</TT>. You will probably need to break the <A HREF="#testing">tmt</A>
test files into two parts to get the program to link. </P>
<P>If you can, upgrade to windows 95, 98 or window NT and use the 32 bit
console model. </P>
<P>If you are using the 16 bit large model, don't forget to keep all matrices
less than 64K bytes in length (90x90 for a rectangular matrix if you are using
<TT>double</TT> as your element type). Otherwise your program will crash
without warning or explanation. You may need to break the <A
HREF="#testing">tmt</A> set of test files into two parts to get the program to
fit into your computer. </P>
<P>Microsoft Visual C++ 4: I haven't tried this - a correspondent reports: I
use Microsoft Visual C++ Version 4. there is only one minor problem. In all
files you must include <TT>#include "stdafx.h"</TT> (presumably if
you are using MFC). This file contains essential information for VC++. Leave it
out and you get <I>Unexpected end of file</I>. </P>
<H2><A NAME="sun"></A>2.4.7 Sun</H2>
<P CLASS="small"><A HREF="#watcom">next</A> - <A HREF="#watcom">skip</A> -
<A HREF="#compiler">up</A> - <A HREF="#top">start</A></P>
<P><B>Sun C++ (version 4.2, version 6):</B> These seem to work fine with
compiler supported exceptions. <B>Sun C++ (version
5):</B> There seems to be a problem with exceptions. If you use my simulated
exceptions the non-linear optimisation programs hang. If you use the compiler
supported exceptions my tmt and test_exc programs crash. You should
<I>disable</I> exceptions.</P>
<H2><A NAME="watcom"></A>2.4.8 Watcom</H2>
<P CLASS="small"><A HREF="#update">next</A> - <A HREF="#update">skip</A> -
<A HREF="#compiler">up</A> - <A HREF="#top">start</A></P>
<P><B>Watcom C++ (version 10a):</B> this works fine. You may need to increase
the stack size to 16384. With this elderly compiler, use my simulated exceptions
and simulated bool class (comment out the line <tt>#define bool_LIB 0</tt> in <i>
include.h</i>). I haven't tried more recent versions of Watcom. (I can <i>
compile</i> with the downloadable version of Watcom 11c but haven't found out
how to <i>link</i> the files).</P>
<H2><A NAME="update"></A>2.5 Updating from previous
versions</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><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"><<</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>&=</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&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&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 << 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>This section applies particularly to people using <i>compiler supported</i>
exceptions rather than my <i>simulated</i> exceptions. </P>
<P>If newmat detects an error it will throw an exception. It is important that
you catch this exception and print the error message. Otherwise you will get an
unhelpful message like <i>abnormal termination</i>. I suggest you set up your
main program like </P>
<pre>#define WANT_STREAM // or #include <iostream>
#include "include.h" // or #include "newmat.h"
#include "myexcept.h"
main()
{
try
{
... your program here
}
// catch exceptions thrown by my programs
catch(Exception) { cout << Exception::what() << endl; }
// catch exceptions thrown by other people's programs
catch(...) { cout << "exception caught in main program" << endl; }
return 0;
}</pre>
<P>If you are using a GUI version rather a console version of the program you
will need to replace the <i>cout </i>statements by windows pop-up messages.</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. It is probably a good idea to do
this if you are using a GUI version of the program as opposed to a console
version as the <i>cout </i>statement used in newmat's <i>Terminate</i> function
may be ignored in a GUI version.</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 Example</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>An example is given in <TT>example.cpp</TT>. This gives a simple 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
(generally it doesn't work with the newer compilers) and the use of the
DO_FREE_CHECK option. </P>
<P>I include a variety of make files. To compile the example use a command like
</P>
<pre> gmake -f nm_gnu.mak example (Gnu G++)
gmake -f nm_cc.mak example (AT&T, HPUX, Sun)
make -f nm_b55.mak example.exe (Borland C++ 5.5)</pre>
<p>You can generate make make files for a number of other compilers with my
<a href="genmake.htm">genmake</a> utility.</p>
<P>To compile all the example and test files use a command like </P>
<PRE> gmake -f nm_gnu.mak (Gnu G++)
</PRE>
<P> The example uses io manipulators. It will not work with a
compiler that does not support the standard io manipulators. </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 the exceptions. </P>
<H2><A NAME="testing"></A>2.8 Testing</H2>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -