1 00:00:09,140 --> 00:00:10,190 PROFESSOR: Hello. 2 00:00:10,190 --> 00:00:13,120 I'm Ian Hutchinson, and the purpose of this short video 3 00:00:13,120 --> 00:00:17,950 is to give you illustration of how to use Octave. 4 00:00:17,950 --> 00:00:20,940 I'm certainly not an expert at [? Octave, ?] 5 00:00:20,940 --> 00:00:25,400 which is an open source equivalent of MATLAB, 6 00:00:25,400 --> 00:00:28,840 but that's part of the demonstration. 7 00:00:28,840 --> 00:00:31,940 Here's someone who's not an expert who 8 00:00:31,940 --> 00:00:37,600 can use this routine for carrying out 9 00:00:37,600 --> 00:00:42,180 the kinds of exercises that we want to do. 10 00:00:42,180 --> 00:00:44,770 So I'm going to delete my picture from the screen 11 00:00:44,770 --> 00:00:49,412 now, and just show you the rest of the screen. 12 00:00:49,412 --> 00:00:51,850 Here I am in a directory. 13 00:00:51,850 --> 00:00:58,000 I'm going to start a new file. 14 00:00:58,000 --> 00:01:00,560 It's going to be called fitting. 15 00:01:00,560 --> 00:01:06,510 Let's say, fitting.m, is the correct extension 16 00:01:06,510 --> 00:01:09,300 for a MATLAB or Octave file. 17 00:01:09,300 --> 00:01:13,100 And I've opened Emax, and I'm ready to get started. 18 00:01:13,100 --> 00:01:15,870 Actually, I'm going to run Octave simultaneously 19 00:01:15,870 --> 00:01:17,060 in the adjacent window. 20 00:01:19,680 --> 00:01:21,670 I run Octave here. 21 00:01:21,670 --> 00:01:24,040 So now I'm in a situation where I, essentially, 22 00:01:24,040 --> 00:01:28,430 have my own IDE, integrated development environment. 23 00:01:28,430 --> 00:01:30,090 It's not quite the same as you would 24 00:01:30,090 --> 00:01:32,240 have if you're running MATLAB itself, 25 00:01:32,240 --> 00:01:35,350 but it's pretty similar. 26 00:01:35,350 --> 00:01:40,530 What I'm going to do now is develop this fitting program. 27 00:01:40,530 --> 00:01:45,937 I'm going to start with some parameters. 28 00:01:45,937 --> 00:01:47,520 Let's, first of all, define the number 29 00:01:47,520 --> 00:01:49,140 of points I'm going to fit. 30 00:01:49,140 --> 00:01:53,370 Let's make it a small number, so that it's kind of manageable. 31 00:01:53,370 --> 00:01:58,630 And now, let's generate some x and y values. 32 00:01:58,630 --> 00:02:04,740 I can set x to be equal to an array. 33 00:02:04,740 --> 00:02:10,220 It might be an array with six points. 34 00:02:10,220 --> 00:02:16,590 And I'm going to make it be run from 1 to endpoints. 35 00:02:16,590 --> 00:02:20,640 And so I do that by saying x is equal to 1 colon 36 00:02:20,640 --> 00:02:23,480 endpoints like this. 37 00:02:23,480 --> 00:02:26,200 I can save this file-- it's called fitting-- 38 00:02:26,200 --> 00:02:31,900 and then I can run it in Octave by just typing fitting. 39 00:02:31,900 --> 00:02:34,570 If I do that, what you see happens is, 40 00:02:34,570 --> 00:02:36,560 it tells me that endpoints is 6. 41 00:02:36,560 --> 00:02:41,790 Tells me that x is 1, 2, 3, 4, 5, and 6. 42 00:02:41,790 --> 00:02:47,260 Actually, I don't want it to run from 1 to 6. 43 00:02:47,260 --> 00:02:50,880 I want it to run from, essentially, 44 00:02:50,880 --> 00:02:52,290 a small value up to 1. 45 00:02:52,290 --> 00:02:56,250 So let's divide it by end points. 46 00:02:56,250 --> 00:03:00,460 And I can save that file again, run it again, 47 00:03:00,460 --> 00:03:03,860 and now, of course, my screen shows 48 00:03:03,860 --> 00:03:08,650 that it runs from 1/6 up to 1. 49 00:03:08,650 --> 00:03:13,380 This is, of course, a row vector. 50 00:03:13,380 --> 00:03:16,630 It's preferable that I have a column vector. 51 00:03:16,630 --> 00:03:21,550 I can transform a row vector into a column vector 52 00:03:21,550 --> 00:03:23,660 by taking its transpose. 53 00:03:23,660 --> 00:03:28,220 In MATLAB or Octave, transpose is prime. 54 00:03:28,220 --> 00:03:34,500 So I can say, transpose the numbers 1 55 00:03:34,500 --> 00:03:39,760 through 6 into a column vector and then divide by endpoints. 56 00:03:39,760 --> 00:03:43,240 And if I do that and save the file, 57 00:03:43,240 --> 00:03:49,770 then I see I've turned it into a column vector. 58 00:03:49,770 --> 00:03:55,190 Let me now make a y variable. 59 00:03:55,190 --> 00:04:01,380 y, I'm going to make equal to x, let's say. 60 00:04:01,380 --> 00:04:04,050 That would just give me a straight line, 61 00:04:04,050 --> 00:04:07,140 if I made it nothing but x. 62 00:04:07,140 --> 00:04:12,000 Then I'll add to it some small fraction-- 63 00:04:12,000 --> 00:04:20,170 let's say, 1/10th-- not 0.1 times the sine of, let us say, 64 00:04:20,170 --> 00:04:24,980 10 x. 65 00:04:24,980 --> 00:04:26,740 I can save that file. 66 00:04:26,740 --> 00:04:28,310 I can run it again. 67 00:04:28,310 --> 00:04:34,060 And it tells me, here's x and here's y. 68 00:04:34,060 --> 00:04:36,870 That's given me a start. 69 00:04:36,870 --> 00:04:39,350 Actually, it's a bit inconvenient 70 00:04:39,350 --> 00:04:41,700 to see it in quite those terms. 71 00:04:41,700 --> 00:04:44,170 So let's actually try to plot it. 72 00:04:44,170 --> 00:04:50,470 So I can say plot x y. 73 00:04:50,470 --> 00:04:52,510 Save that and run it. 74 00:04:52,510 --> 00:04:56,546 And lo and behold, it brings up a plot. 75 00:04:56,546 --> 00:04:58,740 The labeling is rather too small, 76 00:04:58,740 --> 00:05:02,070 but that's kind of built into the rather poor graphics 77 00:05:02,070 --> 00:05:05,360 in Octave and MATLAB, for that matter. 78 00:05:05,360 --> 00:05:08,280 That can be fixed in ways that I'll go into later, 79 00:05:08,280 --> 00:05:10,390 but we won't worry about it now. 80 00:05:10,390 --> 00:05:13,700 This is a line plot, which is a little bit annoying. 81 00:05:13,700 --> 00:05:15,770 So let's change that plot. 82 00:05:15,770 --> 00:05:17,820 I'll put the figure over here. 83 00:05:17,820 --> 00:05:20,430 I'll change that plot by telling it 84 00:05:20,430 --> 00:05:23,180 that it's going to have points, and those points 85 00:05:23,180 --> 00:05:27,910 are going to have the form of a plus sign. 86 00:05:27,910 --> 00:05:30,680 So let's save that and run it again. 87 00:05:30,680 --> 00:05:33,740 And Lo and behold, it's changed it to a plot with points. 88 00:05:33,740 --> 00:05:39,290 Again, the markers are rather unpleasantly small. 89 00:05:39,290 --> 00:05:45,550 I can actually change that if I want by telling it 90 00:05:45,550 --> 00:05:47,065 a string marker size. 91 00:05:51,810 --> 00:05:57,120 Making that size larger than it would be-- let's say, 20-- 92 00:05:57,120 --> 00:05:58,170 and running it again. 93 00:05:58,170 --> 00:06:01,910 And lo and behold, the points are bigger. 94 00:06:01,910 --> 00:06:06,830 So we've started, and we've made, some data. 95 00:06:06,830 --> 00:06:09,350 And we've used parameters. 96 00:06:09,350 --> 00:06:13,930 And in our next video, we'll move on 97 00:06:13,930 --> 00:06:18,560 to finding out how to proceed on that basis.