ArrayTools - Maple Programming Help

Home : Support : Online Help : Programming : Low-level Manipulation : Matrices, Vectors, and Arrays : ArrayTools : ArrayTools/Insert

ArrayTools

 Insert
 insert an element in an Array

 Calling Sequence Insert(A,pos,expr,opts)

Parameters

 A - : Array or Vector pos - : position to insert expr - : expression to insert opts - : (optional) inplace=true or inplace=false

Options

 • inplace : keyword option of the form inplace=true or inplace=false. This specifies whether the insert operation should reuse the existing Array or generate a new Array.  Its default value is true.

Description

 • The Insert(A,pos,expr) command inserts the expression expr into the Vector or the 1-D Array A at the position pos.
 • If there is already a value at position pos, this value and all remaining values are shifted rightwards in the array.
 • If the position pos is beyond the bounds of the array, then the array's size will be increased and any new elements in between exisiting elements and the inserted entry will be initialized to zero.
 • When inplace=false is specified, the insert operation allocates a new Array and does not modify the existing one.  Otherwise, the existing object is modified.
 • This function is part of the ArrayTools package, so it can be used in the short form Insert(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[Insert](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$
 > $A≔\mathrm{Array}\left(\left[2,3,5\right]\right)$
 ${A}{≔}\left[\begin{array}{ccc}{2}& {3}& {5}\end{array}\right]$ (1)
 > $\mathrm{Insert}\left(A,2,\frac{1}{x}\right)$
 $\left[\begin{array}{cccc}{2}& \frac{{1}}{{x}}& {3}& {5}\end{array}\right]$ (2)
 > $\mathrm{Insert}\left(A,3,\mathrm{sin}\left(x\right)\right)$
 $\left[\begin{array}{ccccc}{2}& \frac{{1}}{{x}}& {\mathrm{sin}}{}\left({x}\right)& {3}& {5}\end{array}\right]$ (3)
 > $v≔⟨1,2x⟩$
 ${v}{≔}\left[\begin{array}{c}{1}\\ {2}{}{x}\end{array}\right]$ (4)
 > $\mathrm{Insert}\left(v,2,3{x}^{2},\mathrm{inplace}=\mathrm{false}\right)$
 $\left[\begin{array}{c}{1}\\ {3}{}{{x}}^{{2}}\\ {2}{}{x}\end{array}\right]$ (5)
 > $v$
 $\left[\begin{array}{c}{1}\\ {2}{}{x}\end{array}\right]$ (6)
 > $\mathrm{A2}≔\mathrm{Array}\left(-3..-2,\left[7,8\right]\right)$
 ${\mathrm{A2}}{≔}{\mathrm{Array}}{}\left({-3}{..}{-2}{,}\left\{{-3}{=}{7}{,}{-2}{=}{8}\right\}\right)$ (7)
 > $\mathrm{Insert}\left(\mathrm{A2},-3,6\right)$
 ${\mathrm{Array}}{}\left({-3}{..}{-1}{,}\left\{{-3}{=}{6}{,}{-2}{=}{7}{,}{-1}{=}{8}\right\}\right)$ (8)
 > ${\mathrm{A2}}_{-3}$
 ${6}$ (9)

Compatibility

 • The ArrayTools[Insert] command was introduced in Maple 2016.
 • For more information on Maple 2016 changes, see Updates in Maple 2016.