Right, so this is a lecture on practicing for the peer review assessment of week three.

In the peer review assessment at week three, you will be fitting data by

changing the parameters on a function.

So the function in this case is a circle,

and the data or corrupted data from an original circle, so we know that that data

can be fitted by a circle.

And the only point is to try and get the circle with an adjustable radius and center,

so that it fits the given data as best we can.

So we start by making a parametric plot.

The circle will have a given radius

and a position, and those are the things that we can actually change.

And so we adjust our plotted circle by hand until it fits the data set.

Ok, so the first thing then is to

plot a circle with an adjustable radius.

So what we'll do is we'll make a function, and the function

will plot the circle with radius r

and with center x-naught, y-naught.

We'll be using plots.

We use parametric plotting but just using the plot command as you see here.

There is a way of doing parametric plotting

directly in plots, but we won't go into that.

If you're interested, you can read up.

So the idea of a parametric plot is like you follow this the

curve as if it is being traced out in time by the tip of your pencil.

So you need something that plays the role of time, and we will use t,

but t will go from zero to two pi, which is the radians in a full circle,

and we will be using

the cos of t and the sine of t, so it will be just be r cos t

sine cos t - as t goes from zero to two pi, we do the whole circle.

Ok, so that in this function trialcircle with radius r,

x and y component of the center, we run that so

if we set up, we get a generic function with one method,

and if we now try it out,

we see that we have a circle - not such a great circle but it's there.

Let's just try this out a little bit.

We want to make more than one circle on top of another.

So what we want to do is to

do something like plot bang where we modify the plot, we keep the

old plot, and we add something new and we want trialcircle bang.

So you have to write a new function called trialcircle bang, which uses plot bang.

And, if we do that, we've set up our function and now we can try two

that have both the origin as their center zero zero,

but the radius of one and a radius of two,

and again we see we don't like too much having all these grid lines.

We don't like too much

having, all these, the legend and all that, but before we take a look at all of that,

let's see how we can do many concentric circles.

Now we use the center zero for all the circles.

The value r starts at 0.1 And in steps of 0.1 Goes to four.

And if we plot

all of those circles, it takes a while longer of course

because we are doing a lot of circles, we get this interesting plot.

So, we don't like the plot circle and the grid, nor

do we like the fact that it doesn't actually look like a circle.

We have from minus four to four here and from minus four to four there, but we

see that this minus four to four is actually a lot longer than this minus four to four.

So what we do is we just say aspect underscore

ratio equals one, and when we do that, we get this lovely set of circles here.

So we can now, instead of concentric circles - all of them with the same center, we

can make the center of a radius r at the x value r.

So all of the circles will go to the origin and will be tangential at the origin

to give us this lovely picture.

Now what we actually really want to do

is to get the data,

and the data in this case consists of comma separated values in a file called

Practice Data dot CSV.

We will pretend we don't know exactly what the format is and we'll

try and work out the format by looking at using type of and size.

So the first thing is to read it as a comma delimited file.

So the comma delimitation goes

in single quote marks with a comma, because it's a character, whereas

Practice Data dot CSV is a string - it's the name of the file - and that's why it's

in double quotes.

So, the type of the data

is an array with two dimensions but that doesn't inform us very much.

We know it's kind of like an array with rows and columns

but if we actually do this, we see that there are two rows and 100 columns.

So we are thinking x, y data, so the first row will be

say the x data and the second row will be say the y data.

So, now,

we read in target x and target y, and look at

how we do this - it's target x comma target y,

it's target one comma target two

and target one is comma colon because it's

all of the data in row one and that's all of the data in row two.

All of the data in row one, go to target x, all of the data in row 2, go

to target y, and we get this.

We plot it as scatter, so that we can

see the individual points and we don't get distracted by the

lines that may join them.

And we can see, yes roughly, it looks circular but it's obviously a very coarse circle.

Now we want to superimpose a circle on that.

So let's see minus two and six for the x and minus six and two for the y.

So the middle of minus two and six is at two

and the middle of minus six and two is at minus two.

So that's our x, y coordinate for the center,

and from two to six is a distance of four, so that's our radius.

So we try our trialcircle as center two, minus two with a radius four.

Of course first we put scatter, and then we bang the trialcircle on top of it.

And if we do that,

we see that oh, well, it's not such a bad circle, but

actually it's not that great, is it?

It's not quite in the right place and maybe the radius isn't exactly the same either.

So let's see, we don't need any new code, we can just go here and adjust this.

So we need to shift it left a bit.

So let's shift it to 0.1, but this

blue line through here is probably in more or less the right place, so the center should

also shift to the left slightly to keep this, in fact it should shift

left by the same amount, so let's make that 1.9.

And it's slightly too low, so we must make this a bit negative.

So let's make this 1.9 As well and see what we get.

Well, it's still a little bit too far over,

so we can make this 4.2, and we can make this 1.8.

And now, we see that,

the radius seems pretty good, but it should shift left a little bit more.

Let's shift it left to 0.7, so we can compare it now and see.

Now it becomes a fine adjustment.

If we shift it up slightly, we would gain dots over here.

There's quite a lot of dots on the edge that would go on the inside,

and we would lose probably fewer dots, so let's lift it up a little bit

and see what happens.

We can shift it up to 1.8.

And I wonder if we shouldn't shift it left slightly as well.

Let's shift it left to 1.65 very slightly.

It's beginning to be difficult to tell.

So let's just look at this criterion of stopping.

We could go on and on and you could

wonder, you could actually really carefully start counting

all of the dots on the outside, the dots that are half

on the inside, half on the outside, they are just

touching, but it becomes very difficult to tell.

And basically you have to stop at some point.

I'm going to stop now because I think it's very difficult to tell now for me whether it's

better to make the circles slightly larger, slightly

smaller, slightly higher, slightly lower, slightly left, slightly right.

It seems as if it's

close to the best possible and I don't really know

whether I can make it a lot better by spending a lot of time on it.

So this is a quite subjective thing to do, but the

point to notice is that stopping criteria for optimization are difficult.

They have to be set

to some extent subjectively, to some extent based on experience,

but they are an art, they're a subjective thing, and that's

unavoidable in numerical analysis.

And so there's no reason for us to avoid it here.

So we say that the best values we get by hand are approximately this and we stop there.

That solves the problem from the point of view of the

peer review assessment, and that's the end of this lecture.

Thank you