%                 Aysajan Abidin
clf,clear all;
%%%%%%%% User specified parameters: %%%%%%%%%%%%
N = 100; % Number of simulations
%%% H & K represents the number of spatial and time steps in the fine mesh
K = 2^8; 
H = 2^8;
T = 1;
t0 = 0;
S = [1,2,4,8,16,32];
u0 = zeros(H-1,1); % initial condition

% Computing the finite element solutions and error estimates:
U=[]; error = [];
L2_err = 0;
for i = 1:N
    clear U;
    disp(sprintf('Round %d:', i))  % printing i to know how the process is progressing.
    U = Solver_spde(u0,t0,T,K,H,S,'Colored');  
    L2_err = L2_err + L2_ErrorEst(U(:,1),U(:,2:end),H,S).^2;
end   
error = [error ; sqrt(L2_err/N)]% Computes L_2(Omega,H) error.

%% plot of the error 
h = H./S; 
h = 1./h; 
loglog(h(2:end),error);
hold on,
loglog(h(2:end),error,'r*');
xlabel('Length of the space step h'),ylabel('L_2(Omega,H) error for corresponding space steps')
save error;