plot(x(i), y(i), 'r.-'); % display a red dot for each point, and connect them with lines

i = i + 1; % change index for next iteration

end

x(i) % Display the final x value.

6. Below is a simple model of a DC motor. Implement this model in MATLAB by making a simulation motor.m similar to the baseball trajectory simulation above. Note that the Greek omega is the angular velocity (in radians/second) and the Greek tau is torque (in Newton-meters). In one time step dt, the rotation changes by omega*dt radians, where there are 2*pi radians in 360 degrees. Also in one time step, omega changes by (tau/m)*dt, where m is the moment of inertia of the motor.

7. In a file motor_control_prop.m, develop a proportional control motor controller for the motor model from #6. Introduce a variable K_prop that controls the proportional gain. Design your program so that it runs for several simulated seconds and displays the last time t_last_bad the angle was more than 0.1 degrees away from 90 degrees. Fiddle with K_prop to minimize t_last_bad. What are your values of K_prop and t_last_bad for the least t_last_bad you observe?

8. In a file motor_control_prop_deriv.m, extend your proportional control motor controller from #7 to include derivative control, whose gain is controlled by the variable K_deriv. Fiddle with K_prop and K_derv in an attempt to minimize t_last_bad. What are your values of K_prop, K_deriv, and t_last_bad for the least t_last_bad you observe?