📄 solve.html
字号:
<HTML><HEAD><TITLE>Newmat09 - multiple matrix solve</TITLE></HEAD> <BODY><H2>Multiple matrix solve</H2><A HREF="memory.html"> next</A> - <A HREF="memory.html"> skip</A> - <A HREF="refer.html"> up</A> - <A HREF="index.html"> start</A><P>To solve the matrix equation <TT>Ay = b</TT> where <TT>A</TT> is asquare matrix of equation coefficients, <TT>y</TT> is a columnvector of values to be solved for, and <TT>b</TT> is a column vector,use the code<PRE> int n = something Matrix A(n,n); ColumnVector b(n); ... put values in A and b ColumnVector y = A.i() * b; // solves matrix equation</PRE>The following notes are for the case where you want to solve more thanone matrix equation with different values of <TT>b</TT> but the same<TT>A</TT>. Or whereyou want to solve a matrix equation and also find the determinant of<TT>A</TT>.In these cases you probably want to avoid repeating the LU decomposition of<TT>A</TT>for each solve or determinant calculation.<P>If <TT>A</TT> is a square or symmetric matrix use<PRE> CroutMatrix X = A; // carries out LU decomposition Matrix AP = X.i()*P; Matrix AQ = X.i()*Q; LogAndSign ld = X.LogDeterminant();</PRE>rather than<PRE> Matrix AP = A.i()*P; Matrix AQ = A.i()*Q; LogAndSign ld = A.LogDeterminant();</PRE>since each operation will repeat the LU decomposition.<P>If <TT>A</TT> is a BandMatrix or a SymmetricBandMatrixbegin with<PRE> BandLUMatrix X = A; // carries out LU decomposition</PRE>A CroutMatrix or a BandLUMatrix can't be manipulated orcopied. Usereferences as an alternative to copying.<P>Alternatively use<PRE> LinearEquationSolver X = A;</PRE>This will choose the most appropriate decomposition of <TT>A</TT>. That is, theband form if <TT>A</TT> is banded; the Crout decomposition if <TT>A</TT> issquare or symmetric and no decomposition if <TT>A</TT> is triangular ordiagonal. If you want to use the LinearEquationSolver <TT>#includenewmatap.h</TT>.<P><A HREF="memory.html"> next</A> - <A HREF="memory.html"> skip</A> - <A HREF="refer.html"> up</A> - <A HREF="index.html"> start</A><P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -