summaryrefslogtreecommitdiff
path: root/modules/randlib/demos/exp.dem.sce
blob: ec4d5fe4e934d3601708a178cf0fc4724c5aaafe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ENPC
// Copyright (C) ????-2008 - INRIA
// Copyright (C) 2010 - DIGITEO - Allan CORNET
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.



function [] = ExpT(n)

    function [y]=Exp(m,n,lambda)
        // lambda exp(-lambda x) x>=0
        // ---------------------------
        y=(-1/lambda)* log(rand(m,n,"uniform"));
    endfunction

    // lambda exp(-lambda x) x>=0
    // ---------------------------
    [lhs,rhs] = argn(0);
    if rhs <= 0 ; n = 1000;end
    lambda = 3;
    y = Exp(1, n, lambda);
    drawlater();
    my_handle = scf(100001);
    clf(my_handle, "reset");
    demo_viewCode("exp.dem.sce");
    histplot([0:0.1:10],y,[1,1],"051"," ",[0,0,5,3]);
    deff("[y]=f(x)","y=lambda*exp(-lambda*x);");
    x=[0:0.1:10]';
    plot2d(x, f(x), 1, "000");
    titre= _("Simulation of an exponential random variable");
    xtitle(titre,_("Classes"),"N(C)/Nmax");
    PolylineFillColorId = color(179,179,0);
    current_axe = gca();
    current_axe.title.font_size = 3;
    current_axe.background = color(232,230,200);
    current_axe.children(2).children.fill_mode = "on";
    current_axe.children(2).children.background = PolylineFillColorId;
    current_axe.grid = [-1 PolylineFillColorId];
    legend([_("Simulation");_("Theory")]);
    drawnow();
endfunction

ExpT();
clear ExpT;