Lecture 03

IIT Kanpur July 201
20 followers
Oct 23, 2023
Previously we have discussed about the course policy and also we have talked
about what are the topics we are going to cover in this week. Now let us start
our course from this lecture by taking up an example from which we will try to
understand that what are these things which we call numerical methods. So let
us say for some reason we wish to evaluate an integral that is I which
goes from the limit a to b and it integrates this function u which is a
function of x. Now how can we evaluate this integral? You already know several
techniques for evaluating integral in different mathematics courses. So what
are they in a nutshell? So the solution of this problem is such that we have to
first find a function that will be v that is a function of x and this v
function should be such that its derivative with respect to x will be
equal to u. If we can find such a function v then the integral I which is
given above will be equal to this v at x equals b minus v at x equals a. Now this
technique is something that we are already familiar with but let us see
that is this technique an easy technique to begin with. Actually it is not. First
of all this technique is not suitable for everybody. Everybody cannot do
integrals. You hopefully remember some of the integrals that take very long time
to evaluate and sometimes we can't even evaluate. So such integrals are not
possible for every ux. It's not possible given every function you will find its
anti-derivative or given every u you will find a v such that dv dx will be u.
It's not possible for every function to find this way. The second question is
that can you teach this above technique to a kid? Here I'm using this kid in a
sense that can you teach this above technique who is not an expert in
mathematics or an expert in calculus. So can you teach this to someone who knows
only very basic arithmetic? It is probably not true. You cannot do so.
Someone with a very elementary knowledge of arithmetic only cannot solve for this
integral. So in a sense that it requires certain expertise. This technique here
that we are using before you actually learn this using in your high school you
have already learned several very important concepts which are like
functions, limit, continuity, derivative etc etc and these concepts you have
learned only probably within a span of few months but these concepts if you
think about it humankind had developed these concepts over hundreds of years of
deep research. So you have learned that deep research within few months and then
you are able to evaluate the integral and then you cannot do this integral for
every function. So this is not an easy process if you think about it. This
requires quite a bit of expertise and this process is only thus suitable for
trained person and only suitable for certain particular function u not for
all functions u. Here I want to emphasize this point that we cannot teach this to
a kid. This is important point. This tells us that this can only be done with some
expertise. You cannot outsource this job who doesn't have that kind of expertise.
So one of the basic idea of numerical methods is that to devise a method where
anybody who has very basic very elementary knowledge can solve such
problem. So let us see how we can do so. So we want that some persons with little
mathematics knowledge will solve it but how they will solve it. So let's see one
option here. Let us take a board. Let us say that this is our blackboard and
within that blackboard I have drawn this function ux. So this blue line is my ux
and now I have taken chewing gums. Of course these are large number of chewing
gums and I have taken a group of kids and asked them to chew the chewing gum
and throw the gums to the blackboard randomly. The only condition that it
should go on this board and not outside the board. So this is just a game now.
There is no mathematics involved. This is just a simple game. So we carry on and we
throw these gums over here. All the gums are same. The gums that are coming within
this area ux I have given them blue color and gums that are coming outside
this area but within the blackboard of course I have given them green color and
we continue doing this for a very large number of gums. Once we do so at the end
we count all the gums in and out of the drawn area which means all this blue and
this green gums we count all of them. Once we count then this n number of gums
that are coming inside divided by total number of gums. This ratio is the
fraction of area that is total area by the area under the curve which means
that this I which is the area under this curve between this A and B will be equal
to number of gums inside number of gums total multiplied by this area of the
blackboard that is the total area and as I already said that inside gums are blue
and total gums are of course this blue plus the green gums which are outside
the area. So now you can see that anybody with counting skill can now find the
integral. So all you need is that the area of the blackboard which can be
supplied but after we know the area of the blackboard you identify a person who
can only count and do this experiment. After this experiment the person can
count n inside and n total. This is simply a counting exercise and this n
inside by n total multiplied by a blackboard that is what it is that is the
area so what you need is counting a division and a multiplication and even
if you do the division and a multiplication and you ask someone who
cannot even do the division and multiplication to count it then the
integral can be evaluated like that. So this is the technique of finding an
integral and this comes under the umbrella of numerical method. This is a
very exciting technique and this looks very trivial but this kind of technique
has large number of applications. Of course this counting how many gums you
need you need a very large number of gums of course otherwise you will not
get a reasonable answer. So counting large number of gums will be a very
tedious task. It would be easy but it would be tedious. So anybody with
counting skill can find the integral but in practice will hand over the task
to a machine that is a computer. So let us say that we want to evaluate this
function 0 to pi sine x dx. This is a very simple integral and we can see the
analytical solution of this will be 2. You can find this analytical. This is a
very simple integral and you will see that it will be 2. But using this
counting method if we want to do it how we'll do it. Well you can actually run an
experiment. This is an experimental mathematics basically what we are
talking about. So you can actually run an experiment but we run this experiment
in a computer. So what you see here within this black border is a Python
program for the technique that I have just described. Here I have taken
100,000 of gums. So this many trials I have taken. This is a large number of trials.
This may not be necessary to take so many but I have just taken a failsafe
number of trial very large number of gums and then I'm throwing them on the
board and here in Python we'll talk more about Python later but here what we are
trying to do here is actually in this program we are generating two random
numbers or what we call a pseudo random numbers. So first random number is X
which is coming within 0 to pi. So within this interval between 0 to pi so
this will give me the X value randomly and then the Y is a random number
generated between 0 to 1. So this is the sine X value because between 0 to pi sine
X will be between 0 to 1 so it is giving a sine X value. So between this 0 to 1 I
can now have the complete blackboard. This XY will be the location of the gum
over the blackboard and FX is the location of this function. So this is my
blackboard and this is the function FX is the function XY is giving locations
of this gum. Some of these gums will fall inside the function so for wherever it
is falling inside the function so if my Y location is less than or equal to this
FX, FX indicates this line of sine function so if it is within this sine
function then I count that so I start from J equals 0 and then whenever a
gums fall within the sine function I count it. At the end I have counted
everything my total number of gums are n and the number of gums that are coming
inside a J so this J by n ratio multiplied by this area this area will
be this is 0 to 1 and this is 0 to pi so the area is pi that is the area of
blackboard and in Python we call that math dot pi and math I am writing just
in short form as empty I don't want to write every time math math so I am
writing empty so this empty dot pi multiplied by J by n this should give me
the integral. Now this is the analytical solution of the integral which is 2
here and this is a complete computer code actually you can write it on a
computer and run in a Python interpreter if you do so you will see the program
will give you an output of 2.00006 now you will say that well I have done so
much of work but it is not giving me an exact solution there is a 6 here hanging
here well that is something we have to live with because now we have reduced
the integration problem to a counting problem we have to live with some
inaccuracies and that is inherent in numerical methods so numerical results
are never almost never exact always there will be some inaccuracies so the
goal in this course as you will learn is that not to make this error to be 0 we
cannot make this error 0 that is impossible to make this error 0 in
general sometimes you may get a result that would be matching with the
analytical solution but you cannot do that all the time so the goal in
numerical methods is not to get an error-free solution but to come up to an
acceptable results in general these results are repeatable if I run this
code I hope that I will get the same result but in this particular case we
will not get that because of the stochasticity of the problems so
stochasticity means that this problem is probabilistic if I carry out this
experiment different times I'll get a different result because not all the
time I'll get exactly the same number of gums inside and outside my curve and
that is something we call stochasticity so there is some inherent randomness in
this particular process not necessarily in all kinds of numerical methods I am
only talking about this kind of numerical methods which are probabilistic
in nature so if the method we are using is probabilistic in nature then we may
not have exactly repeatable solution if you run this code different times the
computer program will generate different random numbers and we will get a
slightly different number but theory of probability tells us that our number
will be very close to 2 and you can try it yourself you will see that you will
get a close to 2 numbers also if we change number of trials that is n which
in our case these are the number of gums where all we are doing is that we are
trying to find integral here experimentally so how we conduct the
experiment this number of gums we are using in our experiment if we vary it
we'll see slight changes here not much we'll see slight changes if n is very
few let us say you take n equals 10 then you will get a very inaccurate
result as you increase the number of n you will see that you will come closer
and closer to 2 why it is so well that what theory of probability tells us that
is of course not for us to discuss in this course but if you are interested you
can open up a book of statistics and probability and you will see that why is
it so so this is a very interesting technique of evaluating integral this
looks like a child's play but it has lots of applications now to close this
discussion we have just now learned our first numerical methods and we have
actually applied it for a problem we have got the results in very few lines
of program and this problem is about evaluating an integral and we have also
seen that how to implement this in a computer there is no problem if you
don't understand this implementation now we'll talk more about it later but if
you already know something about computer programming you can try it by
yourself we have also learned one important lesson that numerical methods
always it will contain some error and our goal is to keep the error within
acceptable limit we are never going to get exact results the procedure what we
have seen here the way we have deduced the integral this comes under a bigger
umbrella which we call Monte Carlo method Monte Carlo method is this kind
of stochastic method that is used in many applications for example
applications of radiation heat transfer we use it this is a very successful
method and also there is a rich history behind this Monte Carlo school of
methods if you are interested you can go online and see it that how why this
interesting name of Monte Carlo came and what are other things we can do with
Monte Carlo methods for your exercise you can modify this computer program and
try to evaluate x square sine x dx instead of sine x dx and see that if you
are getting the right result you can actually have an analytical solution of
this also and see that if your numerical solution is matching with the
analytical solution if you do not know computer programming at all you can
skip this exercise but I'll urge you to still do this analytical solution well
so that's all for this lecture I'll see you in next class thank you
