﻿1
00:00:00,710 --> 00:00:01,580
‫Welcome back.

2
00:00:02,120 --> 00:00:10,400
‫Let's now solve the exercise from the previous video and see if there are solutions that minimize the

3
00:00:10,400 --> 00:00:16,520
‫cost function while respecting all the constraints, that was our first question.

4
00:00:17,150 --> 00:00:23,420
‫And then in the second question, we have to justify the answer for the first question.

5
00:00:23,990 --> 00:00:33,260
‫So here you have your double bar matrix small have transposed your matrix and then the H vector transposed.

6
00:00:33,860 --> 00:00:43,610
‫If we say that our delta you global equals Delta Delta zero end Delta A0, then if you look at this

7
00:00:43,610 --> 00:00:49,790
‫h double bar matrix, then you already know that your horizon period equals one.

8
00:00:50,360 --> 00:00:57,080
‫That's because you have two inputs and only one timestamp, so you only have your zero and zero.

9
00:00:57,710 --> 00:01:07,640
‫You don't have here Delta, Delta One, Delta A1, etc. So this vector is two by one two rows in one

10
00:01:07,640 --> 00:01:10,940
‫column and then your h double bar matrix.

11
00:01:11,270 --> 00:01:12,560
‫It's two by two.

12
00:01:13,190 --> 00:01:16,160
‫And so from that, you know that your horizon equals one.

13
00:01:16,730 --> 00:01:23,840
‫And so this is how your cost function looks like J equals one half times delta.

14
00:01:23,840 --> 00:01:25,430
‫You global transposed.

15
00:01:26,030 --> 00:01:29,240
‫Then your h double bar matrix, then your delta.

16
00:01:29,240 --> 00:01:36,740
‫Your global plus small f transposed times, your delta, you global.

17
00:01:37,310 --> 00:01:39,050
‫We can, of course, expand it.

18
00:01:39,650 --> 00:01:41,750
‫And so you will have one half times.

19
00:01:42,500 --> 00:01:44,910
‫This is your delta, your global transposed.

20
00:01:45,530 --> 00:01:47,510
‫This is your h double bar matrix.

21
00:01:48,180 --> 00:01:48,710
‫Your Delta.

22
00:01:48,710 --> 00:01:52,550
‫Your global plus your small f transposed.

23
00:01:53,120 --> 00:01:53,840
‫And your delta.

24
00:01:53,840 --> 00:01:54,440
‫You global.

25
00:01:55,070 --> 00:02:03,740
‫Now, just to mention something, if instead of this, I had written Delta You Global Equals and then

26
00:02:03,740 --> 00:02:13,760
‫Delta Delta zero and Delta Delta One, then that means that I would have had only one input, but two

27
00:02:13,760 --> 00:02:19,520
‫time stamps, which means that my horizon period would have been two.

28
00:02:20,240 --> 00:02:25,730
‫Then instead of Delta A0, I would have had Delta Delta One.

29
00:02:26,360 --> 00:02:32,830
‫However, from the point of view of mathematics, it's exactly the same thing for you.

30
00:02:32,840 --> 00:02:40,220
‫There is a different meaning, but mathematically your cost function has two independent variables.

31
00:02:40,910 --> 00:02:42,260
‫Either it's Delta Delta.

32
00:02:42,290 --> 00:02:47,510
‫Zero and Delta zero or Delta Delta zero in Delta Delta One.

33
00:02:48,080 --> 00:02:50,180
‫For the solver, it's all the same.

34
00:02:50,810 --> 00:02:56,960
‫And so if I now write the cost function out completely, then this is what you will get.

35
00:02:57,530 --> 00:03:07,670
‫You will have one half times 100 Delta Delta zero squared plus one half Delta A0 squared.

36
00:03:08,270 --> 00:03:09,590
‫That's the first term.

37
00:03:10,190 --> 00:03:21,080
‫And then for the second term, I will write plus zero times Delta and Delta zero plus zero times Delta

38
00:03:21,110 --> 00:03:21,770
‫A0.

39
00:03:22,370 --> 00:03:33,410
‫In other words, you will have 50 times Delta Delta zero squared plus one half Delta A0 squared, and

40
00:03:33,410 --> 00:03:34,640
‫that's your cost function.

41
00:03:35,300 --> 00:03:42,620
‫Now, if you look at it and we don't consider any constraints whatsoever, then can you tell me the

42
00:03:42,620 --> 00:03:45,880
‫values for Delta Delta?

43
00:03:45,920 --> 00:03:51,680
‫Zero and Delta A0 that will give you the smallest j possible?

44
00:03:52,250 --> 00:03:54,200
‫Well, in this case, it's quite easy.

45
00:03:54,840 --> 00:04:00,950
‫Your jammin without the constraints it will be located at Delta.

46
00:04:00,950 --> 00:04:04,820
‫You Global equals zero and zero.

47
00:04:05,360 --> 00:04:14,810
‫So your Delta Delta zero equals zero gradients and Delta A0, it equals zero meters per second squared.

48
00:04:15,440 --> 00:04:17,320
‫That will give you the smallest J.

49
00:04:17,360 --> 00:04:27,080
‫Possible J equals 50 times zero squared plus one half times zero squared.

50
00:04:27,680 --> 00:04:28,850
‫It will give me zero.

