~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to man/eng/elementary/dsearch.xml

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
 
2
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
 
3
<MAN>
 
4
  <LANGUAGE>eng</LANGUAGE>
 
5
  <TITLE>dsearch</TITLE>
 
6
  <TYPE>Scilab Function</TYPE>
 
7
  <DATE>2001</DATE>
 
8
  <SHORT_DESCRIPTION name="dsearch">binary search (aka dichotomous search in french)</SHORT_DESCRIPTION>
 
9
  <CALLING_SEQUENCE>
 
10
    <CALLING_SEQUENCE_ITEM>[ind, occ, info]  = dsearch(X, val [, ch ])  </CALLING_SEQUENCE_ITEM>
 
11
  </CALLING_SEQUENCE>
 
12
  <PARAM>
 
13
    <PARAM_INDENT>
 
14
      <PARAM_ITEM>
 
15
        <PARAM_NAME>X</PARAM_NAME>
 
16
        <PARAM_DESCRIPTION>
 
17
          <SP>: a real vector or matrix</SP>
 
18
        </PARAM_DESCRIPTION>
 
19
      </PARAM_ITEM>
 
20
      <PARAM_ITEM>
 
21
        <PARAM_NAME>val</PARAM_NAME>
 
22
        <PARAM_DESCRIPTION>
 
23
          <SP>: a real (row or column) vector with n components in strictly increasing 
 
24
             order val(1) &lt; val(2) &lt; ... &lt; val(n)</SP>
 
25
        </PARAM_DESCRIPTION>
 
26
      </PARAM_ITEM>
 
27
      <PARAM_ITEM>
 
28
        <PARAM_NAME>ch</PARAM_NAME>
 
29
        <PARAM_DESCRIPTION>
 
30
          <SP>: (optionnal) a character &quot;c&quot; or &quot;d&quot; (default value &quot;c&quot;)</SP>
 
31
        </PARAM_DESCRIPTION>
 
32
      </PARAM_ITEM>
 
33
      <PARAM_ITEM>
 
34
        <PARAM_NAME>ind</PARAM_NAME>
 
35
        <PARAM_DESCRIPTION>
 
36
          <SP>: a real vector or matrix with the same dimensions than X</SP>
 
37
        </PARAM_DESCRIPTION>
 
38
      </PARAM_ITEM>
 
39
      <PARAM_ITEM>
 
40
        <PARAM_NAME>occ</PARAM_NAME>
 
41
        <PARAM_DESCRIPTION>
 
42
          <SP>: a real vector with the same format than val (but with n-1 components in the case ch=&quot;c&quot;)</SP>
 
43
        </PARAM_DESCRIPTION>
 
44
      </PARAM_ITEM>
 
45
      <PARAM_ITEM>
 
46
        <PARAM_NAME>info</PARAM_NAME>
 
47
        <PARAM_DESCRIPTION>
 
48
          <SP>: integer</SP>
 
49
        </PARAM_DESCRIPTION>
 
50
      </PARAM_ITEM>
 
51
    </PARAM_INDENT>
 
52
  </PARAM>
 
53
  <DESCRIPTION>
 
54
    <P>This function is useful to search in an ordered table and/or to count the number of components
 
55
       of a vector falling in some classes (a class being an interval or a value).
 
56
    </P>
 
57
    <P>By default or when <VERB>ch=&quot;c&quot;</VERB>, this is the interval case, that is, for 
 
58
       each X(i) search in which of the n-1 intervals it falls, the intervals being defined by:
 
59
    </P>
 
60
        <VERBATIM>
 
61
<![CDATA[            I1 = [val(1), val(2)]
 
62
            Ik = (val(k), val(k+1)] for 1 < k <= n-1 ; ]]>
 
63
</VERBATIM>
 
64
    <P>and:
 
65
    </P>
 
66
    <ITEMIZE>
 
67
       <ITEM label="ind(i)">
 
68
            <SP>: is the interval number of X(i) (0 if X(i) is not in
 
69
              [val(1),val(n)])</SP>
 
70
       </ITEM>
 
71
       <ITEM label="occ(k)">
 
72
            <SP>: is the number of components of X which are in Ik</SP>
 
73
       </ITEM>
 
74
       <ITEM label="info">
 
75
            <SP>: is the number of components of X which are not in [val(1),val(n)]</SP>
 
76
       </ITEM>
 
77
    </ITEMIZE>
 
78
    <P>When <VERB>ch=&quot;d&quot;</VERB> case, this is the discrete case, that is, for 
 
