Chapter 2: Building on Physics Past

In this section of the course we will use Mathematica to solve physics problems taken from first year.  We will then be able solve more complicated, generalized versions of the problems.

2.1 The bicycle and the truck

A truck is waiting at a red light.  A cyclist trying to catch up is 3m behind the truck just as the light turns green.  The bicycle keeps a constant velocity of 20.0 km/h, while the truck accelerates at a constant rate of 3.00 m/(s^2).  When does the bicycle catch up to the truck? When does the truck overtake the bicycle?

Solution

Remove["Global`*"]

Convert velocity of bicycle to m/s

vb=20 *1000/60/60

%//N

Seems like a reasonable number.  Position of bicycle as a function of time, given initial postion of -3m is,

xb[t_]:=vb t-3

Position of truck as a function of time (formula from first year kinematics with v0=0, x0=0)

xt[t_]:=(1/2)a (t^2)
a=3;

Plot position of truck and bicycle (guessing how long to plot for).

Plot[{xt[t],xb[t]},{t,0,6}]

Looks like the bicycle overtakes the truck after about 0.6 s and the truck will overtake the bicycle at around 3 s.  Let's solve for that time exactly.

sol=Solve[xt[t]==xb[t],t]

The solution is expressed as a replacement rule.  The first root gives the time for the bicycle passing the truck, and the second root give the truck passing the bicycle.

sol[[1]]

t1=t/.sol[[1]]

%//N

The bicycle overtakes the truck after 0.66 s.

sol[[2]]

t2=t/.sol[[2]]

%//N

The truck overtakes the bicycle after 3.05 s.

2.2 The bicycle and the truck generalized

A truck is waiting at a red light.  A cyclist trying to catch up is 3m behind the truck just as the light turns green.  The cyclist travels at a velocity of roughly 20 km/h, but can't keep up the pace.  The velocity of the bicylce is given by 4 Exp[-t/3] + 2  m/s, with t measured from the moment the light turns green in s, while the truck accelerates at a rate of (2 -0.1 t)  m/(s^2).  When does the truck overtake the bicycle (answer to 3 sig figs.)?

Solution

Wipe the slate clean from previously used symbols.

Remove["Global`*"]

Velocity of bicyle as a function of t.

vb[t_]:=4 Exp[-t/3]+2

To get the position of bicycle as a function of time, we must integrate the velocity, bearing in mind that position is zero at t=0.

xb[t_]=(∫_0^t)vb[T]\[DifferentialD]T-3

Position of truck as a function of time (we must integrate twice)

a[t_]:=2-0.1t

vt[t_]=(∫_0^t)a[T]\[DifferentialD]T

(Why didn’t I use := ?)

xt[t_]=(∫_0^t)vt[T]\[DifferentialD]T

Plot position of truck and bicycle (guessing how long to plot for).

Plot[{xt[t],xb[t]},{t,0,5}]

Looks like truck will overtake the bicycle at around 4 s.  Let's solve for that time exactly.

sol=Solve[xt[t]==xb[t],t]

This time the function Solve can't solve the set of equations.  If Solve can't do it, FindRoot will work, but we need to give an initial guess.

sol=FindRoot[xt[t]==xb[t],{t,4}]

tcross=t/.sol

The truck overtakes the bicycle after 3.72 s.

Getting xt a different way... as an ODE

