//TP03.sci

function y = modele1(t,x)
    // x est un tableau L fois 2
    // L nombre de donnees initiales
    // x1 = x_{n-1} x2 = x_n
    x1 = x(:,1);
    x2 = x(:,2);
    y = zeros(L,2);
    y(:,1) = x2;
    y(:,2) = x2.*exp(r*(1-x1));
endfunction

function test01()
    r = 0.9;
    L = 1;
    n = 0:100;
    x_init = [0,0.9];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(n,x_final(2:2:$),'LineWidth', 5)
    a = gca();
    a.font_size = 5;
    title("r = 0.9, x_init = [0,0.9]","FontSize",5)
        
    xs2pdf(gcf(),'../Images/imgTP03_01.pdf')
    
    x_init = [0,2];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(n,x_final(2:2:$), 'LineWidth', 5);
    a = gca();
    a.font_size = 5;
    title("r = 0.9, x_init = [0,2]","FontSize",5)
        
    xs2pdf(gcf(),'../Images/imgTP03_02.pdf')
endfunction

function test02()
    r = 2;
    L = 1;
    n = 0:100;
    x_init = [0,0.1];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(n,x_final(2:2:$), 'LineWidth',5);
    a = gca();
    a.font_size = 5;
    title("r = 2, x_init = [0,0.1]","FontSize",5)
        
    xs2pdf(gcf(),'../Images/imgTP03_03.pdf')
    
    x_init = [0,1.3];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(n,x_final(2:2:$), 'LineWidth', 5);
    a = gca();
    a.font_size = 5;
    title("r = 2, x_init = [0,1.3]","FontSize",5)
        
    xs2pdf(gcf(),'../Images/imgTP03_04.pdf')
endfunction

function test03()
    r = 1.02;
    L = 1000;
    n = [60000:60060,60120];
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final(:,2),'-k','LineWidth',3)
    plot(x1_init,x_final(:,4),'-r','LineWidth',3)
    plot(x1_init,x_final(:,6),'g','LineWidth',3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.02, 0 <= x_init(:,2) <= 10"],"FontSize",5)
    xstring(9,0.05,"$x_1$")
        
    xs2pdf(gcf(),'../Images/imgTP03_05.pdf')
    
    r = 1.2;
    L = 1000;
    n = [60000:60060,60120];
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final(:,2),'-k','LineWidth',3)
    plot(x1_init,x_final(:,4),'-r','LineWidth',3)
    plot(x1_init,x_final(:,6),'g','LineWidth',3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.2, 0 <= x_init(:,2) <= 10"],"FontSize",5)
    xstring(9,0.05,"$x_1$")

    xs2pdf(gcf(),'../Images/imgTP03_06.pdf')
endfunction

function test04()
    r = 1.02;
    L = 1000;
    n = [60000,60006,60012];
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final(:,2:2:6),'-k', 'LineWidth', 2)
    a = gca();
    a.font_size = 5;
    title(["r = 1.02, 0 <= x_init(:,2) <= 10"],...
           "FontSize",5)
    xstring(9,0.05,"$x_1$")

    xs2pdf(gcf(),'../Images/imgTP03_07.pdf')
    
    //pause
    r = 1.05;
    L = 1000;
    n = [60000,60006,60012];
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final(:,2:2:6),'-k', 'LineWidth', 2)
    a = gca();
    
    a.font_size = 5;
    title(["r = 1.05, 0 <= x_init(:,2) <= 10"],...
           "FontSize",5)
    xstring(9,0.05,"$x_1$")

    xs2pdf(gcf(),'../Images/imgTP03_08.pdf')
endfunction

function test05()
    r = 1.9;
    L = 1000;
    n = 60000;
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final,'-k', 'LineWidth', 3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.9, x_init = [0,10]"],...
           "FontSize",5)

    xs2pdf(gcf(),'../Images/imgTP03_09.pdf')
    
    //pause
    r = 1.94;
    L = 1000;
    n = 60000;
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final,'-k', 'LineWidth', 3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.94, x_init = [0,10]"],...
           "FontSize",5)

    xs2pdf(gcf(),'../Images/imgTP03_10.pdf')
endfunction

function test06()
    r = 1.7;
    L = 1000;
    n = 60000;
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final,'-k', 'LineWidth', 3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.7, x_init = [0,10]"],...
           "FontSize",5)

    xs2pdf(gcf(),'../Images/imgTP03_11.pdf')
    
    //pause
    r = 1.8;
    L = 1000;
    n = 60000;
    x1_init = (linspace(0,10,L))';
    x_init = [zeros(L,1),x1_init];
    clf();
    x_final = ode("discrete",x_init,0,n,modele1);
    plot(x1_init,x_final,'-k', 'LineWidth', 3)
    a = gca();
    a.font_size = 5;
    title(["r = 1.8, x_init = [0,10]"],...
           "FontSize",5)

    xs2pdf(gcf(),'../Images/imgTP03_12.pdf')
endfunction


//test01();
//test02();
test03()
//test04()
//test05()
//test06()

