T = 0.01;
N = 100;
J = 0.1;
plot_flag = 0;
% use nearest neighbours
nn = 0;
a = 2;

temp_min = 0.01;
temp_max = 0.5+temp_min;
temp_vals = 51;
temp_array = linspace(temp_min,temp_max,temp_vals); 
E_array = zeros(temp_vals,1); 
M_array = zeros(temp_vals,1); 
chi_array = zeros(temp_vals,1);
Cv_array = zeros(temp_vals,1);


 for i = 1:temp_vals
     [E,M,chi,Cv, Elist, Mlist] = ising1D(temp_array(i),N,J,nn,a,plot_flag);
     E_array(i) = E;
     M_array(i) = M;
     chi_array(i) = chi;
     Cv_array(i) = Cv;
     fprintf('iter: %d, T: %5.5E, E: %5.5E, M: %5.5E, chi: %5.5E, Cv: %5.5E\n', i,temp_array(i), E, M, chi, Cv);
 end

figure;
sub1=subplot(2,2,1);          
plot(temp_array, E_array);
title('E');
hold on;                      
sub1=subplot(2,2,2); 
plot(temp_array, M_array);
title('M');
sub1=subplot(2,2,3); 
plot(temp_array, chi_array);
title('\chi');
sub1=subplot(2,2,4); 
plot(temp_array, Cv_array);
title('C_v');
hold off;                     

%[E,M,chi,Cv, Elist, Mlist] = ising1D(T,N,J,nn,a,plot_flag);
%figure;
%histogram(Mlist);