Please go through your code. The states chosen are not correct. You would have to convert the equation of motion to a set of first order equations. Let x be the cart displacement and theta1 and theta2 be the angular deviations of the rods from the upright position. Your state vector should look like:
y = [x1 x2 theta1 theta3 theta2 theta4]',
Hence the state equation becomes dy/dt = f(y,u). Now d(theta3)/dt and d(theta4)/dt can be found out by rearranging the equation (2). Use an ODE solver (ex: ode45) and pass the arguments appropriately. The odefun will have 6 state equations based on dy/dt = f(y,u).