﻿1
00:00:00,620 --> 00:00:01,460
‫Welcome back.

2
00:00:02,150 --> 00:00:09,380
‫And now let's continue with our inner loop now we're here in MPAC simplification and we're going to

3
00:00:09,380 --> 00:00:12,410
‫enter this NPC simplification function.

4
00:00:13,080 --> 00:00:16,760
‫So this function is here, support that NPC simplification.

5
00:00:17,150 --> 00:00:24,800
‫It takes in your discrete ABC and the matrices and your horizon period, and it gives you these huge

6
00:00:24,800 --> 00:00:33,170
‫matrices each double bar, then double bar transposed, then C double bar and then A with two hats.

7
00:00:34,010 --> 00:00:41,900
‫So this NPC simplification function, I literally copied it from my previous course.

8
00:00:42,710 --> 00:00:50,420
‫I did not change anything in this function compared to the previous course, because in the previous

9
00:00:50,420 --> 00:00:53,570
‫course, I built it in a scalable way.

10
00:00:53,600 --> 00:01:00,410
‫So if I have bigger matrices, then this function will take that into account automatically.

11
00:01:01,100 --> 00:01:09,320
‫Remember that the point of the NPC simplification was to go from your discrete A, B, C and D matrices.

12
00:01:10,550 --> 00:01:16,100
‫To first of all, these matrices, que double bar te double bar are double bar.

13
00:01:17,120 --> 00:01:18,450
‫So you can see them here.

14
00:01:18,470 --> 00:01:21,200
‫Cue double bar, T double bar, double bar.

15
00:01:21,650 --> 00:01:23,480
‫And that's the process for that.

16
00:01:23,510 --> 00:01:30,500
‫So first of all, you take your disk with a b, c d matrices, then you augment them.

17
00:01:31,520 --> 00:01:34,880
‫And remember that this is the augmentation process.

18
00:01:35,180 --> 00:01:42,890
‫So you see, I create these eight will then be till the C deal, then detailed the like this and I'm

19
00:01:42,890 --> 00:01:44,960
‫doing the same thing here in the code.

20
00:01:45,770 --> 00:01:47,260
‫Then these ones, here they are.

21
00:01:47,280 --> 00:01:50,990
‫My MBC weight matrices, QSR.

22
00:01:52,070 --> 00:01:54,590
‫And then I also need these terms here.

23
00:01:54,890 --> 00:02:02,360
‫C tilde transpose times, queue times, C2 and then also see till there, transpose times s time still

24
00:02:02,360 --> 00:02:12,500
‫there and then also queue times Ctrl there and then also s time see tilde and all that is created here

25
00:02:13,310 --> 00:02:14,240
‫in this block.

26
00:02:15,200 --> 00:02:18,380
‫Then queue, double bar, double bar and double bar.

27
00:02:19,220 --> 00:02:20,960
‫That's this one here.

28
00:02:21,260 --> 00:02:24,950
‫Well, actually here I simply create the big zero matrices.

29
00:02:25,760 --> 00:02:31,730
‫And then here in this loop, I will start filling in these zero matrices.

30
00:02:32,660 --> 00:02:40,490
‫So all these elements in these big matrices, these diagonal elements, they will enter into these Q

31
00:02:40,490 --> 00:02:53,330
‫double bar and T double bar matrices here in this loop in your RW bar matrix is then created here,

32
00:02:53,330 --> 00:02:55,460
‫which is inside this loop as well.

33
00:02:56,330 --> 00:03:01,670
‫And then I also need my C double bar matrix and then a with two hats.

34
00:03:01,820 --> 00:03:06,470
‫So these are these matrices here, and they are created here.

35
00:03:07,190 --> 00:03:14,360
‫So for example, if you take a look at this C double bar matrix, then it becomes pretty long.

36
00:03:15,260 --> 00:03:19,010
‫But these are just positions, so it's c double bar matrix.

37
00:03:19,700 --> 00:03:23,150
‫And this would be the role for this matrix.

38
00:03:23,360 --> 00:03:27,350
‫And then this would be the column for this matrix.

39
00:03:27,650 --> 00:03:36,080
‫And then that element in the matrix equals this, which is some kind of element like, for example,

40
00:03:36,080 --> 00:03:40,040
‫b tilde or maybe a deal, the squared times B tilde.

41
00:03:40,820 --> 00:03:48,500
‫And then once they have those matrices, then I also need to get my h double bar and f double bar transposed.

42
00:03:49,400 --> 00:03:51,800
‫And so I get them here.

43
00:03:52,040 --> 00:03:59,180
‫Once I have my other matrices, I can construct my h double bar and then f double bar transposed, then

44
00:03:59,180 --> 00:04:00,410
‫happens all here.

45
00:04:01,310 --> 00:04:09,050
‫So, for example, h double bar equals this c double bar transpose times Q Double Bar Times C Double

46
00:04:09,050 --> 00:04:10,850
‫Bar, plus R double bar.

47
00:04:11,750 --> 00:04:14,330
‫And with these two operations, I will get that.

48
00:04:15,170 --> 00:04:23,570
‫So first of all, I multiply the CW bar transpose with Q Double Bar and then whatever I get here, I

49
00:04:23,570 --> 00:04:28,460
‫multiply by C Double Bar and then I add this double bar.

50
00:04:29,300 --> 00:04:37,040
‫And well, these four lines here they are here to create this f double bar transposed matrix.

51
00:04:37,880 --> 00:04:45,110
‫And then you give all these matrices to the main file and your main file receives each double bar,

52
00:04:45,320 --> 00:04:49,340
‫double bar transpose C double bar and A with two hats.

53
00:04:50,240 --> 00:04:55,910
‫And then if you take this row vector and you multiply it by f double bar transpose.

54
00:04:56,910 --> 00:04:59,970
‫Then you will get your small f transposed.

55
00:05:00,360 --> 00:05:02,670
‫So it's this one here.

56
00:05:03,450 --> 00:05:08,910
‫So this role, that's this vector times this matrix.

57
00:05:09,810 --> 00:05:17,610
‫And then to get your delta use, you had to take the gradient of your cost function and then you had

58
00:05:17,610 --> 00:05:21,360
‫to take the inverse of your h double bar matrix.

59
00:05:22,140 --> 00:05:24,270
‫And then you also had the minus sign here.

60
00:05:25,370 --> 00:05:35,920
‫And then this f double bar times this vector that will be the transpose of this small F.T.

61
00:05:36,800 --> 00:05:41,300
‫And so this formula here that you see in the code.

62
00:05:41,900 --> 00:05:43,400
‫The formula is this one.

63
00:05:44,150 --> 00:05:47,780
‫So you see I take the inverse of the double bar matrix.

64
00:05:48,440 --> 00:05:51,080
‫I also take the transpose of my F.T.

65
00:05:51,530 --> 00:05:56,750
‫And then I multiply them together and I put the minus sign here as well.

66
00:05:57,350 --> 00:05:58,970
‫And then I get my dues.

67
00:05:59,870 --> 00:06:01,400
‫Remember that here.

68
00:06:01,670 --> 00:06:03,900
‫My due is not a scalar.

69
00:06:03,920 --> 00:06:05,060
‫It's a vector.

70
00:06:05,930 --> 00:06:15,140
‫And not only I have four time instances here, not only I have their K and then keep one and then K

71
00:06:15,140 --> 00:06:18,290
‫plus two and then K plus three.

72
00:06:19,040 --> 00:06:24,840
‫But for each time period, I have three different control input increments.

73
00:06:24,860 --> 00:06:34,460
‫So for example, four K plus two I have Delta You two, Delta U three and Delta U four.

74
00:06:35,150 --> 00:06:38,590
‫And that's true for K K plus one, K plus two and K plus three.

75
00:06:38,600 --> 00:06:43,280
‫That means that this vector will have twelve elements.

76
00:06:44,240 --> 00:06:48,710
‫But of course, for the plant, I need the original control inputs.

77
00:06:49,820 --> 00:06:53,180
‫So I take my previous you to Q3 and Q4.

78
00:06:54,230 --> 00:06:59,600
‫And then out of this deal vector, I take the first element for each control input.

79
00:07:00,770 --> 00:07:03,290
‫So essentially, I'm doing this thing here.

80
00:07:03,920 --> 00:07:07,400
‫You see, I only want to take this vector.

81
00:07:07,400 --> 00:07:11,570
‫I have this big vector and then I have the small sub vectors.

82
00:07:12,230 --> 00:07:15,440
‫And here you have an example four K plus two.

83
00:07:15,470 --> 00:07:17,390
‫That's how this vector looks like.

84
00:07:18,050 --> 00:07:20,630
‫And I only want to take this first vector.

85
00:07:21,720 --> 00:07:31,440
‫And in the cold, I do it here and then here in this Utah little matrix, I keep track of all my control

86
00:07:31,440 --> 00:07:34,200
‫inputs in order to be able to plot them later.

87
00:07:35,040 --> 00:07:39,640
‫So you see, whenever I have my new, you want you to use three and you four.

88
00:07:39,840 --> 00:07:43,710
‫They get concatenated to this you total matrix.