79
       each X(i)  search if it is equal to one val(k) and:
 
80
    </P>
 
81
    <ITEMIZE>
 
82
       <ITEM label="ind(i)">
 
83
            <SP>: is equal to the index of the component of val which matches X(i) 
 
84
               (ind(i) = k if X(i)=val(k)) or 0 if X(i) is not in val.</SP>
 
85
       </ITEM>
 
86
       <ITEM label="occ(k)">
 
87
            <SP>: is the number of components of X equal to val(k)</SP>
 
88
       </ITEM>
 
89
       <ITEM label="info">
 
90
            <SP>: is the number of components of X which are not in the set {val(1),...,val(n)}</SP>
 
91
       </ITEM>
 
92
     </ITEMIZE>
 
93
  </DESCRIPTION>
 
94
  <EXAMPLE>
 
95
<![CDATA[
 
96
// example #1 (elementary stat for U(0,1))
 
97
m = 50000 ; n = 10;
 
98
X = grand(m,1,"def");
 
99
val = linspace(0,1,n+1)';
 
100
[ind, occ] = dsearch(X, val);
 
101
xbasc() ; plot2d2(val, [occ/m;0])  // no normalisation : y must be near 1/n
 
102
 
 
103
 
 
104
// example #2 (elementary stat for B(N,p))
 
105
N = 8 ; p = 0.5; m = 50000;
 
106
X = grand(m,1,"bin",N,p); val = (0:N)';
 
107
[ind, occ] = dsearch(X, val, "d");
 
108
Pexp = occ/m; Pexa = binomial(p,N); 
 
109
xbasc() ; hm = 1.1*max(max(Pexa),max(Pexp));
 
110
plot2d3([val val+0.1], [Pexa' Pexp],[1 2],"111",  ...
 
111
        "Pexact@Pexp", [-1 0 N+1 hm],[0 N+2 0 6])
 
112
xtitle(  "binomial distribution B("+string(N)+","+string(p)+") :" ...
 
113
        +" exact probability versus experimental ones")
 
114
 
 
115
 
 
116
// example #3 (piecewise Hermite polynomial)
 
117
x = [0 ; 0.2 ; 0.35 ; 0.5 ; 0.65 ; 0.8 ;  1];
 
118
y = [0 ; 0.1 ;-0.1  ; 0   ; 0.4  ;-0.1 ;  0];
 
119
d = [1 ; 0   ; 0    ; 1   ; 0    ; 0   ; -1];
 
120
X = linspace(0, 1, 200)';
 
121
ind = dsearch(X, x);
 
122
// define Hermite base functions
 
123
deff("y=Ll(t,k,x)","y=(t-x(k+1))./(x(k)-x(k+1))")   // Lagrange left on Ik
 
124
deff("y=Lr(t,k,x)","y=(t-x(k))./(x(k+1)-x(k))")     // Lagrange right on Ik
 
125
deff("y=Hl(t,k,x)","y=(1-2*(t-x(k))./(x(k)-x(k+1))).*Ll(t,k,x).^2")
 
126
deff("y=Hr(t,k,x)","y=(1-2*(t-x(k+1))./(x(k+1)-x(k))).*Lr(t,k,x).^2")
 
127
deff("y=Kl(t,k,x)","y=(t-x(k)).*Ll(t,k,x).^2")
 
128
deff("y=Kr(t,k,x)","y=(t-x(k+1)).*Lr(t,k,x).^2")
 
129
// plot the curve
 
130
Y = y(ind).*Hl(X,ind) + y(ind+1).*Hr(X,ind) + d(ind).*Kl(X,ind) + d(ind+1).*Kr(X,ind);
 
131
xbasc(); plot2d(X,Y,2) ; plot2d(x,y,-9,"000") 
 
132
xtitle("an Hermite piecewise polynomial")
 
133
// NOTE : you can verify by adding these ones : 
 
134
// YY = interp(X,x,y,d); plot2d(X,YY,3,"000")
 
135
   ]]>
 
136
  </EXAMPLE>
 
137
  <SEE_ALSO>
 
138
    <SEE_ALSO_ITEM>
 
139
      <LINK>find</LINK>
 
140
    </SEE_ALSO_ITEM>
 
141
    <SEE_ALSO_ITEM>
 
142
      <LINK>tabul</LINK>
 
143
    </SEE_ALSO_ITEM>
 
144
  </SEE_ALSO>
 
145
  <AUTHOR>B.P.   </AUTHOR>
 
146
</MAN>