Sylvestre Ledru [Mon, 20 Aug 2012 14:24:45 +0000 (16:24 +0200)]
Change-Id: I8e08cf91d78d7efd5f18c3bff162688833636ec2

index 28fd211..85dd365 100644 (file)
@@ -11,7 +11,7 @@
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab"  xmlns:scilab="http://www.scilab.org"  xml:id="dsearch" xml:lang="en">
<refnamediv>
<refname>dsearch</refname>
<refpurpose>
@@ -345,8 +345,8 @@ dsearch   : the array s (arg 2) is not well ordered
this is the empirical histogram of the uniform distribution function.
The expectation for occ/m is equal to 1/(n-1).
</para>
-        <programlisting role="example"><![CDATA[
-m = 50000 ;
+        <programlisting role="example"><![CDATA[
+m = 50000 ;
n = 10;
X = grand(m,1,"def");
s = linspace(0,1,n)';
@@ -358,6 +358,19 @@ plot(s(1:n-1), e,"r-");
legend(["Experiment","Expectation"]);
xtitle("Uniform random numbers","X","P(X)");
]]></programlisting>
+        <scilab:image>
+            m = 50000 ;
+            n = 10;
+            X = grand(m,1,"def");
+            s = linspace(0,1,n)';
+            [ind, occ] = dsearch(X, s);
+            e = 1/(n-1)*ones(1,n-1);
+            scf() ;
+            plot(s(1:n-1), occ/m,"bo");
+            plot(s(1:n-1), e,"r-");
+            legend(["Experiment","Expectation"]);
+            xtitle("Uniform random numbers","X","P(X)");
+        </scilab:image>
<para>
In the following example, we compare the histogram of binomially distributed
random numbers with the binomial probability distribution function B(N,p),
@@ -380,6 +393,21 @@ plot(s,Pexa',"r-");
xtitle("Binomial distribution B(8,0.5)","X","P(X)");
legend(["Experiment","Expectation"]);
]]></programlisting>
+        <scilab:image>
+            N = 8 ;
+            p = 0.5;
+            m = 50000;
+            X = grand(m,1,"bin",N,p);
+            s = (0:N)';
+            [ind, occ] = dsearch(X, s, "d");
+            Pexp = occ/m;
+            Pexa = binomial(p,N);
+            scf() ;
+            plot(s,Pexp,"bo");
+            plot(s,Pexa',"r-");
+            xtitle("Binomial distribution B(8,0.5)","X","P(X)");
+            legend(["Experiment","Expectation"]);
+        </scilab:image>
<para>
In the following example, we use piecewise Hermite polynomials to
interpolate a dataset.
@@ -421,9 +449,43 @@ legend(["Experiment","Expectation"]);
plot(x,y,"bo")
xtitle("Hermite piecewise polynomial");
legend(["Polynomial","Data"]);
-      // NOTE : you can verify by adding these ones :
+      // NOTE : it can be verified by adding these ones :
// YY = interp(X,x,y,d); plot2d(X,YY,3,"000")
]]></programlisting>
+        <scilab:image>
+
+            function y=Ll(t,k,x)
+            y=(t-x(k+1))./(x(k)-x(k+1))
+            endfunction
+            function y=Lr(t,k,x)
+            y=(t-x(k))./(x(k+1)-x(k))
+            endfunction
+            function y=Hl(t,k,x)
+            y=(1-2*(t-x(k))./(x(k)-x(k+1))).*Ll(t,k,x).^2
+            endfunction
+            function y=Hr(t,k,x)
+            y=(1-2*(t-x(k+1))./(x(k+1)-x(k))).*Lr(t,k,x).^2
+            endfunction
+            function y=Kl(t,k,x)
+            y=(t-x(k)).*Ll(t,k,x).^2
+            endfunction
+            function y=Kr(t,k,x)
+            y=(t-x(k+1)).*Lr(t,k,x).^2
+            endfunction
+
+            x = [0 ; 0.2 ; 0.35 ; 0.5 ; 0.65 ; 0.8 ;  1];
+            y = [0 ; 0.1 ;-0.1  ; 0   ; 0.4  ;-0.1 ;  0];
+            d = [1 ; 0   ; 0    ; 1   ; 0    ; 0   ; -1];
+            X = linspace(0, 1, 200)';
+            ind = dsearch(X, x);
+
+            Y = y(ind).*Hl(X,ind) + y(ind+1).*Hr(X,ind) + d(ind).*Kl(X,ind) + d(ind+1).*Kr(X,ind);
+            scf();
+            plot(X,Y,"k-");
+            plot(x,y,"bo")
+            xtitle("Hermite piecewise polynomial");
+            legend(["Polynomial","Data"]);
+        </scilab:image>
</refsection>
<refsection role="see also">
<title>See Also</title>
index 3085021..3967157 100644 (file)
@@ -110,6 +110,10 @@ clf();histplot(20,d,normalization=%f)
clf();histplot(20,d,leg='rand(1,10000,''normal'')',style=5)
clf();histplot(20,d,leg='rand(1,10000,''normal'')',style=16, rect=[-3,0,3,0.5]);
]]></programlisting>
+                <scilab:image>
+                    d=rand(1,10000,'normal');
+                    clf();histplot(20,d,leg='rand(1,10000,''normal'')',style=16, rect=[-3,0,3,0.5]);
+                </scilab:image>
</member>
<member>
Example #2: histogram of a binomial (B(6,0.5)) random sample
@@ -124,6 +128,17 @@ subplot(2,1,2)
histplot(c, d, normalization=%f, style=5)
xtitle("non normalized histogram")
]]></programlisting>
+                <scilab:image>
+                    d = grand(1000,1,"bin", 6, 0.5);
+                    c = linspace(-0.5,6.5,8);
+                    clf()
+                    subplot(2,1,1)
+                    histplot(c, d, style=2)
+                    xtitle("normalized histogram")
+                    subplot(2,1,2)
+                    histplot(c, d, normalization=%f, style=5)
+                    xtitle("non normalized histogram")
+                </scilab:image>
</member>
<member>
Example #3: histogram of an exponential random sample
@@ -137,6 +152,16 @@ x = linspace(0,max(Xmax),100)';
plot2d(x,lambda*exp(-lambda*x),strf="000",style=5)
legend(["exponential random sample histogram" "exact density curve"]);
]]></programlisting>
+                <scilab:image>
+                    lambda = 2;
+                    X = grand(100000,1,"exp", 1/lambda);
+                    Xmax = max(X);
+                    clf()
+                    histplot(40, X, style=2)
+                    x = linspace(0,max(Xmax),100)';
+                    plot2d(x,lambda*exp(-lambda*x),strf="000",style=5)
+                    legend(["exponential random sample histogram" "exact density curve"]);
+                </scilab:image>
</member>
</simplelist>
</refsection>
index 802eb11..940d678 100644 (file)
</refsection>
<refsection>
<title>Example 1</title>
-        <programlisting role="example1"><![CDATA[
+        <programlisting role="example"><![CDATA[
t= 0:.01:2*%pi;
clf();polarplot(sin(7*t),cos(8*t))
-
-clf();polarplot([sin(7*t') sin(6*t')],[cos(8*t') cos(8*t')],[1,2])
]]></programlisting>
+        <scilab:image>
+            t= 0:.01:2*%pi;
+            polarplot(sin(7*t),cos(8*t))
+        </scilab:image>
+
</refsection>
<refsection>
<title>Example 2</title>
-        <programlisting role="example2"><![CDATA[
+        <programlisting role="example"><![CDATA[
t= 0:.01:2*%pi;

clf();polarplot([sin(7*t') sin(6*t')],[cos(8*t') cos(8*t')],[1,2])
]]></programlisting>
+        <scilab:image>
+            t= 0:.01:2*%pi;
+
+            clf();polarplot([sin(7*t') sin(6*t')],[cos(8*t') cos(8*t')],[1,2])
+        </scilab:image>
+
</refsection>
<refsection>
<title>Example 3</title>
-        <programlisting role="example3"><![CDATA[
+        <programlisting role="example"><![CDATA[
t = 0:0.01:2*%pi;
-
polarplot(t, -1 + sin(t));

]]></programlisting>
+        <scilab:image>
+            t = 0:0.01:2*%pi;
+            polarplot(t, -1 + sin(t));
+        </scilab:image>
+    </refsection>
+    <refsection>
+        <title>Example 4</title>
+        <programlisting role="example"><![CDATA[
+  clf()
+  theta=[0:0.02:2*%pi]';
+  rho=1+0.2*cos(theta.^2)
+  polarplot(theta,rho,style=5)
+  a=gca()
+  a.isoview='on'
+  a.data_bounds=[-1.2,-1.2;1.2,01.2]
+ ]]></programlisting>
+        <scilab:image>
+            theta=[0:0.02:2*%pi]';
+            rho=1+0.2*cos(theta.^2)
+            polarplot(theta,rho,style=5)
+            a=gca()
+            a.isoview='on'
+            a.data_bounds=[-1.2,-1.2;1.2,01.2]
+
+        </scilab:image>
</refsection>
</refentry>
index 760a6a4..d28cd03 100644 (file)
</refsection>
<refsection>
<title>Examples</title>
-        <programlisting role="example"><![CDATA[
-// isoview scaling
+        <programlisting role="example"><![CDATA[
+// isoview scaling
plot2d(0,0,-1,"031"," ",[-2,-2,2,2])
xset("color",3)
xarc(-1,1,2,2,0,90*64)
xarc(-1.5,1.5,3,3,0,360*64)
]]></programlisting>
+
+        <programlisting role="example"><![CDATA[
+
+  rect=[-1,-1,1,1]
+  plot2d(0,0,0,rect=rect,frameflag=3,axesflag=5)
+  xrpoly([0,0],3,1)
+  xarc(-1,1,2,2,0,64*360)
+  xarc(-1,1,2,2,0,64*360)
+  xstring(1,0.1,'A')//label A
+  xstring(-0.5,0.9,'B')//label B
+  xstring(-0.5,-1,'C')//label C
+ ]]></programlisting>
+        <scilab:image>
+
+            rect=[-1,-1,1,1]
+            plot2d(0,0,0,rect=rect,frameflag=3,axesflag=5)
+            xrpoly([0,0],3,1)
+            xarc(-1,1,2,2,0,64*360)
+            xarc(-1,1,2,2,0,64*360)
+            xstring(1,0.1,'A')//label A
+            xstring(-0.5,0.9,'B')//label B
+            xstring(-0.5,-1,'C')//label C
+
+        </scilab:image>
</refsection>
<refsection role="see also">
<title>See Also</title>
index fcbfda6..143c8d5 100644 (file)
@@ -10,7 +10,7 @@
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
-->
<refnamediv>
<refname>tabul</refname>
<refpurpose> frequency of values of a matrix or vector</refpurpose>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
-// first example
X = [2 8 0 3 7 6 8 7 9 1 6 7 7 2 5 2 2 2 9 7]
m1 = tabul(X)
m2 = tabul(X, "i")
+ ]]></programlisting>
+        <programlisting role="example"><![CDATA[

-// second example
X = ["ba" "baba" "a" "A" "AA" "a" "aa" "aa" "aa" "A" "ba"]
m = tabul(X,"i")
+ ]]></programlisting>
+        <programlisting role="example"><![CDATA[

-// third example
n = 50000;
X = grand(n,1,"bin",70,0.5);
m = tabul(X,"i");
clf()
plot2d3(m(:,1), m(:,2)/n)
xtitle("empirical probabilities of B(70,0.5)")
+ ]]></programlisting>
+        <scilab:image>
+
+            n = 50000;
+            X = grand(n,1,"bin",70,0.5);
+            m = tabul(X,"i");
+            clf()
+            plot2d3(m(:,1), m(:,2)/n)
+            xtitle("empirical probabilities of B(70,0.5)")
+
+        </scilab:image>
+        <programlisting role="example"><![CDATA[

-// last example : computes the occurrences of words of the scilab license
+// computes the occurrences of words of the license of scilab