Here I've written the solution for Q hat in terms of the recursive quantities themselves.

Remember though that a quadratic equation always has exactly two solutions,

we need to know inside of

our embedded system and our battery management system which one of

these two roots should we compute and which one should we keep as our estimate of Q hat.

A general quadratic equation could have

solutions where both are positive real values or both are

negative real values or maybe one is positive and one is

a negative real value or even both solutions could be complex conjugates of each other.

In our application we're solving for

a battery cell total capacity which we recognize must be positive and real.

But is it possible for this equation to come up with complex numbers?

That would certainly not be good in

an embedded system that needs to rely on a really robust computation.

So, we need to check that.

Over it, if we always get exactly two real roots,

can we guarantee that which one we want?

Is one negative and one positive always or are both positive?

How do we figure out which route to choose?

I'm going to use a technique that is taught in control systems classes

to determine whether roots of a polynomial are in what we call the right half plane,

which means they have positive real part,

or if they're in the negative half plane,

which means they have negative real part,

and we're going to apply that to this problem.

The technique is called the Routh test,

and it involves building up a matrix that we call the Routh array.

If you have never seen this technique before that's perfectly fine,

we are going to come up with a conclusion that you can still use with confidence,

but if you have seen this method before I present to you some of

the steps so that you can understand and have confidence in this particular solution.

First, I use the standard method of populating this matrix that we

call the Routh array using the coefficients of the polynomial from the previous slide.

Then once we have populated this Routh array we use the Routh test,

and the test looks at the first column,

the leftmost column of the array,

the one that starts with k squared c2,n,

and we scan this column from top to bottom or even from bottom to top it doesn't matter,

and we count the number of times that the sign of the element

changes from positive to negative or from negative to positive,

and the number of sign changes tells you how many roots are in

the right half of the complex plane versus the left half of the complex plane.

When we do this using the definitions for

the recursive parameters where some of them

are always squared so they're always positive for example,

we can find that there is always

exactly one sign change in the left column of this Routh array,

and so there will be exactly one root in the right half of the complex plane.

How does that help us?

The Routh test has told us there's going to be

exactly one root of our polynomial in the right half plane,

and therefore the other root must either be in

the left half plane or on the imaginary axis.

The fundamental theorem of algebra says that,

if I'm trying to find the roots of a polynomial where the coefficients

of the polynomial are real values as they are in our case,

the roots must either be all real or they must be

all complex conjugates of each other or they must be a combination of those two.

I can't have a single complex number that comes up without its conjugate value.

We've determined that these roots

must be in different halves of the complex plane and so,

it's impossible for them to be complex conjugates of each other.

So, both of the solutions to this equation must be real,

and since one is in the right half plane and the other is in the left half plane,

one will be positive and the other will be negative or 0.

Since total capacity is always a positive real number,

this makes our job easy.

All we need to do is choose the larger root of the quadratic equation,

which will be the larger real number,

and that will be our solution.

So, bottom line.

If you followed this description of the Routh test,

if that brings up some information of knowledge from your past, that's really great.

If you haven't, that's still fine.

I hope that you can accept from this explanation that this Routh method

has determined the sign of the radical in the numerator of the quadratic equation,

then it must always be positive it can never be the negative solution.

So, to implement the simplified Total Least Squares method

we must continuously update the c1,

c2 and c3 variables,

then we must compute the estimate of the total capacity using

this quadratic equation here every time new information becomes available to us.