function v=difusao8(t,x)
%function v=difusao8(t,x)
% objetivo eh resolver problema de difusao
%     v_t = nu * v_xx
%     v(x,t) = f(x)
%     v_x(0,t) = a(t), v_x(1,t) = b(t) , t > 0
% usando o esquema de Euler  (FTCS)
% entrada:
%   t = [t0 t1 ... tN] : discretizacao no tempo
%   x = [x0 x1 ... xK] : discretizacao no espaco
% saida:
%   v : matriz com a solucao discretizada
% funcoes internas:  f(x), a(t) , b(t)
%  Mai 2012   
nu=1/6;

dt=t(2)-t(1); N=max(size(t))-1;

dx=x(2)-x(1); K=max(size(x))-1;

v = zeros(N+1,K+1);

for k=1:K+1
  xk = (k-1)*dx; v(1,k)=f( xk );
end
r = dt*nu/(dx*dx);
for i=1:N
  for k=2:K
     v(i+1,k) = v(i,k) + r*( v(i,k+1)-2*v(i,k)+v(i,k-1) );
  end
  v(i+1,1) = v(i+1,2)-dx*a( (i+1)*dt ); 
  v(i+1,K+1)=v(i+1,K)+dx*b( (i+1)*dt );
end


function u=f(x)
u = 1 + x*(1-x);
return
function u=a(t)
 u = exp(-t);
return
function u=b(t)
 u = -exp(-t);
return

return
