0:00:00.000,0:00:04.842 And then you just have to keep in mind,[br]when you use that fft you'd better know 0:00:04.842,0:00:09.377 that the fft is doing the shifting. And[br]you could ask, well, why not, why the, why 0:00:09.377,0:00:14.342 make it, why not shift it back? Why, why[br]make me shift it back?" Cuz a lot of times 0:00:14.342,0:00:19.430 when you're doing computation, you're not[br]gonna necessarily go look at the spectrum 0:00:19.430,0:00:23.965 all the time. You, the reason it stays[br]shifted is because, remember, speed is 0:00:23.965,0:00:29.635 everything. Speed is everything in terms[br]of the computing. You want, if you got, if 0:00:29.635,0:00:35.033 you got n log n speed, you wanna add you[br]know, stuff on top of it. You can do that 0:00:35.033,0:00:40.229 on your own time. With this computing,[br]keep it at n log n, fast. Okay? In my last 0:00:40.229,0:00:45.627 class, I talked in my last course, 581. I[br]always tell people you may get the right 0:00:45.627,0:00:51.859 answer. But it's wrong if you did it the[br]slow way. Okay? Part of computing now is 0:00:51.859,0:00:56.925 not just about oh, I can compute and I got[br]this really, I got this method that can 0:00:56.925,0:01:01.865 compute it right. It's not about that[br]anymore, it's about not only can I compute 0:01:01.865,0:01:10.877 it right, I can compute it faster than[br]you. Okay. It's not that, it's not that I 0:01:10.877,0:01:16.222 guess you know, competitive. But, but[br]actually, you know it kind of is. If 0:01:16.222,0:01:20.546 you're trying to write a paper in this[br]area, that's what you're trying to say 0:01:20.546,0:01:25.318 actually all the time. It's like oh, I can[br]compute this faster than you can. And here 0:01:24.925,0:01:29.698 is why. Okay? That's, that's how you write[br]a paper in scientific computing. You tell 0:01:29.698,0:01:33.853 people how much awesomer you are. Okay?[br]Alright. But, see, the nice thing with 0:01:33.853,0:01:38.064 your data analysis skills, you might be[br]working, I don't know, in atmospheric 0:01:38.064,0:01:42.331 sciences or geology geologoy or something.[br]With your skills you'll be able to say how 0:01:42.331,0:01:46.947 much better you are also. See, then I'll,[br]then we'll all have won. Okay? Alright. So 0:01:46.947,0:01:52.459 there you go. that's the simple[br]implementation. Now I'm gonna use it to do 0:01:52.459,0:02:00.542 a trick. Okay? Yes? So, the actual[br]coefficients are positive and negative 0:02:00.542,0:02:04.327 alternating. This is. Yeah. This is the[br]absolute value. If it's complex you know, 0:02:04.807,0:02:09.373 most people, by the way, when you get a[br]complex spectrum, what you normally do 0:02:09.373,0:02:13.878 what people call the power spectrum. I[br]don't know if you've heard this. Okay? 0:02:13.878,0:02:18.864 Well that's an aggressive word just like[br]the competition. It's all, it's all like 0:02:18.864,0:02:23.790 smackdown for comp, computing. So the[br]power spectrum is always the absolute 0:02:23.790,0:02:28.535 value of the spectral content, cuz that's[br]what you want to know is how much 0:02:28.535,0:02:34.313 frequency content, not necessarily what[br]phase it's in. Okay? Alright. So, there's 0:02:34.313,0:02:42.284 that. And now, for my next trick, I will[br]differentiate a function, computation. Are 0:02:42.284,0:02:46.054 you ready? I, I don't know if you guys are[br]ready. Let's, can I have the lights on 0:02:46.054,0:02:53.055 real quick, upfront? There's this very[br]nice relationship, that's actually worked 0:02:53.055,0:03:07.968 out in the notes, which says the[br]following. It says the following, the hat 0:03:07.968,0:03:13.520 represent Fourier transform by the way,[br]and this represents the nth derivative. If 0:03:13.520,0:03:19.521 I take the nth derivative of a function[br]and I wanna find what that is, the Fourier 0:03:19.521,0:03:24.290 transform of the nth derivative is the[br]same as taking the function itself, and 0:03:24.290,0:03:29.662 Fourier transforming it, and multiplying[br]by ik to the nth power. Okay? So if I want 0:03:29.662,0:03:34.318 to compute the third derivative, all I[br]gotta do is take the function, Fourier 0:03:34.318,0:03:39.981 transform it, multiply this by k^3 inverse[br]Fourier transform it. That's it. By the 0:03:39.981,0:03:43.742 way, this is one of the most, if, if your[br]boundary conditions work for you, like 0:03:43.742,0:03:47.797 here the boundaries go to zero, right? And[br]there's supposed to be a periodic 0:03:47.797,0:03:51.264 function, but here the boundaries are[br]pretty much going to zero. This is 0:03:51.264,0:03:55.123 probably one of the most accurate ways you[br]can compute a derivative, spectrally 0:03:55.123,0:03:58.738 accurate. Okay? So let's compute a[br]derivative, and here's the thing I'm gonna 0:03:58.738,0:04:04.212 compute. oh actually, we can go back with[br]the lights down. Okay. So I'm gonna take 0:04:04.212,0:04:10.754 this function u here. and I'm gonna do the[br]dollowing function. Here is my favorite 0:04:10.754,0:04:16.031 function, hyperbolic secant x. I don't[br]know if you have a favorite function yet. 0:04:16.031,0:04:20.543 It's just a little bit of time before you[br]graduate to pick one out. This one's taken 0:04:20.543,0:04:27.060 by the way, don't even try. and by the[br]way. its derivative, it's called ud is 0:04:30.420,0:04:35.758 sech * tanh. Now what I'm going to do is[br]try to compute t hat derivative 0:04:35.758,0:04:41.173 accurately. And by the way, second[br]derivative, let's call it ud2 for the 0:04:41.173,0:04:47.564 second derivative will be sech x - two *[br]sech x^3. something like that, pretty 0:04:47.564,0:04:54.987 close. I think I actually have it in the[br]notes here. sorry, give me just a second 0:04:54.987,0:05:02.590 here. yeah, actually yeah, that's right.[br]Okay. and what I'm gonna do is, now, 0:05:02.590,0:05:07.833 compute these derivatives using my Fourier[br]transform. So let me write at the top. 0:05:07.833,0:05:13.197 There is u, second or first derivative.[br]And first of all, if I wanna calculate the 0:05:13.197,0:05:18.256 derivatives, first I have to have Fourier[br]transform of the function. There it is and 0:05:18.256,0:05:23.288 I'm gonna calculate now the first[br]derivative. Okay? So, to calculate the 0:05:23.288,0:05:31.200 first derivative, remember, what I gotta[br]do is take i * k and multiply it by 0:05:33.360,0:05:39.114 Fourier transform. There it is. And then,[br]what I gotta do with this is inverse 0:05:39.114,0:05:44.793 Fourier transform it. Right?'Cuz Cuz what[br]this is, is the derivative of the it's the 0:05:44.793,0:05:50.926 Fourier transform of the first derivative.[br]So what I can do is just say, okay, if I 0:05:50.926,0:05:57.362 want the first derivative, let's call it[br]my ud s for spectral approximations, first 0:05:57.362,0:06:03.495 derivative is spectral is ifft. By the way[br]that's how you invert a Fourier transform, 0:06:03.495,0:06:12.405 ifft and fft are the pairs. Okay? And by[br]the way, the second derivative, let's call 0:06:12.405,0:06:21.620 it ud2s is equal to ifft of i times k.[br]That being squared now, times ut. There 0:06:20.920,0:06:29.817 you go. I, I want to call this u, right?[br]So I'm kind of done. So, let's make some 0:06:29.817,0:06:38.401 plots. I'm going to plot here the function[br]and for short here I'm going to say, call 0:06:38.401,0:06:46.600 it ks for k shift will be the fftshift(k)[br]and so that way I can make this be just, 0:06:47.540,0:06:52.575 first I'm gonna plot the function. And[br]then I'll plot, in addition to the 0:06:52.575,0:06:58.587 function, I'm gonna plot the derivative of[br]the function, so x versus ud. And my 0:06:58.587,0:07:03.923 approximation, let's plot that in a red[br]line and then I'm gonna plot my 0:07:03.923,0:07:16.098 approximation to the derivative uds, and[br]I'll plot that with magenta circles. what 0:07:16.098,0:07:20.857 I'm plotting is here is the exact answer,[br]right there, x, ud, that's the exact 0:07:20.857,0:07:27.262 answer and I'm plotting my approximation[br]to the exact answer. Oh, that's just the 0:07:27.262,0:07:30.978 original function. We don't have to have[br]that in there. Would you like to take it 0:07:30.978,0:07:36.301 away? We can just do that. What's that? Oh[br]that was the fft, yeah we don't want the 0:07:36.301,0:07:41.323 fft of the original function. We just want[br]the function. Oh, by the way. There you 0:07:41.323,0:07:45.732 go, look at that. The red line is exact,[br]the magenta line is my approximation. Who 0:07:45.732,0:07:49.805 likes that approximation? Give it up you[br]all. Okay. So listen, I know it's the 0:07:49.805,0:07:54.440 first day of class, we're just warming up.[br]We'll have a dance party about midway. We 0:07:54.440,0:07:59.051 can get disco balls and you know, we can[br]shine that light on there. It's pretty 0:07:59.051,0:08:03.433 sweet. Okay. Alright so there is my[br]approximation. By the way, let's zoom in a 0:08:03.433,0:08:07.816 little bit. Let's just see how well we[br]really did. Let's see how long it takes 0:08:07.816,0:08:12.255 for that magenta ball to fall off. Oh, oh,[br]oh, oh, come on, fall off. I'm zooming in, 0:08:12.255,0:08:16.695 I'm zooming in, I'm zooming in. Look, it's[br]pretty dang accurate. Look at that. Oh, 0:08:16.695,0:08:21.248 it's finally coming off there. I know it,[br]I can sense it. Oh, look at that. But look 0:08:21.248,0:08:25.708 over here on the left, it's like down to[br]ten minus five or negative six. Pretty 0:08:25.708,0:08:30.190 amazing accuracy. Now, you can screw up.[br]Let me just show you one other thing. 0:08:30.190,0:08:37.507 Suppose I take a smaller domain. Oh, not[br]quite hold on a little smaller just real 0:08:37.507,0:08:45.004 quick. Just give me two seconds for the[br]final. Oh, crap. Okay. Come on. Let's do 0:08:45.004,0:08:50.177 four. wanna, I wanna, I wanna show you[br]what happens when you kind of start to 0:08:50.177,0:08:55.338 violate, yeah, there you go, you start[br]seeing it. Now, notice what happens here? 0:08:55.338,0:09:00.143 Here, remember it's supposed to be a two[br]pie periodic function. Right? This is 0:09:00.143,0:09:04.884 clearly not periodic. Before they both[br]went to zero, you could say kinda looks 0:09:04.884,0:09:10.006 periodic. Here, it's up here above point[br]two here. It's below negative point two. 0:09:10.006,0:09:15.123 There's a jump and any time you have a[br]jump in a Fourier transform, when you try 0:09:15.123,0:09:19.255 to represent, you get what's called a[br]Gibbs' phenomenon, which is oscillations 0:09:19.255,0:09:23.911 near the jump and this is what you see[br]over here. So it does amazingly well here 0:09:23.911,0:09:28.450 and over here it starts to oscillate, not[br]so well. Okay. We're gonna use this on 0:09:28.450,0:09:34.876 Friday to do radar problems. Okay. Ha ve a[br]good Wednesday. See you guys soon.