Check for time invariance of a _system_ using MATLAB? I am having difficulty in developing an algorithm for checking if a given system is time invariant or not. 

For example, let there be 2 systems with input output relation given as:

$$y(t)=x(t-2)$$ or $$ y(t)=tx(t-1)$$

Now the first system is time invariant whereas the second one is not. But how do I write a function in MATLAB that would take the input output relationship and find out if the system is time invariant or not.
You can't do that. What you can do is write a function that computes the output given the input signal, then shifts the input signal (the shift could be an input parameter), and then checks if the output signal is a shifted version of the original output signal. If this is NOT the case, then you know that the system is time varying. However, if the output signal is just a shifted version of the original output signal then you don't know anything, because you would need to try all possible (i.e. infinitely many) shifts (and all possible input signals) and verify this condition for all these cases. Only after having checked infinitely many shifts (and all possible input signals) would you be able to assert that the system is indeed time-invariant.