II. A More General State Space Model The introduction above arrived at the idea of state model by starting from a differential equation, solving it, then manipulating it to get the state space model. However, for more complicated dynamical systems engineers are more likely to develop the state space model directly. Then it can be used to iteratively solve for the dynamical system's behavior as we described above. But, it is also possible to use the model to understand why the system behaves the way it does. It is also possible to use the state-space model to develop engineering techniques that allow you to control the system's behavior (e.g., an auto-pilot control system) or aid in the measurement of information about the system's state using sensors (e.g., an airplane's navigation system uses sensors to measure the plane's velocity and acceleration). Note that it is not possible to control a system's behavior without having accurate measurements of how it is responding! Thus, here we will focus on using state space models to aid in the measurement of the system's behavior. In this section we will describe a more general state-space model than what was developed above. This more general state-space model will characterize the dynamics of the system being modeled. In the next section we will introduce a measurement model that can be used together with the state-space model to extract information about the system's state behavior. The previous section developed a simple state-space model of q[n+1] = Aq[n] with specific forms for the state vector and the state transition matrix (e.g., A was upper diagonal with Is on the diagonal). Let the state vector q[n] be Nxl - that is, we have N state elements; then we say we have a N-state system or the system has order of N. Then the state transition matrix A is NxN. We can then write a more general form of the state space dynamics model as q[n+1] = Aq[n]+Bx[n], (18) where the gx1 vector x[n] is a vector of inputs to the system (e.g., stimuli to the system - such as voltages, forces, etc. - that affect the system's behavior), and the Nxq matrix B is the so- called input matrix that forms N linear combinations of the inputs and adds one to each state. Sometimes the inputs are modeled as known functions of time but it is common to model them as random to mimic the randomness of the effect of things like wind forces, etc. It is common to model the effect of wind as causing a random change in the velocity state as we will explore in the lab work below. In MATLAB we can create a sequence of random x[n] vectors from a Gaussian distribution (which is most commonly used) as follows: Note that the "n" at the end of randn means that it generates random numbers from the "normal" distribution "normal" is another term for "Gaussian". 8 X=randn(q,M); where q is the dimension of the x[n] vector and M is the number of vectors to create. This puts one x[n] vector in each column of the qxM matrix X. Lab Work Write a MATLAB function called gen_state.m that will implement the general state space model discussed in this section. Your function should: Accept a general state transition matrix from the user Accept a general input matrix from the user Accept input from the user to specify the initial state vector Accept input from the user to specify the times at which the response is to be computed Provide as output the time-varying state vector o The function itself should NOT make any plots Now use your gen_state.m to implement a 2D aircraft trajectory (x & y axes) under the following conditions: The state transition matrix gives a constant-velocity model for the dynamics The dimension of the random input vectors is q = 2 and these are created using the randn command. The input matrix models: o No random input applied to either of the position states The first element of the random input vector is applied to the x velocity state with a multiplier of o, The second element of the random input vector is applied to the y velocity state with a multiplier of o, From these conditions you should be able to deduce the proper form for B Pick the initial positions as (0,0) and the initial velocities as (100,100) m/s Let the time spacing be 7-1 second and consider a time range from 0 to 60 seconds. Explore the effect of the values selected in the B matrix on the trajectory o Plot the y position versus the x position to display the trajectory By selecting the B matrix values small you can get trajectories with small deviations from a true constant velocity path . If you set them both to your aircraft's path will be a perfect constant-velocity path! o By selecting the B matrix values fairly large you can get trajectories with large deviations from a true constant velocity path that are not realistic with the effect of wind but can instead model a maneuvering aircraft interesting!!). on't start real large... work your way up and see how the nature of the trajectory changes o . . II. A More General State Space Model The introduction above arrived at the idea of state model by starting from a differential equation, solving it, then manipulating it to get the state space model. However, for more complicated dynamical systems engineers are more likely to develop the state space model directly. Then it can be used to iteratively solve for the dynamical system's behavior as we described above. But, it is also possible to use the model to understand why the system behaves the way it does. It is also possible to use the state-space model to develop engineering techniques that allow you to control the system's behavior (e.g., an auto-pilot control system) or aid in the measurement of information about the system's state using sensors (e.g., an airplane's navigation system uses sensors to measure the plane's velocity and acceleration). Note that it is not possible to control a system's behavior without having accurate measurements of how it is responding! Thus, here we will focus on using state space models to aid in the measurement of the system's behavior. In this section we will describe a more general state-space model than what was developed above. This more general state-space model will characterize the dynamics of the system being modeled. In the next section we will introduce a measurement model that can be used together with the state-space model to extract information about the system's state behavior. The previous section developed a simple state-space model of q[n+1] = Aq[n] with specific forms for the state vector and the state transition matrix (e.g., A was upper diagonal with Is on the diagonal). Let the state vector q[n] be Nxl - that is, we have N state elements; then we say we have a N-state system or the system has order of N. Then the state transition matrix A is NxN. We can then write a more general form of the state space dynamics model as q[n+1] = Aq[n]+Bx[n], (18) where the gx1 vector x[n] is a vector of inputs to the system (e.g., stimuli to the system - such as voltages, forces, etc. - that affect the system's behavior), and the Nxq matrix B is the so- called input matrix that forms N linear combinations of the inputs and adds one to each state. Sometimes the inputs are modeled as known functions of time but it is common to model them as random to mimic the randomness of the effect of things like wind forces, etc. It is common to model the effect of wind as causing a random change in the velocity state as we will explore in the lab work below. In MATLAB we can create a sequence of random x[n] vectors from a Gaussian distribution (which is most commonly used) as follows: Note that the "n" at the end of randn means that it generates random numbers from the "normal" distribution "normal" is another term for "Gaussian". 8 X=randn(q,M); where q is the dimension of the x[n] vector and M is the number of vectors to create. This puts one x[n] vector in each column of the qxM matrix X. Lab Work Write a MATLAB function called gen_state.m that will implement the general state space model discussed in this section. Your function should: Accept a general state transition matrix from the user Accept a general input matrix from the user Accept input from the user to specify the initial state vector Accept input from the user to specify the times at which the response is to be computed Provide as output the time-varying state vector o The function itself should NOT make any plots Now use your gen_state.m to implement a 2D aircraft trajectory (x & y axes) under the following conditions: The state transition matrix gives a constant-velocity model for the dynamics The dimension of the random input vectors is q = 2 and these are created using the randn command. The input matrix models: o No random input applied to either of the position states The first element of the random input vector is applied to the x velocity state with a multiplier of o, The second element of the random input vector is applied to the y velocity state with a multiplier of o, From these conditions you should be able to deduce the proper form for B Pick the initial positions as (0,0) and the initial velocities as (100,100) m/s Let the time spacing be 7-1 second and consider a time range from 0 to 60 seconds. Explore the effect of the values selected in the B matrix on the trajectory o Plot the y position versus the x position to display the trajectory By selecting the B matrix values small you can get trajectories with small deviations from a true constant velocity path . If you set them both to your aircraft's path will be a perfect constant-velocity path! o By selecting the B matrix values fairly large you can get trajectories with large deviations from a true constant velocity path that are not realistic with the effect of wind but can instead model a maneuvering aircraft interesting!!). on't start real large... work your way up and see how the nature of the trajectory changes o