function y = nonlinearbvpfd(yguess)
%
%  This function returns the solution to a nonlinear
%  ODE where we have linearized using a guess for values
%  of the solution:
%     In this case we solve:
%                  y''+2y'(2-yguess)+3y=0
%                  y(0)=1    y(10)=0
%  =======================================================
%  Suggested use:
%      set up a guess like:   x=linspace(0,10,200);
%                             y=ones(200,1);
%                             plot(x,y)
%                             hold on % keeps old plot and draws new
%      then repeatedly run:
%                 y=nonlinearbvp_fd(y); plot(x,y)
%
n=length(yguess);
h=(10-0)/(n-1);

ID=sparse(2:n-1,2:n-1,1,n,n);
UP=sparse(2:n-1,3:n,1,n,n);
DN=sparse(2:n-1,1:n-2,1,n,n);
secderv=(UP-2*ID+DN)/h^2;
derv=(UP-DN)/(2*h);

cod=sparse(2:n-1,2:n-1,2-yguess(2:n-1),n,n);

bc=sparse([1 n],[1 n],[1 1],n,n);

%full(cod*derv)
LHS= secderv-2*cod*derv+3*ID + bc;
RHS=zeros(n,1);
RHS(1)=1;
RHS(n)=0; 

y= LHS\RHS;
