// Question 1

function y=f(t,x)
    y=x-exp(x)
endfunction

// Question 2

// Formule d'Euler implicite y_{n+1} = y_n + dt*f(t_{n+1},y_{n+1})

// Si g(a,b) = a-b-dt*(a-exp(a)) alors on a bien g(y_{n+1},y_n)=0

function y=g(a,b)
    dt=0.01
    y=a-b-dt*(a-exp(a))
endfunction

// Question 3

// dx(g)(x,b) = 1-dt+dt*exp(x)

// Méthode de Newton : x_{k+1} = x_k -g(x_k,b)/dx(g)(x_k,b) = x_k - (x_k - b - dt*(x_k - exp(x_k)))/(1 - dt + dt*exp(x_k))

// Question 4

function z=Newton(b)
    dt=0.01
    z=0
    while abs(g(z,b)) > 10^(-10)
        z = z - (z - b - dt*(z - exp(z)))/(1 - dt + dt*exp(z))
    end
endfunction

// Question 5

function L=eulerI()
    y=3
    L=[y]
    for i=1:4/0.01
        y = Newton(y)
        L=[L,y]
    end
endfunction

