📄 copy.html
字号:
<HTML><HEAD><TITLE>Newmat09 - assignment and copying</TITLE></HEAD><BODY><H2>Assignment and copying</H2><A HREF="entering.html"> next</A> - <A HREF="entering.html"> skip</A> - <A HREF="refer.html"> up</A> - <A HREF="index.html"> start</A><P>The operator <TT>=</TT> is used for copying matrices, converting matrices, orevaluating expressions. For example<PRE> A = B; A = L; A = L * U;</PRE>Only conversions that don't lose information are supported. Thedimensions of the matrix on the left hand side are adjusted to those ofthe matrix or expression on the right hand side. Elements on the righthand side which are not present on the left hand side are set to zero.<P>The operator <TT><<</TT> can be used in place of <TT>=</TT> whereit is permissible for information to be lost.<P>For example<PRE> SymmetricMatrix S; Matrix A; ...... S << A.t() * A;</PRE>is acceptable whereas<PRE> S = A.t() * A; // error</PRE>will cause a runtime error since the package does not (yet?) recognise<TT>A.t()*A</TT> as symmetric.<P>Note that you can not use <TT><<</TT> with constructors. For example<PRE> SymmetricMatrix S << A.t() * A; // error</PRE>does not work.<P>Also note that <TT><<</TT> cannot be used to load values from a fullmatrix intoa band matrix, since it will be unable to determine the bandwidth of theband matrix.<P>A third copy routine is used in a similar role to <TT>=</TT>. Use<PRE> A.Inject(D);</PRE>to copy the elements of <TT>D</TT> to the corresponding elements of <TT>A</TT>but leavethe elements of <TT>A</TT> unchanged if there is no corresponding element of<TT>D</TT>(the <TT>=</TT> operator would set them to 0). This is useful, for example, forsetting the diagonal elements of a matrix without disturbing the rest ofthe matrix. Unlike <TT>=</TT> and <TT><<</TT>, Inject does not resetthe dimensions of<TT>A</TT>,which must match those of <TT>D</TT>. Inject does not test for no loss ofinformation.<P>You cannot replace <TT>D</TT> by a matrix expression. The effect of<TT>Inject(D)</TT>depends on the type of <TT>D</TT>. If <TT>D</TT> is an expression it mightnot be obviousto the user what type it would have. So I thought it best to disallowexpressions.<P>Inject can be used for loading values from a regular matrix into a bandmatrix. (Don't forget to zero any elements of the left hand side thatwill not be set by the loading operation).<P>Both <TT><<</TT> and Inject can be used with submatrix expressionson the lefthand side. See the section on <A HREF="submat.html">submatrices</A>.<P>To set the elements of a matrix to a scalar use operator <TT>=</TT><PRE> Real r; int m,n; ...... Matrix A(m,n); A = r;</PRE><P><A HREF="entering.html"> next</A> - <A HREF="entering.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 + -