Pulley system. Why do I need to put a minus sign? I am a mathematics undergraduate who's struggling to understand elementary physics. The following exercise looks particularly obscure to me.
A $3.70\,\text{kg}$ mass (let's call it $m_1$) is connected to a $2.30\,\text{kg}$ mass (let it be $m_2$) through a massless and inextensible rope, which is bent by a pulley like in the figure below.

I need to compute the acceleration of the masses ($a$) and the tension of the rope ($T$). By considering two different reference frames for each mass (as the picture shows), I worked out the following equations for the forces acting on $m_1$ along its $x$-axis, and those acting on $m_2$ along its $y$-axis:
$$
\begin{cases}
T - m_1g\sin{30^{\circ}} = m_1a \\
T - m_2g = m_2a
\end{cases}
$$
In order to come up with this system, I observed that:


*

*$T$ must be the same at each end of the rope, because it is inextensible;

*the same argument proves that the acceleration $a$ is the same for both masses;

*$T$ has a positive direction in both reference frames, whereas $-m_1g\sin{30^{\circ}}$ and $-m_2g$ always have a negative one (hence the minus signs).


I thought I had done everything correctly, but when I attempted to compute $a$ and $T$ my results could not agree with those I found in my book. After a few tries, I found out that the above system would yield the right solutions, if only I change the sign of $m_2a$ like this:
$$
\begin{cases}
T - m_1g\sin{30^{\circ}} = m_1a \\
T - m_2g = \color{red}{-m_2a}
\end{cases}
$$
This apparently agrees with the fact that, from a physical point of view, $m_2$ will go downward while pulling $m_1$ toward the pulley. My question is: am I supposed to know this in advance? Do I need the knowledge of what-mass-is-pulling-the-other-one-and-where to solve the problem? I also have to mention that, because $m_1$ has a greater mass, I initially thought that $m_1$ would be the one sliding downward while lifting $m_2$ toward the pulley, so I tried to rewrite the first system with $-m_1a$ instead of $m_1a$ (leaving $m_2a$ untouched). As you can guess, that didn't help.
I just want to understand why my reasoning is flawed. I chose the signs of $T$, $-m_1g\sin{30^{\circ}}$, $-m_2g$ so that they would agree with the reference frames I used, while I had to leave $m_1a$ and $m_2a$ as they are because I did not know how the system would be going to evolve. Yet it seems this knowledge is necessary to understand the mechanics of the two masses. How is this possible?
 A: As part of the process of analyzing problems like this, it's important to select positive and negative directions for vector quantities like forces and accelerations and stick with that assignment for the entire problem. In your first equation, you have selected motion up the incline to be positive, and the sign of all forces acting on $m_1$ need to be consistent with this choice. And in fact they are.
For your equation for $m_2$, you have chosen the positive vertical direction to be upwards, and the signs of all forces acting on this mass must be consistent with this choice. Since upwards is the positive direction, and the block is moving downwards, the acceleration must be chosen to be negative in this case. Vector quantities like forces and accelerations have magnitudes AND directions. 
A: Your problem is, in part, due to your placement of the axes on the diagram.  While not incorrect, they can lead to the sort of confusion you experienced.  As my high school physics teacher said, "pulleys are axis-benders."  You can visualize it this way:  Since you picked the positive x-axis to point up the slope, the positive x-axis should stay parallel with the rope.  When the rope goes around the pulley and then straight down, the x-axis also "bends" to point downward. This means that, where $m_2$ is located, the x-axis points downward instead of angling up and to the right.  The negative sign naturally follows once you choose the coordinate system in this way.  
A: There is absolutely nothing wrong with your choice of axes except that the right hand set of axes should perhaps be labelled $Y'$ and $X'$.
That being so the two equations of motion are:
$$
\begin{cases}
T - m_1g\sin{30^{\circ}} = m_1a \\
T - m_2g = m_2a'
\end{cases}
$$
You will note the subtle difference in my second equation from your second equation where I have written down the acceleration as $a'$ in the primed set of coordinates.
The problem in terms of solving these equations is that you have only two equations but three unknowns $a, a'$ and $T$.
This is where you have to realise that the string imposes a constraint on the system of the two masses and that constraint only depends on the geometry of the system.
What you have done is applied the constraint incorrectly and the answer to your question "Am I supposed to know this in advance?" is "Yes", otherwise you cannot apply the constraint.
So how do you apply the constraint in this case?
You note that a displacement of the block on the ramp attached to the left hand end of the inextensible string in the positive $X$ direction results in a displacement of the block on the right attached to the right hand end of the string in the negative $Y'$ direction.
Differentiating the displacements with respect to time once gives you a connection between the velocities of the two blocks in their different coordinate systems and once again their accelerations leading to the constraint condition
$$a = - a'$$
A: Better to write
$$T - m_1g\sin\theta = m_1a_1$$
$$T - m_2g = m_2a_2$$
$$ a_1 = -a_2$$
The acceleration variables represent the acceleration of each mass in its own independent coordinate system, so they should be identified as such.  The third equation is an equation of constraint that establishes the connection between the two coordinate systems.  By choosing one variable to represent the acceleration of both, you miss that connection.   
Keep the coordinate systems separate, and identify constraints explicitly.   The simpler problems do yield easily to the approach of choosing a particular set of axes chosen to make the motion appear simple.  But complicated problems with several objects connected in complicated ways you will go crazy trying to figure out the "simple" arrangement of axes that simplifies the motion while at the same time respecting the constraints.  Each object gets a coordinate system; systems are related by equations of constraint.   This is a systematic approach that will pay dividends in the long run.  It's a good habit to establish, in my opinion.
A: Yes, you need to know it in advance. Here's how you do so: In the first equation you wrote, $a$ is positive if the object moves higher on the slope. If this object moves higher up on the slope, the object hanging on the rope would go downwards. That means that a positive $a$ and by extension, a positive force would point downwards. So your equation should not be $T-m_2g=m_2a$ but $m_2g-T=m_2a$.
A: 
$T$ has a positive direction in both reference frames

This is incorrect.  $T$ is a scalar property of the rope and has no direction.  The attachment of the rope to the masses provides a force on the mass, and this does have a direction.
The magnitude of $T$ and the applied force are the same, but the direction of the applied force needs to be accounted for in your reference.  
So a single $T$ turns into separate forces on the two masses, and these forces are in different directions along the path of travel, so they should have different signs.
A: No it is not necessary to know it in advance ... 
Just assume one direction , Lets say that $m_2$ is going downwards then by constraint $m_1$ is coming upwards , Now form the equations as 
$$
\begin{cases}
T - m_1g\sin{30^{\circ}} = m_1a \\
 m_2g - T = m_2a
\end{cases}
$$    
and get the answer 
If in case you have assumed opposite direction then answer will automatically come negative. 
In your solution your mistake is that you have taken both of them going upward which is wrong by constraint and also practically not possible . 
A: 
My question is: am I supposed to know this in advance?

No. You are suppose to read it off your coordinate systems. 
If the system accelerates from rest such that $m_1$ heads up the ramp, then the velocity and acceleration of $m_1$ are in the +x direction and the those of $m_2$ are in the -y direction.
This is a (mis-)feature of the coordinate systems that you are using.
Frankly for this class of problem I prefer to use a coordinate system for $m_2$ so that it's motion is along the x-axis and has the same sense as the block on the ramp (that is, I do parallel transport of my coordinate system on along the string so that the $y$-axis for $m_2$ points to the right while the $x$-axis points down).

While we're at it I should note that the argument about the string being inextensible only shows you that the magnitude of the two displacements/velocities/accelerations are the same, because the pulley allows their directions to differ. Which I presume that you understood, but sometimes it helps to make it explicit.
A: You would need to use intuition to make sense of the sign on $m_2a$.  Do a small experiment in your head.  If I were to move/accelerate $m_2$ in the positive y direction in its coordinate system, which direction would $m_1$ move/accelerate along it's x axis?  It would have to move to the left, which is the negative direction.  If I were to move $m_2$ in the negative y direction, $m_1$ would need to move to the right, the positive x direction.  Because these directions are opposite, you need a negative sign.
It doesn't actually matter which direction the blocks move in the end, but you have to be consistent in both frames.  If you are consistent, but pick the wrong direction, you will just get a negative acceleration, which is not a problem.
If you were to use a single coordinate system to describe the behavior of this system, rope, pully, and all, then you would not have to pay attention to this.  You'd just sum all of the vectors together and the signs would sort themselves out.  Brute force is nice in that way.  However, to take this approach you'd have to consider the behavior of the rope, the normal forces at the pulley, and all sorts of other things which would make the equations more complicated than you'd like (like potentially having to integrate along the path of the rope around the pulley!).  This approach, using two coordinate systems, takes advantage of the symmetry in the problem: the tension in the rope, which is the same everywhere on the rope.  By taking advantage of this, we can simplify many details, but we have to pay a small price.  We have to make sure that our use of variables is consistent between the frames.  Otherwise, the shortcut just doesn't work.
A: Yes, you are expected to know that if $m_1$ moves up the plane by a certain distance then $m_2$ will move down by the same distance, with the same implication for speed and acceleration. This follows from the fact that the rope is described as inextensible.
Just as in mathematics, in physics you are expected to know the properties of the elements or concepts used, and the common implications of those properties.
Your choice of co-ordinate systems is confusing but that is irrelevant here - because you don't actually make any use of them! Your equations are almost correct - as @garyp's answer shows. The flaw is your inconsistent use of the direction for acceleration $a$. While the tension $T$ in the rope acts in opposite 'directions' on $m_1$ and $m_2$, the motions of $m_1$ and $m_2$ must be consistent, in the same 'direction', according to the constraint imposed by the inextensibility of the rope.
A: You're not supposed to know in advance that $m_2$ will go down and $m_1$ will go right.
What you are supposed to know is that: If $m_1$ goes down, $m_2$ will go up; if $m_2$ goes up, $m_1$ goes down. That is obvious by looking at the picture.
Your mistake is in assuming that the two masses have equal acceleration, where in fact, their accelerations are opposite (in your selected reference frames).
This will become much clearer if you don't use a single variable $a$, but rather $a_1$ for the acceleration of $m_1$ and $a_2$ for the acceleration of $m_2$. If $a_1$ is positive then $a_2$ is negative, and if $a_1$ is negative then $a_2$ is positive, so what you have is not $a_1=a_2$ but rather $a_1=-a_2$.
Of course, you could have chosen axes directions where the two accelerations are of equal signs, but then of course the forces would be negated for one of the bodies, leading to the same result.
A: A primary thing to keep in mind is that most mathematical functions to a physic person are scalar functions.  Physics equations are vectors.  The difference is that vectors have direction.  When comparing functions, if one is going up, and the other down, one must be negative.  If one is going right, and one left, again, one must be negative.  In truth, it does not matter which you define as negative, but they must balance.
A good example is speed.  A car is going 50 MPH, that is its speed.  Velocity though is what a physicist cares about, it is going 50 MPH in what direction?  Speed is a scalar, it does not care about direction, Velocity is a vector, it is speed + direction.  Math cares about this too, and in vector arithmetic expresses it the same way, but prior to vectors tends to gloss over it sometimes, as do some non-calculus based physics explanations.  
