Thursday, October 22, 2009

Index of an array element closest to an arbitrary value

>> x = 1:100:1000;

The index of the array which is closest to say 130 is given by

>> [v,idx] = min(abs(x-130));

The answer is

v = 29, idx = 2

Friday, October 2, 2009

Effect of Controllability and Observability On Stability

In this post, I would post the email conversation that I had with my friends over the topic "the effect of controllability and observability on stability". I am thankful to the student Asmini who actually raised this question.

My response :

In simple terms, controllability is the virtue of a system by which one can control the state of the system. In technical terms, controllability is the ability to be able to control each state variable or to be able to take it from one point in state space to another point. There is subtle difference between the terms "Controllability" and "Reachability". Don't worry about this second term at present. Both are more or less same. If a system is controllable, that means we can design a controller to control all states. That's good for us, is n't it?

On the other hand, observability is the virtue of system which enables us to observe all the states. I mean if a system is observable, we can use sensors to record all state variables. Note that this is not always the case. We may not have access to all states of a system. Again, it is good to have a completely observable system.

Now coming to your question, what is the effect of controllability and observability on stability?

Well, I think if a system is completely controllable or observable, then it is possible to design controllers which can stabilise the system. But if the system is either uncontrollable or unobservable, then it would be difficult to stabilise it. In some case, it would be impossible to design a controller to stabilize the system.


Indrani's Response:

I assume that we know the meaning of "stability of a system". If a system
dynamics is not stable we can make it stable by application of a proper
control input. On the other hand, controllability of a system implies
that it is possible to force the system to a particular state by
application of a control input. If a state is uncontrollable then no
input will be able to control that state. Thus if a system state is not
controllable as well as the corresponding dynamics is not stable then it
will not be possible to make that state stable by applying a control
input.


Similarly if a state is not observable then the controller will not be
able to determine its behavior from the system output and hence not be
able to use that state to stabilize the system. Thus controllability and
observability of a system are two important properties which are to be
considered before designing a controller.

Prem's response:

Yes... Indrani's answer is correct... There is no correlation between stability and controllability. A controllable system can be either unstable or stable.

But controllability means that if the system is unstable then you can stabilize it using proper state feedback. Observability indicates whether we can deduct the states from the observed output so that states will be available for stabilization.

If some of the nodes are not observable and those nodes are already stable then also we can stabilize.

so we can classify into two cases.

i) An observable and controllable system can be stabilizable with state feedbacm.

ii) If some of the states are unobservable and those nodes are stable, then again we can design state feedback to design the stabilizing the controller with observable states.


I am still waiting for Awhan's response and I would update this post once I hear from him. But following thing can be concluded about this topic.

  • Controllability and Observability properties are desirable for controller design. This is the first thing to be checked before designing a controller.

  • There is no correlation between Controllability and Observability with Stability of the system. Stability is the property of the system (Plant + Controller). On the other hand controllability and Observability are the properties of Plant alone.

Thursday, September 24, 2009

Matlab Plotting within a loop with different colors

Matlab by default has 7 colors. Following code demonstrates how one can invoke plot command within a for loop so that each time it plots a given data set in a different color. Don't worry about the variables that are used in this piece of code. You should notice that we can pass randomized color information to the plot command inside a for loop.


hold on;
for k = 1:length(idx)
ridx = find(idx == k);
color = rand(1,3);
for j = 1:length(ridx);
plot(logdata(:,1,ridx(j)),logdata(:,2,ridx(j)), ...
'Color',color,'LineWidth',2);
end
end
hold off;

Monday, August 24, 2009

Useful Octave Links

Some good tutorials for beginners are available at following links:

  1. Tutorial 1

  2. Tutorial 2

  3. Octave 3.0 documentation

  4. Now a GUI front end is also available for Octave. It is called Qt-Octave. Click here to see a demo.

Tuesday, June 3, 2008

Octave and C++

I have been looking for a vector matrix library which can be used in C/C++ directly. Don't you think it would be cool if you could write something like C = A * B where C, A and B are matrices. This is not like I was n't aware of existence of such libraries. For instance, sometime back I used a library called CVMLIB. This library provides very good interface for all kinds of matrices and vectors along with a number of linear algebra routines. I don't know why I gave up using that. More recently I came across a library called liboctave. This provides a similar interface with the promise that it is possible to call several octave routines directly from a C++ program. I found it simpler to use as compared to CVMLIB. But I must admit that CVMLIB is more complete as compared to liboctave. If I can learn using octave functions, then it would be really great. Presently I am using a mixture of gsl, lapack, blas routines to get my work done.