51
00:04:29,450 --> 00:04:36,350
‫Any other combination of Delta Delta zero and Delta A0 will give you a positive j.

52
00:04:36,980 --> 00:04:45,410
‫Even if Delta Delta zero and Delta A0 are negative values, since you square your independent variables

53
00:04:45,410 --> 00:04:46,430
‫in the cost function.

54
00:04:47,090 --> 00:04:56,820
‫Even if, let's say, your Delta Delta zero equals minus one end Delta a zero equals minus two.

55
00:04:57,530 --> 00:05:00,080
‫Then you would have J equals.

56
00:05:00,760 --> 00:05:01,720
‫50 times.

57
00:05:02,410 --> 00:05:08,140
‫Minus one squared plus one half times minus two squared.

58
00:05:08,800 --> 00:05:17,800
‫It will be 50 plus two equals 52 and well, 52 is greater than zero.

59
00:05:18,430 --> 00:05:24,850
‫However, what if small f transposed was this one instead?

60
00:05:25,450 --> 00:05:30,880
‫In that case, your cost function would be all that.

61
00:05:31,570 --> 00:05:34,660
‫Now you see that this is your small f transpose here.

62
00:05:35,290 --> 00:05:38,620
‫Instead of a zero and zero, you have three and minus four.

63
00:05:39,220 --> 00:05:50,200
‫And so all that will equal 50 times Delta Delta zero squared plus one half times Delta A0 squared plus

64
00:05:50,200 --> 00:05:58,240
‫three times Delta Delta zero minus four times Delta A0.

65
00:05:58,810 --> 00:06:00,850
‫In this case, it's a different thing.

66
00:06:01,480 --> 00:06:07,570
‫The solution without the constraints would be the following I will take the gradient of my cost function.

67
00:06:08,230 --> 00:06:10,000
‫It will be the partial j.

68
00:06:10,630 --> 00:06:14,830
‫With respect to Delta on Delta zero and the partial of J.

69
00:06:15,430 --> 00:06:17,410
‫With respect to Delta A0.

70
00:06:18,100 --> 00:06:22,690
‫So this will be the first element and this will be the second element.

71
00:06:23,260 --> 00:06:29,950
‫That's because in the first element, I only take the derivative with respect to Delta and to zero.

72
00:06:30,550 --> 00:06:36,100
‫And in the second element, I only take the derivative with the respect to Delta A0.

73
00:06:36,610 --> 00:06:41,020
‫And so you know that you have to make the gradient equal to zero.

74
00:06:41,680 --> 00:06:44,470
‫So all this, it will be zero.

75
00:06:45,160 --> 00:06:50,110
‫That means that this element here, I will write it down like this.

76
00:06:50,740 --> 00:06:54,940
‫And then this element here it will be written down like this.

77
00:06:55,540 --> 00:07:02,890
‫And so here you will find that 100 times the R 2.0 equals minus three.

78
00:07:03,520 --> 00:07:08,470
‫And here you will find that Delta A0 equals four.

79
00:07:09,100 --> 00:07:17,740
‫And so from here, you can find that Delta Delta zero equals minus three over 100.

80
00:07:18,370 --> 00:07:23,830
‫And so this is your solution minus three over one hundred and four.

81
00:07:24,370 --> 00:07:28,900
‫So your delta you global that minimizes your cost function.

82
00:07:29,560 --> 00:07:30,940
‫It's this vector here.

83
00:07:31,510 --> 00:07:33,880
‫And now we can calculate our G men.

84
00:07:34,540 --> 00:07:48,190
‫It equals 50 times minus three over 100 squared plus one half times four squared plus three times minus

85
00:07:48,280 --> 00:07:53,490
‫three over 100 minus four times four.

86
00:07:54,130 --> 00:07:58,300
‫And that gives you minus eight point zero for five.

87
00:07:58,810 --> 00:07:59,800
‫That's your game.

88
00:07:59,800 --> 00:08:08,290
‫In any other combination of Delta Delta zero or Delta A0 would give you a bigger G.

89
00:08:08,860 --> 00:08:15,280
‫Essentially, you could have achieved the same result with this formula from the previous section.

90
00:08:17,590 --> 00:08:25,360
‫So that was the case for when your small f transposed was three and minus four.

91
00:08:25,900 --> 00:08:29,260
‫But in our case, it was zero and zero.

92
00:08:29,920 --> 00:08:32,560
‫Therefore, this was your cost function.

93
00:08:33,190 --> 00:08:38,170
‫The gradient of J now equals again the partial of J.

94
00:08:38,770 --> 00:08:43,750
‫With respect to Delta Delta zero and then the partial J.

95
00:08:44,350 --> 00:08:52,120
‫With respect to Delta A0, that will give you 100 times Delta and Delta zero.

96
00:08:52,780 --> 00:08:58,240
‫And then the second term here, your Power two will go in front.

97
00:08:58,810 --> 00:09:04,000
‫And so you will simply have Delta A0, then you make them equal to zero.

98
00:09:04,600 --> 00:09:12,550
‫So from here, you can see that Delta Delta zero equals zero over 100, so that's just zero.

99
00:09:13,180 --> 00:09:20,230
‫And so that's why this is your solution that gives you mean that equals zero.

