# Computationally obtaining the convergence rate of upwind scheme for Advection equation

The Advection equation (with velocity = 1) is

$${\partial u \over \partial x} + {\partial u \over \partial t} = 0$$ I am trying to solve the equation with periodic BC. One of the ways to numerically solve it is the Upwind scheme given by $$U^{n+1}_j = U^n_j -{k\over h}\left(U^n_{j} - U^n_{j-1}\right)$$ I coded it on Matlab and was trying to obtain the $$||E||_2$$ defined as $$||E||_2 = norm(U_{exact}(T) - U_{FDM}(T))$$ where $$T$$ is the time of simulation.

However, the problem with this way of calculating Error as a function of step size in space $$(h)$$ to obtain the rate of convergence is since the time discretization also introduces an error in the Finite Difference modeling. Therefore, error should depend on the value of step size for the time discretization, at least that's what I am observing.

How do I accurately obtain the rate of convergence in both space and time without one effecting the another. I am putting my code also for reference

% Nt - time steps
% Ns - space steps
clear;

X = 1;
T = 2;
NsRange = 400:20:1000;
Error = [];
for Ns = NsRange
h = X/Ns;
Nt =2800;
k = T/Nt;
Ns
uexact = sin(2*pi*(linspace(0,X,Ns+1)'-T));
plot(linspace(0,X,Ns+1)', uexact)
hold on
U = zeros(Ns+1,Nt+1);
U(:,1) = sin(2*pi*linspace(0,X,Ns+1)');

% Upwind
for n=1:Nt
for j=2:Ns+1
U(j,n+1) = U(j,n) - k/h*(U(j,n) - U(j-1,n));
end
U(1,n+1) = U(1,n) - k/h*(U(1,n) - U(Ns,n));
end
plot(linspace(0,X,Ns+1)', U(:,end));
Error = [Error;norm(uexact - U(:,end))];
end
hData = (X./NsRange)';
loglog(hData,Error);
temp = polyfit(log(hData),log(Error),1);
slope = temp(1)