This document presents a simulation of a cart and pendulum system and describes how to simultaneously design the structure and control of the system. It includes the mass matrix, controller functions for force and torque, simulation of the system, and an optimization of the system weights and controller gains using the fmincon function in MATLAB. The goal is to minimize an objective function of the torque and counterweight mass subject to constraints on the counterweight mass.