‫Welcome back.
‫Let's now solve the exercise from the previous video and see if there are solutions that minimize the
‫cost function while respecting all the constraints, that was our first question.
‫And then in the second question, we have to justify the answer for the first question.
‫So here you have your double bar matrix small have transposed your matrix and then the H vector transposed.
‫If we say that our delta you global equals Delta Delta zero end Delta A0, then if you look at this
‫h double bar matrix, then you already know that your horizon period equals one.
‫That's because you have two inputs and only one timestamp, so you only have your zero and zero.
‫You don't have here Delta, Delta One, Delta A1, etc. So this vector is two by one two rows in one
‫column and then your h double bar matrix.
‫It's two by two.
‫And so from that, you know that your horizon equals one.
‫And so this is how your cost function looks like J equals one half times delta.
‫You global transposed.
‫Then your h double bar matrix, then your delta.
‫Your global plus small f transposed times, your delta, you global.
‫We can, of course, expand it.
‫And so you will have one half times.
‫This is your delta, your global transposed.
‫This is your h double bar matrix.
‫Your Delta.
‫Your global plus your small f transposed.
‫And your delta.
‫You global.
‫Now, just to mention something, if instead of this, I had written Delta You Global Equals and then
‫Delta Delta zero and Delta Delta One, then that means that I would have had only one input, but two
‫time stamps, which means that my horizon period would have been two.
‫Then instead of Delta A0, I would have had Delta Delta One.
‫However, from the point of view of mathematics, it's exactly the same thing for you.
‫There is a different meaning, but mathematically your cost function has two independent variables.
‫Either it's Delta Delta.
‫Zero and Delta zero or Delta Delta zero in Delta Delta One.
‫For the solver, it's all the same.
‫And so if I now write the cost function out completely, then this is what you will get.
‫You will have one half times 100 Delta Delta zero squared plus one half Delta A0 squared.
‫That's the first term.
‫And then for the second term, I will write plus zero times Delta and Delta zero plus zero times Delta
‫A0.
‫In other words, you will have 50 times Delta Delta zero squared plus one half Delta A0 squared, and
‫that's your cost function.
‫Now, if you look at it and we don't consider any constraints whatsoever, then can you tell me the
‫values for Delta Delta?
‫Zero and Delta A0 that will give you the smallest j possible?
‫Well, in this case, it's quite easy.
‫Your jammin without the constraints it will be located at Delta.
‫You Global equals zero and zero.
‫So your Delta Delta zero equals zero gradients and Delta A0, it equals zero meters per second squared.
‫That will give you the smallest J.
‫Possible J equals 50 times zero squared plus one half times zero squared.
‫It will give me zero.
‫Any other combination of Delta Delta zero and Delta A0 will give you a positive j.
‫Even if Delta Delta zero and Delta A0 are negative values, since you square your independent variables
‫in the cost function.
‫Even if, let's say, your Delta Delta zero equals minus one end Delta a zero equals minus two.
‫Then you would have J equals.
‫50 times.
‫Minus one squared plus one half times minus two squared.
‫It will be 50 plus two equals 52 and well, 52 is greater than zero.
‫However, what if small f transposed was this one instead?
‫In that case, your cost function would be all that.
‫Now you see that this is your small f transpose here.
‫Instead of a zero and zero, you have three and minus four.
‫And so all that will equal 50 times Delta Delta zero squared plus one half times Delta A0 squared plus
‫three times Delta Delta zero minus four times Delta A0.
‫In this case, it's a different thing.
‫The solution without the constraints would be the following I will take the gradient of my cost function.
‫It will be the partial j.
‫With respect to Delta on Delta zero and the partial of J.
‫With respect to Delta A0.
‫So this will be the first element and this will be the second element.
‫That's because in the first element, I only take the derivative with respect to Delta and to zero.
‫And in the second element, I only take the derivative with the respect to Delta A0.
‫And so you know that you have to make the gradient equal to zero.
‫So all this, it will be zero.
‫That means that this element here, I will write it down like this.
‫And then this element here it will be written down like this.
‫And so here you will find that 100 times the R 2.0 equals minus three.
‫And here you will find that Delta A0 equals four.
‫And so from here, you can find that Delta Delta zero equals minus three over 100.
‫And so this is your solution minus three over one hundred and four.
‫So your delta you global that minimizes your cost function.
‫It's this vector here.
‫And now we can calculate our G men.
‫It equals 50 times minus three over 100 squared plus one half times four squared plus three times minus
‫three over 100 minus four times four.
‫And that gives you minus eight point zero for five.
‫That's your game.
‫In any other combination of Delta Delta zero or Delta A0 would give you a bigger G.
‫Essentially, you could have achieved the same result with this formula from the previous section.
‫So that was the case for when your small f transposed was three and minus four.
‫But in our case, it was zero and zero.
‫Therefore, this was your cost function.
‫The gradient of J now equals again the partial of J.
‫With respect to Delta Delta zero and then the partial J.
‫With respect to Delta A0, that will give you 100 times Delta and Delta zero.
‫And then the second term here, your Power two will go in front.
‫And so you will simply have Delta A0, then you make them equal to zero.
‫So from here, you can see that Delta Delta zero equals zero over 100, so that's just zero.
‫And so that's why this is your solution that gives you mean that equals zero.