Thursday, May 1, 2008

Least Square Solution

I always get confused with this topic. Awhan explained it to me very nicely. I would discuss this issue briefly so that I can refer back to it when ever needed.

A set of linear equations is given by

A x = y .................... (1)

where A is m x n dimensional constant matrix. 'x' is a n-dimensional vector and y is a m-dimensional output or measurement vector. The task is to find a solution 'x' that satisfies equation (1).


Solution to equation (1) exists if and only if y lies in the range space of A. In other words,

rank[ A y] = rank[A] = r ............ (2)


In case this rank condition is satisfied, we know that there exists at least one solution. General solution to equation (1) is given by

x = xp + \lambda * xh .............. (3)

xp is the particular solution and xh is the homogenous solution. Multiplying both sides of equation (2) by A, we get

Ax = A * xp + \lambda A * xh = A * xp = y

Since xh is a vector that lies in the null space of A, we have A * xh = 0. Dimension of null space is given by \gamma = n - rank(A). Whenever \gamma > 0, or we have a non-trivial null space, we will have multiple solutions.


Lets assume that we have a solution for the set of equations given by (1). Consider following cases :

  • If m is less than n . Less number of equations and more number of variables. This is also known as under-determined set of equations. If A is of full rank, that is , rank(A) = m, there exists a null space of dimension (n-m) and hence there would be many solutions to equation (1). You have many solutions even when rank(A) = r .
  • If m > n. More number of equations and less number of variables. This is also known as overdetermined set of equations. If A is of full rank, that is, rank(A) = n, then the dimension of null space = n - n = 0. Hence there exists a unique solution to the set of equations given by (1). If rank(A) = r < n , then the set of equations (1) would have infinitely many solutions as the null space becomes non-trivial.

Date: 21 September 2008 Sunday

For m >= n (overdetermined system), the least square solution is obtained by minimizing the following cost function:

V = || Ax-y || ^2

which gives x = inv(A'*A) * A' * y = pinv(A)*y. This is also known as moore-penrose pseudo-inverse solution.

One can use matlab's backslash operator to compute the least square solution.

x = A\y

If A is not full rank, then A\b will generate an error message, and then
a least-squares solution will be returned.

-----------------

For under-determined system (m is less than or equal to n), the minimum-norm is solution is given by

x = A' * inv(A*A') * y

You can also use the pseudo-inverse function pinv(), which computes the pseudo-inverse,

x = pinv(A) * y;

when A is full rank and fat or square. (The pseudo-inverse is also defined when A is not full
rank, but it's not given by the formula above.)


Warning: If A is fat and full rank, then A\y gives a solution of the Ax = y, not necessarily the
least-norm solution.

The minimum-norm solution for least square could be derived by using Lagrange multiplier method:

Consider the problem of  minimizing ||x||^2 subject to Ax = y. For this, the Lagrange function may be written as

L(x, \lambda) = 0.5 x^x + \lambda^T * (Ax-y)

dL/dx = x^T + \lambda^T * A = 0.

This gives, x = A^T = \lambda and \lambda = inv (A*A^T) * y. Substituting the \lambda into the former, we get

x = A^T * inv(A*A^T) * y = pinv(A) * y


Monday, April 28, 2008

Non-minimum phase systems and Bode plot

Consider the bode plot for the system shown below:

What can be said about this system:
  • The magnitude plot has a slope of -40 dB/decade. Its predominantly a second order system with double pole at origin.
  • It has a non-minimum phase characteristic with negative phase margin.
Now can we say that the system is BIBO unstable. One of my undergrad student pointed out this to me. He said that its an unstable system because it seemed to have a double pole at origin. Infact another student approximated this bode plot with following transfer function:

s = tf('s');

g = 507*(s+7)/(s^2*(s^2+601*s+600));

bode(g);


However, we need to keep following points in mind:
  • Non-minimum phase systems are not always unstable system.
  • Negative phase margin does not always imply instability.
  • For non-minimum phase systems with stable poles, we can't apply the approximations that hold for a standard second order system.
 
pre { margin: 5px 20px; border: 1px dashed #666; padding: 5px; background: #f8f8f8; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ }