WEBVTT

00:00:09.140 --> 00:00:10.190
PROFESSOR: Hello.

00:00:10.190 --> 00:00:13.120
I'm Ian Hutchinson, and the
purpose of this short video

00:00:13.120 --> 00:00:17.950
is to give you illustration
of how to use Octave.

00:00:17.950 --> 00:00:20.940
I'm certainly not an
expert at [? Octave, ?]

00:00:20.940 --> 00:00:25.400
which is an open source
equivalent of MATLAB,

00:00:25.400 --> 00:00:28.840
but that's part of
the demonstration.

00:00:28.840 --> 00:00:31.940
Here's someone who's
not an expert who

00:00:31.940 --> 00:00:37.600
can use this routine
for carrying out

00:00:37.600 --> 00:00:42.180
the kinds of exercises
that we want to do.

00:00:42.180 --> 00:00:44.770
So I'm going to delete my
picture from the screen

00:00:44.770 --> 00:00:49.412
now, and just show you
the rest of the screen.

00:00:49.412 --> 00:00:51.850
Here I am in a directory.

00:00:51.850 --> 00:00:58.000
I'm going to start a new file.

00:00:58.000 --> 00:01:00.560
It's going to be called fitting.

00:01:00.560 --> 00:01:06.510
Let's say, fitting.m,
is the correct extension

00:01:06.510 --> 00:01:09.300
for a MATLAB or Octave file.

00:01:09.300 --> 00:01:13.100
And I've opened Emax, and
I'm ready to get started.

00:01:13.100 --> 00:01:15.870
Actually, I'm going to
run Octave simultaneously

00:01:15.870 --> 00:01:17.060
in the adjacent window.

00:01:19.680 --> 00:01:21.670
I run Octave here.

00:01:21.670 --> 00:01:24.040
So now I'm in a situation
where I, essentially,

00:01:24.040 --> 00:01:28.430
have my own IDE, integrated
development environment.

00:01:28.430 --> 00:01:30.090
It's not quite the
same as you would

00:01:30.090 --> 00:01:32.240
have if you're
running MATLAB itself,

00:01:32.240 --> 00:01:35.350
but it's pretty similar.

00:01:35.350 --> 00:01:40.530
What I'm going to do now is
develop this fitting program.

00:01:40.530 --> 00:01:45.937
I'm going to start
with some parameters.

00:01:45.937 --> 00:01:47.520
Let's, first of all,
define the number

00:01:47.520 --> 00:01:49.140
of points I'm going to fit.

00:01:49.140 --> 00:01:53.370
Let's make it a small number,
so that it's kind of manageable.

00:01:53.370 --> 00:01:58.630
And now, let's generate
some x and y values.

00:01:58.630 --> 00:02:04.740
I can set x to be
equal to an array.

00:02:04.740 --> 00:02:10.220
It might be an array
with six points.

00:02:10.220 --> 00:02:16.590
And I'm going to make it
be run from 1 to endpoints.

00:02:16.590 --> 00:02:20.640
And so I do that by saying
x is equal to 1 colon

00:02:20.640 --> 00:02:23.480
endpoints like this.

00:02:23.480 --> 00:02:26.200
I can save this file--
it's called fitting--

00:02:26.200 --> 00:02:31.900
and then I can run it in
Octave by just typing fitting.

00:02:31.900 --> 00:02:34.570
If I do that, what
you see happens is,

00:02:34.570 --> 00:02:36.560
it tells me that endpoints is 6.

00:02:36.560 --> 00:02:41.790
Tells me that x is
1, 2, 3, 4, 5, and 6.

00:02:41.790 --> 00:02:47.260
Actually, I don't want
it to run from 1 to 6.

00:02:47.260 --> 00:02:50.880
I want it to run
from, essentially,

00:02:50.880 --> 00:02:52.290
a small value up to 1.

00:02:52.290 --> 00:02:56.250
So let's divide
it by end points.

00:02:56.250 --> 00:03:00.460
And I can save that file
again, run it again,

00:03:00.460 --> 00:03:03.860
and now, of course,
my screen shows

00:03:03.860 --> 00:03:08.650
that it runs from 1/6 up to 1.

00:03:08.650 --> 00:03:13.380
This is, of course,
a row vector.

00:03:13.380 --> 00:03:16.630
It's preferable that I
have a column vector.

00:03:16.630 --> 00:03:21.550
I can transform a row
vector into a column vector

00:03:21.550 --> 00:03:23.660
by taking its transpose.

00:03:23.660 --> 00:03:28.220
In MATLAB or Octave,
transpose is prime.

00:03:28.220 --> 00:03:34.500
So I can say,
transpose the numbers 1

00:03:34.500 --> 00:03:39.760
through 6 into a column vector
and then divide by endpoints.

00:03:39.760 --> 00:03:43.240
And if I do that
and save the file,

00:03:43.240 --> 00:03:49.770
then I see I've turned
it into a column vector.

00:03:49.770 --> 00:03:55.190
Let me now make a y variable.

00:03:55.190 --> 00:04:01.380
y, I'm going to make
equal to x, let's say.

00:04:01.380 --> 00:04:04.050
That would just give
me a straight line,

00:04:04.050 --> 00:04:07.140
if I made it nothing but x.

00:04:07.140 --> 00:04:12.000
Then I'll add to it
some small fraction--

00:04:12.000 --> 00:04:20.170
let's say, 1/10th-- not 0.1
times the sine of, let us say,

00:04:20.170 --> 00:04:24.980
10 x.

00:04:24.980 --> 00:04:26.740
I can save that file.

00:04:26.740 --> 00:04:28.310
I can run it again.

00:04:28.310 --> 00:04:34.060
And it tells me,
here's x and here's y.

00:04:34.060 --> 00:04:36.870
That's given me a start.

00:04:36.870 --> 00:04:39.350
Actually, it's a
bit inconvenient

00:04:39.350 --> 00:04:41.700
to see it in quite those terms.

00:04:41.700 --> 00:04:44.170
So let's actually
try to plot it.

00:04:44.170 --> 00:04:50.470
So I can say plot x y.

00:04:50.470 --> 00:04:52.510
Save that and run it.

00:04:52.510 --> 00:04:56.546
And lo and behold,
it brings up a plot.

00:04:56.546 --> 00:04:58.740
The labeling is
rather too small,

00:04:58.740 --> 00:05:02.070
but that's kind of built
into the rather poor graphics

00:05:02.070 --> 00:05:05.360
in Octave and MATLAB,
for that matter.

00:05:05.360 --> 00:05:08.280
That can be fixed in ways
that I'll go into later,

00:05:08.280 --> 00:05:10.390
but we won't worry about it now.

00:05:10.390 --> 00:05:13.700
This is a line plot, which
is a little bit annoying.

00:05:13.700 --> 00:05:15.770
So let's change that plot.

00:05:15.770 --> 00:05:17.820
I'll put the figure over here.

00:05:17.820 --> 00:05:20.430
I'll change that
plot by telling it

00:05:20.430 --> 00:05:23.180
that it's going to have
points, and those points

00:05:23.180 --> 00:05:27.910
are going to have the
form of a plus sign.

00:05:27.910 --> 00:05:30.680
So let's save that
and run it again.

00:05:30.680 --> 00:05:33.740
And Lo and behold, it's changed
it to a plot with points.

00:05:33.740 --> 00:05:39.290
Again, the markers are
rather unpleasantly small.

00:05:39.290 --> 00:05:45.550
I can actually change that
if I want by telling it

00:05:45.550 --> 00:05:47.065
a string marker size.

00:05:51.810 --> 00:05:57.120
Making that size larger than
it would be-- let's say, 20--

00:05:57.120 --> 00:05:58.170
and running it again.

00:05:58.170 --> 00:06:01.910
And lo and behold,
the points are bigger.

00:06:01.910 --> 00:06:06.830
So we've started, and
we've made, some data.

00:06:06.830 --> 00:06:09.350
And we've used parameters.

00:06:09.350 --> 00:06:13.930
And in our next
video, we'll move on

00:06:13.930 --> 00:06:18.560
to finding out how to
proceed on that basis.