Programmer Guide/Command Reference/EVAL/vsubn: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Extract rows from a vector or matrix.
Extract rows from a vector or matrix.
;Usage: '''<code><var>vsubn(x</var> {, <var>o</var> {, <var>n</var>}})</code>'''
;Usage: <code>vsubn(<var>x</var> {, <var>o</var> {, <var>n</var>}})</code>
:;<var>x</var>: source vector or matrix
:;<var>x</var>: source vector or matrix
:;<var>o</var>: offset, 0 <= ''o'' < <code>nrow(''x'')</code>
:;<var>o</var>: offset, 0 &le; ''o'' < <code>nrow(''x'')</code> (default=0)
:;<var>n</var>: length, ''n'' > 0 and ''o''+''n'' <= <code>nrow(''x'')</code>
:;<var>n</var>: length, ''n'' > 0 and ''o''+''n'' &le; <code>nrow(''x'')</code> (default=<code>nrow(''x'')-''o''</code>)
;Result: A numerical object with <code>ncol(''x'')</code> columns and ''n'' rows, consisting of the rows ''o'' to ''o''+''n''-1 of the argument ''x''.
;Result: A numerical object with <code>ncol(''x'')</code> columns and ''n'' rows, consisting of the rows ''o'' to ''o''+''n''-1 of the argument ''x''.
;See also: [[Programmer_Guide/Command_Reference/EVAL/vv|vv]], [[Programmer_Guide/Command_Reference/EVAL/vvset|vvget]], [[Programmer_Guide/Command_Reference/EVAL/vvset|vvset]], [[Programmer_Guide/Command_Reference/EVAL/vvcat|vvcat]], [[Programmer_Guide/Command_Reference/EVAL/vmcol|vmcol]], [[Programmer_Guide/Command_Reference/EVAL/vsubn|vsubn]], [[Programmer_Guide/Command_Reference/EVAL/vsubc|vsubc]]
;See also: [[../vsubc|vsubc]], [[../select|select]], [[../vvset|vv]]
 
[[../#Functions|<function list>]]
 


Example:
Example:
<pre>
<pre>
#a := eval vv(1,2,3,4,5)
#a := eval vv(1,2,3,4,5)
#b := eval init(5,2,0)
#b := eval vmcol($#a, vv(5,4,3,2,1))
#c := eval vmcol($#a, $#b, $#a)  
#c := vsubn($#a,3)
// -> $#c is a matrix with 4 rows and 5 columns:
// -> vector: $#c = { 4 , 5 }
//   $#c[*,*] = $#a,  #c[1,*] = $#b[*,0], $#c[2,*] = $#b[*,1], $#c[3,*] = $#a
#d := eval vsubn($#b, 1 , 3)
// -> matrix: $#d[*,0] = { 2 , 3 , 4 }$#d[*,1] = { 4 , 3 , 2 }
#e := eval vsubn($#a, 2, 1)
// -> scalar: $#e = 2, this is equivalent to $#a[2]
#f := eval vsubn($#b, 2, 1)
// -> vector (!!): $#f = { 3 , 3 }, this is equivalent to $#b[2,*]
</pre>
</pre>


[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]
Use the [http://en.wikipedia.org/wiki/Trapezoidal_rule trapezoidal rule] to approximate technique definite integral of a function.
<pre>
// The function y=f(x) is given by the points y[i]=f(x[i]).
// Approximate the definite integral of the function:
#n := int $#y[!nrow]-1
#a = eval (vsubn($#x,1,$#n)-vsubn($#x,0,$#n)) * (vsubn($#y,1,$#n)+vsubn($#y,0,$#n)) / 2
</pre>

Latest revision as of 12:12, 21 April 2011

Extract rows from a vector or matrix.

Usage
vsubn(x {, o {, n}})
x
source vector or matrix
o
offset, 0 ≤ o < nrow(x) (default=0)
n
length, n > 0 and o+nnrow(x) (default=nrow(x)-o)
Result
A numerical object with ncol(x) columns and n rows, consisting of the rows o to o+n-1 of the argument x.
See also
vsubc, select, vv

<function list>


Example:

#a := eval vv(1,2,3,4,5)
#b := eval vmcol($#a, vv(5,4,3,2,1))
#c := vsubn($#a,3)
// -> vector: $#c = { 4 , 5 }
#d := eval vsubn($#b, 1 , 3)
// -> matrix: $#d[*,0] = { 2 , 3 , 4 },  $#d[*,1] = { 4 , 3 , 2 }
#e := eval vsubn($#a, 2, 1)
// -> scalar: $#e = 2, this is equivalent to $#a[2]
#f := eval vsubn($#b, 2, 1)
// -> vector (!!): $#f = { 3 , 3 }, this is equivalent to $#b[2,*]

Use the trapezoidal rule to approximate technique definite integral of a function.

// The function y=f(x) is given by the points y[i]=f(x[i]).
// Approximate the definite integral of the function:
#n := int $#y[!nrow]-1
#a = eval (vsubn($#x,1,$#n)-vsubn($#x,0,$#n)) * (vsubn($#y,1,$#n)+vsubn($#y,0,$#n)) / 2

Navigation menu

Personal tools