solODE=DSolve[{x''[t]==a[t],x'[0]==0,x[0]==0},x[t],t]

XT[t_]=x[t]/.solODE[[1]]

Plot[{XT[t],xb[t]},{t,0,5}]

2.3 Another ODE: Simple Harmonic Oscillator

Consider a block of mass m attached to a spring on a horizontally frictionless table. Experiments have shown that the force exerted by a spring is linearly proportional to the distance x the spring is displaced from its equilibrium position. Mathematically, this is

F=-k x

where k is the spring constant. Its value depends on the particular spring used.  Newton’s Second Law then gives

m a=-k x	(1)

Since a=(((d^2)x)/(dt^2)), this yields the ordinary differential equation

m(((d^2)x)/(dt^2))=-k x		(2)

which is often written as

	(((d^2)x)/(dt^2))=-((Subscript[ω, 0])^2) x  (with ((Subscript[ω, 0])^2)= k/m)

with initial conditions

x(0)=(Subscript[x, i])
u(0)=(Subscript[u, i])

where u=(dx/dt) is the velocity.  In the previous section, the accelation (force) was given an explicit time dependence.  Instead, the force here depends on position.  A general solution to (2) was found analytically back in PHYS1050 in terms of sines and cosines, and we can recover it here.

Remove["Global`*"]

X[t_]=x[t]/.Simplify[DSolve[{x''[t]==-w0^2 x[t],x'[0]==ui,x[0]==xi},x[t],t]]//First

Note that this solution is equivalent to the form A Cos[(Subscript[ω, 0]) t + ϕ].  This becomes evident if we consider

A Cos[w0 t+ϕ]//TrigExpand

which implies through comparison that A Cos[ϕ] = xi  and  A Sin[ϕ] = - ui/w0, which in turn yield

A=(Sqrt[(xi^2)+((((ui/(Subscript[ω, 0]))))^2)])  and tan(ϕ)=-(ui/(xi (Subscript[ω, 0])))

The parameter A is the amplitude of the oscillations and ϕ is the phase angle.

Since there is no dissipation, i.e. no friction, the total mechanical energy of this system should be conserved. Let's check this. The total mechanical energy is the sum of the potential energy U and kinetic energy K. The potential energy is given by (k = ((Subscript[ω, 0])^2) m):
	U=(1/2)(kx^2) = (1/2)((Subscript[ω, 0])^2) m (x^2)    
and the kinetic energy is
	K=(1/2)(mu^2)
Adding these contributions, we should get a constant.

EnergyE=(1/2)(w0^2) m ((X[t])^2)+(1/2)m ((X'[t])^2)//Simplify

The fact that energy is conserved can be used to test numerical algorithms for solving ODEs: the mechanical energy based on a numerical solution should also be constant with time.  The degree to which it remains constant is a test of the numerical procedure.

In terms of the amplitude, the energy is simply (1/2)k (A^2)=(1/2)m ((Subscript[ω, 0])^2) (A^2).  Let’s check this.

A=(Sqrt[(xi^2)+((((ui/w0)))^2)])

(1/2)m (w0^2)  A^2//Simplify

This is exactly what we had before.

EnergyE

We will be exploring variants of the harmonic oscillator in some depth in this course.

2.4 Another Integral: Travel time

The simple formula d = vt, or t = d/v is valid for the scenario for which velocity is constant.  One scenario in which the velocity is not constant is the case of a wave (like a sound pulse) travelling through a medium in which the the speed of the wave front varies with position, e.g. soundwaves travelling through layers of different types of rock, or through water where salinity and temperature vary with depth.

For a one-dimensional scenario, if v(z) is the sound velocity as a (known) function of depth z, the time it takes to travel an infinitesimal distance is dt = dz/v(z), and the time it takes for the wave front to reach a certain depth is 

T = (∫_0^Zfinal)(1/(v[z]))dz

This expression assumes that the wave is incident at 90 degress to any interfaces and no refraction occurs.  We will examine this more complicated case later on in the course.  Even in the one-dimensional case, v(z) may only be known from measurement, and hence the integration must be performed numerically.

2.5 Block on an inclined plane

A 1.5kg block rests on a horizontal board hinged at one end.  The coefficient of static friction is μ=0.1.  The free end of the board is lifted very slowly.  At what angle will the block begin to slide down the board?

Solution

Remove["Global`*"]

The component of gravity acting along the board (r=0 is at the hinge, r increases up the board):

Fgradial:= -m g Sin[θ]

The component of gravity acting prependicular to the board:

Fgnormal:=-m g Cos[θ]

Normal force:

Fnormal:=-Fgnormal

Maximum upword force (in direction of increasing r) provided by static friction:

Fstat:=μ Fnormal

Find θ at which Fgradial + Fstat = 0

Fgradial

Fstat

It looks like m and g will cancel out.

Fgradial+Fstat

sol=Solve[Fgradial+Fstat==0,θ]

Indeed, m and g have cancelled out, but we need to specify μ to get a number

μ=0.1;

sol

solnice=sol/.C[1]->0

Picking out the physically meaningful root...

θc=(θ/.solnice[[2]])/π*180

So the block will begin to slide down the board at an angle of 5.71 degrees.

2.6 Block on an rotating inclined plane

A 1.5kg block rests on a horizontal board hinged at one end.  The block rests 0.3 m away from the hinge (hinge is at r=0).  The coefficient of static friction is μ=0.1.  The free end of the board is lifted so that angle between the board and the horizontal increases at a steady rate of ω=0.4 rad/s.  At what angle will the block begin to slide down the board?
The twist here is that since the board is rotating with a non-negligible speed, the block feels a centrifugal force pushing it away from the hinge (up the board).  Thus, the angle at which it begins to slide should be larger.  The centrifugal force is Fc = m r (ω^2). (Alternatively, the force of static friction provides the centripetal acceleration required to keep the block moving in constant circular motion while it as rest with respect to the board.)  Use g=9.80.

Solution

Remove["Global`*"]

The component of gravity acting along the board (r=0 is at the hinge, r increases up the board):

Fgradial:= -m g Sin[θ]

Centrifugal force:

Fc:=m r (ω^2)

The component of gravity acting prependicular to the board:

Fgnormal:=-m g Cos[θ]

Normal force:

Fnormal:=-Fgnormal

Maximum upword force (in direction of increasing r) provided by static friction:

Fstat:=μ Fnormal

Find θ at which Fgradial + Fstat + Fc = 0

Fgradial

Fc

Fstat

Fgradial+Fstat+Fc

sol=Solve[Fgradial+Fstat+Fc==0,θ]

Looks like we'll need to specify g, r, ω and μ

μ=0.1;ω=0.4;r=0.3;g=9.8;

sol

solnice=sol/.C[1]->0

Again, picking out the physically meaninful root (small positive angle)

θc=(θ/.solnice[[2]])/π*180

So the block will begin to slide down the board at an angle of 5.98983 degrees.

2.7 Moving block on rotating inclined plane

The 1.5kg block from example 2.4 is now on the move.  The coefficient of kinetic friction is μ=0.09.  Plot the position of the block along the board up to t=1s according to the solution of Newton's equation.  When does the block hit the bottom of the board?
The twist here is that since the board is rotating with a non-negligible speed, in addition to the centrifugal force, the block feels a coriolis force pushing it into the board.  The coriolis force is Fcor = 2 m (dr/dt)ω (pushing into the board, increasing the normal force).

Solution

Remove["Global`*"]

The component of gravity acting along the board (r=0 is at the hinge, r increases up the board):

Fgradial:= -m g Sin[θ]

(negative since down the board)

Centrifugal force:

Fcen:=m r[t] (ω^2)

(positive since up the board)

Coriolis force:

Fcor:=-2 m r'[t] ω

(negative since into the board)

The component of gravity acting prependicular to the board:

Fgnormal:=-m g Cos[θ]

Normal force:

Fnormal:=-Fgnormal-Fcor

Force of kinetic friction (should be positive because it tries to keep the block from sliding down)

Fkin:=μ Fnormal

At t=0, angle is what we found in 2.4

θ:=ω t+θc

Net force in the r direction

Fgradial+Fkin+Fcen

(Friction is increased because of the coriolis force.)

Solving Newton's equation

g=9.8;ω=0.4;θc=0.10454232332880666;μ=0.09;

WHEN IN DOUBT, USE RADIANS

R[t_]=r[t]/.DSolve[{m r''[t]==Fgradial+Fkin+Fcen,r[0]==0.3,r'[0]==0},r[t],t]//First

Let's get rid of the small imaginary parts

R[t_]=r[t]/.DSolve[{m r''[t]==Fgradial+Fkin+Fcen,r[0]==0.3,r'[0]==0},r[t],t]//First//Chop

Plot[R[t],{t,0,1}]

Solve[R[t]==0,t]

FindRoot[R[t]==0,{t,0.8}]

So the block slides down to the bottom in 0.74 s.

2.8 Collision on a track

Two carts are on a collision course on a frictionless track.  The first cart of mass m1=1.1 kg is moving to the right with v1=0.23 m/s while the second cart of mass m2=0.87 kg is moving to the left at v2=1.3 m/s.  Assuming the collision is elastic, find the velocities of the carts after the collision.

Solution

Remove["Global`*"]

Conservation of momentum

eqp:=m1 v1 + m2 v2==m1 v1f + m2 v2f

Conservation of energy

eqe:=(1/2)m1 (v1^2)+(1/2)m2 (v2^2)==(1/2)m1 (v1f^2)+(1/2)m2 (v2f^2)

sol=Solve[{eqp,eqe},{v1f,v2f}]

m1=1.1;m2=0.87;v1=0.23;v2=-1.3;

v1f/.sol[[2]]

The first cart ends up moving to the left at -1.1 m/s.

v2f/.sol[[2]]

The second cart ends up moving to the right at 0.41 m/s.

2.9 Collision in 2D

A block of ice of mass 4.5 kg rests on an ice rink.  Consider the ice rink as the xy-plane with the block at the origin.  A physicist slides another block of ice of mass 8.2 kg with a velocity of 0.3 m/s in the x direction.  After colliding elastically and losing no energy to friction, the y component of the velocity of the physicist's block is 0.05 m/s.  The physicist also notes that the x component of his block doesn't change all that much.  What is the resulting velocity of the smaller block of ice?

Solution

Remove["Global`*"]

Conservation of momentum

eqpx:=m1 v1xi + m2 v2xi==m1 v1xf + m2 v2xf

eqpy:=m1 v1yi+m2 v2yi==m1 v1yf + m2 v2yf

Conservation of energy

eqe:=(1/2)m1 ((v1xi^2)+(v1yi^2))+(1/2)m2 ((v2xi^2)+(v2yi^2))==(1/2)m1 ((v1xf^2)+(v1yf^2))+(1/2)m2 ((v2xf^2)+(v2yf^2))

eqpx

eqpy

eqe

Let's label with "1" quantities associated with the smaller, originally stationary block.
Let's label with "2" quantities associated with the larger, originally moving block (the physicist's block).

m1=4.5;v1xi=0;v1yi=0;

m2=8.2;v2xi=0.3;v2yi=0;v2yf=0.05;

sol=Solve[{eqpx,eqpy,eqe},{v1xf,v1yf,v2xf}]

The first solution is the one we want as v2xi ~ v2xf.  Therefore, the velocity of the originally stationary block is 0.023 m/s in the x direction and 0.091 in the negative y direction.

2.10 A look ahead: Simulating the 1D collision

Suppose the cart in 2.6 are equipped with magnets so arranged that the carts feel a repulsive force of magnitude 0.1/(d^4) in newtons, where d is the distance between the carts in metres.  Let's say the carts start 5m apart (initially x1=0 and x2=5 metres).  Everything else is as given in 2.6.  Use one of Mathematica's ODE solvers to solve Newton's equation and then plot x1[t], x2[t], v1[t] and v2[t].  Long after the collision, do the final velocities match those given by the answer to 2.6?

Solution

Remove["Global`*"]

Equation of motion for cart1

eq1:=m1 x1''[t]==F1

Force on cart1 depends on x1 and x2, and it always points to the left (negative)

F1=-(0.1/(((x1[t]-x2[t]))^4))

eq1

Information for cart1

m1=1.1;
v1=0.23;
x1init=0;

Equation of motion for cart2

eq2:=m2 x2''[t]==F2

Force on cart2 depends on x1 and x2, and it always points to the right (positive).  It's also equal and opposite the force on cart1.

F2=-F1

eq2

Information for cart2

m2=0.87;
v2=-1.3;
x2init=5;

Solving Newton's equation

DSolve[{eq1,eq2,x1[0]==x1init,x1'[0]==v1,x2[0]==x2init,x2'[0]==v2},{x1[t],x2[t]},t]

Looks like Mathematica can't do this analytically.  Let's try the numerical solver.  We must specify an end time.

sol=NDSolve[{eq1,eq2,x1[0]==x1init,x1'[0]==v1,x2[0]==x2init,x2'[0]==v2},{x1[t],x2[t]},{t,0,10}]

X1[t_]=x1[t]/.sol[[1]]

X2[t_]=x2[t]/.sol[[1]]

Plot[{X1[t],X2[t]},{t,0,10}]

Looks like they "collide" at around 3 s.  Let's plot the velocities.

Plot[{X1'[t],X2'[t]},{t,0,10}]

What are the "final" velocities?

X1'[10]
X2'[10]

These compare well with -1.12137 and 0.408629

Abs[((X1'[10]-(-1.12137))/(-1.12137))]*100
Abs[((X2'[10]-(0.408629))/0.408629)]*100

with only small percantage differences.

2.11 Falling rope

A long coiled rope rests at the edge of a platform.  One free end is gently placed 10cm below the edge of the platform and released.  The rope begins to fall, unwinding as it goes over the edge.  The rope has uniform mass per unit length of 2 kg/m, and g=9.8.  If the height of the platform is 4m, find how long it takes for the end of the rope to reach the ground.  Ignore friction.

Solution

Here we must use the more general form of Newton's 2nd Law: F= (dp/dt)= m[t] y''[t]+ m'[t] y'[t].

Remove["Global`*"]

If the length of the rope's end is y[t], then the length of rope dangling over the edge is h-y[t], and the mass of the rope is

m[t_]:=r(h-y[t])

Newton's 2nd Law

eqN:=F==m[t]y''[t]+m'[t]y'[t]

F:=-g m[t]

eqN//FullSimplify

Let’s try to see if Mathematica can find a general solution to the problem

DSolve[{eqN,y[0]==h,y'[0]==0},y[t],t]

Density of the rope (mass/length), height and gravity

r=2;
h=4;
g=9.8;

sol=NDSolve[{eqN,y[0]==h-0.1,y'[0]==0},y[t],{t,0,3}]

Plot[{y[t]/.sol[[1]],h-0.1-0.5g (t^2)},{t,0,2},PlotRange->{All,{-2,h}}]

Also plotted in the graph is the height of an object falling freely initially alongside the rope end.  The rope falls more slowly.

FindRoot[y[t]/.sol[[1]],{t,1}]

2.12 Atwood's machine

Atwood's machine, a familiar construct to budding physicists, consists of two masses hanging by a non-elastic rope of negligible mass running over a small, massless and frictionless pulley.  Find the height of mass 1 as a function of time in terms of relevant parameters of the system.

Solution

Remove["Global`*"]

Because of the geometrical setup of the system, the accelerations of the masses are equal in magnitude and opposite in direction.  Let's write the length of the string in terms of y1 and y2 (which we take to be negative).

L=-y1[t]-y2[t]+c

To get the relationship between the accelerations of mass 1 and 2, we use the constraint that L does not change in time.  Indeed, its second derivative wrt t is also 0

eqc=D[L,{t,2}]==0

Forces on mass 1

eq1:=m1 y1''[t]==-m1 g + T

Forces on mass 2

eq2:=m2 y2''[t]==-m2 g +T

Let's solve for y1''[t], eliminating T and y2''[t] from the equations

sol=Solve[{eq1,eq2,eqc},y1''[t],{y2''[t],T}]//Simplify//First

eqD=y1''[t]==(y1''[t]/.sol)

sol=DSolve[{eqD,y1[0]==yi,y1'[0]==0},y1[t],t]//First//FullSimplify

Y1analytic[t_]=y1[t]/.sol

Before we could plot this function, we would have to provide numbers for the various parameters.

This problem has an analytical solution.  If it did not, then we would need to solve it with the numerical solver NDSolve, which requires a time interval over which to solve for the function.  We also have to make sure that all parameters have numerical values.

yi=4.;
g=9.8;
m1=3.2;
m2=3.;

sol=NDSolve[{eqD,y1[0]==yi,y1'[0]==0},y1[t],{t,0,3}]

Y[t_]=y1[t]/.sol[[1]]

Plot[Y[t],{t,0,3}]

2.13 Atwood's machine swinging

Now consider the case where one of the masses, m1=1 kg, of an Atwood Machine is free to swing.  The system is constructed in such a way that the swinging mass won't collide with the other mass or the string.  Consider this as a 2D problem with the pulley at the origin.  m2=1kg.  Initially x1=-0.5m, y1=-4 and y2=-8.  Show an animation of the motion of the two masses for the first 20s.

Solution

Remove["Global`*"]

To find a relationship between the accelerations of the masses, let's write the length of the string in terms of x1, y1 and y2 (we expect y1 and y2 to be negative).

L=(Sqrt[((x1[t])^2)+((y1[t])^2)])-y2[t]

To get the relationship between the accelerations of mass 1 and 2, we use the constraint that L does not change in time.  Indeed, its second derivative wrt t is also 0

eqc=D[L,{t,2}]==0

That's a little more complicated than the previous case!

Force on mass 1 in the x direction (Fx = -T Sin[θ] = T ((-x1[t])/(Sqrt[((x1[t])^2)+ ((y1[t])^2)]))... here we have assumed θ positive when x1 is positive)

eq1x:=m1 x1''[t]==-T [t]((x1[t])/(Sqrt[((x1[t])^2)+((y1[t])^2)]))

Forces on mass 1 in the y direction (T Cos[θ] = T ((-y1[t])/(Sqrt[((x1[t])^2)+ ((y1[t])^2)])))

eq1y:=m1 y1''[t]==-T[t] ((y1[t])/(Sqrt[((x1[t])^2)+((y1[t])^2)]))-m1 g

Forces on mass 2

eq2:=m2 y2''[t]==-m2 g +T[t]

Rather than solving for y1''[t] by eliminating T and y2''[t] from the equations, let’s throw the whole mess to Mathematica’s ODE solver.

DSolve[{eq1x,eq1y,eq2,eqc,x1[0]==x1i,y1[0]==y1i,y2[0]==y2i,x1'[0]==0,y1'[0]==0,y2'[0]==0},{x1[t],y1[t],y2[t],T[t]},t]

(Looks like there is no analytical solution.)

g=9.8;m1=1.;m2=1.;x1i=-0.5;y1i=-4;y2i=-8;

sol=NDSolve[{eq1x,eq1y,eq2,eqc,x1[0]==x1i,y1[0]==y1i,y2[0]==y2i,x1'[0]==0,y1'[0]==0,y2'[0]==0},{x1[t],y1[t],y2[t],T[t]},{t,0,20}]

{X1[t_],Y1[t_],Y2[t_],Ten[t_]}={x1[t],y1[t],y2[t],T[t]}/.sol[[1]]

Plot[{X1[t],Y1[t],Y2[t]},{t,0,20},PlotStyle->{Blue,Red,Green}]

Manipulate[ListPlot[{{X1[t],Y1[t]},{0,Y2[t]}},PlotRange->{{-4,2},{-14,3}},PlotStyle->{Red,PointSize[0.03]}],{t,0,20}]

Check that L does not change in time.

Plot[(Sqrt[((X1[t])^2)+((Y1[t])^2)])-Y2[t],{t,0,20}]

2.14 Atwood's machine over a table

Block 1 of mass m1=5kg lies on a frictionless table, and is connected by a non-elastic string running parallel to the table through a pulley to a second block of mass m2=1kg hanging vertically.  Solve.

Solution

Remove["Global`*"]

Because of the geometrical setup of the system, the accelerations of the masses are equal in magnitude but point in different directions.  Let's write the length of the string in terms of x and y (x increases to the left and y increases downward... and no, we didn't have to pick this coordinate system).

L=y[t]+x[t]

To get the relationship between the accelerations of mass 1 and 2, we use the constraint that L does not change in time.  Indeed, its second derivative wrt t is also 0.

eqc=D[L,{t,2}]==0

This is the relationship between the accelerations of the blocks.

Forces on mass 1 (only the tension is pulling it to the right, so (Subscript[T, x])=-T).

eq1:=m1 x''[t]==-T

Forces on mass 2

eq2:=m2 y''[t]==m2 g -T

Let's solve for x''[t], eliminating T and y''[t] from the equations

sol=Solve[{eq1,eq2,eqc},x''[t],{y''[t],T}]//Simplify//First

Setting up Newton's equation for block 1

eqD:=x''[t]==(x''[t]/.sol)

eqD

Let's say the blocks are released from rest, from some initial position

DSolve[{eqD,x[0]==xi,x'[0]==0},x[t],t]//First//FullSimplify

2.15 Atwood's machine over a table with an angle

Block 1 of mass m1=5kg lies on a frictionless table, and is connected by a non-elastic string running through a pulley to a second block of mass m2=1kg hanging vertically.  The pulley is a height h above the origin (technically at y=-h).  Thus the string forms an angle θ with the horizontal.  θ changes as the blocks move, resulting in a non-constant tension.  Furthermore, the accelerations of the blocks are not equal in magnitude in general.  We can assume that block 1 stays on the table and doesn't lift off.  For initial conditions x(0) = 4 and x'(0)=0, and h = 4, plot the position of block 1 for the first 4 seconds along with the corresponding solution from 2.12.

Solution

Remove["Global`*"]

Because of the geometrical setup of the system, the accelerations of the masses are different.  Let's write the length of the string in terms of x and y (x increases to the left and y increases downward... and no, we didn't have to pick this coordinate system).  We use q=(Sqrt[(x^2)+(h^2)])

L=(Sqrt[(h^2)+((x[t])^2)])+y[t]

To get the relationship between the accelerations of mass 1 and 2, we use the constraint that L does not change in time.  Indeed, its second derivative wrt t is also 0

eqc=D[L,{t,2}]==0

This is the relationship between the accelerations of the blocks.  Nice.

Forces on mass 1 (only the tension is pulling it to the right, so (Subscript[T, x])=-T, tending to decrease x in our coordinate system).  We'll use cos(θ)=x/q=x/(Sqrt[(h^2)+(x^2)])

eq1:=m1 x''[t]==-T[t] ((x[t])/(Sqrt[(h^2)+((x[t])^2)]))

Forces on mass 2

eq2:=m2 y''[t]==m2 g -T[t]

This problem has no analytic solution.

m1=5;m2=1;g=9.8;x0=4;y0=5;h=4;tf=4;

solD=NDSolve[{eq1,eq2,eqc,x[0]==x0,x'[0]==0,y[0]==y0,y'[0]==0},{x[t],y[t],T[t]},{t,0,tf}]//First

X[t_]=x[t]/.solD;

If we needed y[t] stored in a function, we could get it by issuing the following command

Y[t_]=y[t]/.solD;

Plot[{X[t],-((g m2 (t^2))/(2 (m1+m2)))+x0},{t,0,tf},PlotStyle->{Blue,Red}]

We see that compared to the simpler case (θ=0), with these particular parameters (initial conditions, masses, h), the first block reaches the edge more slowly.