clear
N=100;
h=10/(N-1);
D2 = (diag(-2*ones(N,1)) + diag(ones(N-1,1),-1) + diag(ones(N-1,1),1))/(h^2);
x = [0:h:10]';
u = -cos(x);
plot(x,u)
hold on
F=u;
while norm(F)>=1e-6
    J =D2 + diag(cos(u));
    F = D2*u + sin(u);
    J(1,1)=-1/h; J(1,2)=1/h; J(N,N)=1; J(N,N-1)=0; F(1)=(u(2)-u(1))/h; F(N)=u(N)-pi/4;
    du = -J\F;
    u = u + du;
    norm(F)
    plot(x,u);
    hold on
end
    plot(x,u,'o-');
hold off