 Welcome to dealing with materials data, in this course we are going to be talking about the collection, analysis and interpretation of materials data. We have started learning R and we are familiarizing ourselves with R as a calculator and plotter and we are going to continue in this session also to use R as a calculator and plotter for couple of more problems. These are very simple problems which you might have done in very early stages in any degree in material science and engineering or metallurgy. And so I am going to show how to do some of these calculations using R. The first problem that we want to do using R is this, interplanar distances between planes in a crystal can be calculated using x-ray diffraction data and we are considering an x-ray diffraction experiment on aluminum and 1.54 angstrom is the wavelength of the x-ray used to probe this aluminum crystal. And let us say that we know that the reflections from two zero zero planes are observed at a Bragg angle of 22.4 degrees. We know the Bragg's law so 2D sin theta is n lambda and we are going to use n to be 1 where lambda is the wavelength of the x-ray, theta is the Bragg angle. But remember this is sin theta so this value should go as radian and not as 22.4 degree and D is what we are trying to calculate that is the interplanar distance between the two zero zero planes. What is the distance? So that is D. So that is obtained and we are going to use n is equal to 1. What does that mean? That means that higher order reflection superpose on lower order ones for the parallel planes. So this is known as crystallograph as Bragg's law so we are going to use that so the answer is very simple. So it is just a simple calculation so we are going to use R as a calculator. So we want to calculate D which is nothing but lambda by 2 sin theta. So let us do that and for doing that let me also open my notes. So we are going to do this. So first thing is you can write a comment. So let us write the script. So you can write a comment say and you can write another comment it was 1.54 angstroms okay and D is the interspacing so we want to get D is equal to. Now notice when we are writing it as a script there is nothing that appears in the environment that is because we are not in the interpretation mode. So there are 2 modes in which you can work with R. One is the interpretation mode where you just keep giving commands and looking at the results. The other one is the scripting mode where we put all the commands that we want R to execute in one place and then we just call R to execute that right. So we are in the scripting mode. So lambda divided by 2 times sin we already know that sin theta is what theta but remember theta should be in radians. So we are going to multiply it by pi divided by 180 right. So we are going to save this in the scripts as aluminum interplane R. So let us run this script okay let me also add this command okay. So when I source it now you can see that D is 2.02 angstroms obviously because this is 2.00 so if you look at the aluminum lattice parameter which is like 4.04 angstroms. So we are getting the right answer and so you can run the script by sourcing it okay. So and once you source it you can see that the values of D lambda theta etc which we have entered here or available here. You also notice that there are 2 ways of giving parameters or attributing values to parameters. One is using this angular bracket with a dash the other one is equal to. So you can replace actually all attributions like this. Let us see if this works save then source of course it works right. And you also notice that for pi I just used to pi and it works okay. So help pi will tell you that there are constants this is a built-in constant there are lots of other built-in constants also that are available in R. So this is the first problem. So let us go to the next problem. So the next problem that we want to solve is as follows okay. Let us consider the composition in a binary alloy given by the variable XB and that is a mole fraction of the B atoms. Let us assume that we are considering an ideal solution that is random distribution of A and B atoms on the lattice. Then you can calculate the change in configurational entropy when mixing happens of the AB atoms on the lattice and that is given by the change in entropy delta S as R XB log XB plus 1 minus XB log 1 minus XB. This is natural logarithm R is a universal gas constant and we want to plot delta S as a function of XB. So that is what we want to do okay. So let us go back and write another script for that okay new file I want to get an R script. So what is the R script I want to get? So first we want to define XB and it is a sequence. So it goes from 0 to 1 because this is a composition and let us say that it changes by 0, 1 and del S so before that I need to get R so let us say R is equal to 8.314 okay and del S is nothing but R into X to log of X underscore B plus 1 minus X underscore B into log of 1 minus X underscore B. I want to know if this is correct and so this completes and this completes okay. Now I want to know what is this log so help log will give you so it is a log computes logarithms and by default natural logarithm. So we know if we want base 10 we have to use base 10 and here you can see log X you can give what is the base by default it is basis exponential and you can give other base for example it is possible to say log 10 base equal to 10 right or log 2 base equal to 10. The point to note is that in this case for example I cannot say base and then the other symbol right this is not allowed when you are giving values for argument variables that has to be done by equal to sign but assigning values to variables like here for example those can be done by this symbol okay so and typically the advice is to assign values using this and use equal to only in such scenarios in any case so help file is useful so we know that log is the natural logarithm so what we have written is okay and our aim is to plot X B and the change in entropy so let us source this yes now you have this nice curve of course I want to you know make it more refined let us say we plot every 0.001 okay much more better curve let us make it still better or let us say that I make it 1 e power minus 5 right source yes. So as you can see as you are going to leaner and leaner compositions you find that this curve is sort of going with infinite slope towards 0 so it is approaching parallel to y axis the y axis of course I can also give one more but that computation is going to take some time so it is going to be a bit slow but let us do it anyway so you can see this small red symbol that is the stop symbol it is just a way of r to tell you that it is doing the computations and once that disappears that means it has completed the calculation okay and why does the curves for the change in entropy go towards 0 and 1 in both cases in both because this curve is symmetric about 0.5 it goes with infinite slope that is because the configurational entropy contribution can be very large if you have very lean solutions very few atoms and very large number of sites that are available so the number of configurations are very large in number so lean solutions always contribute a lot towards entropy and that is why lean solutions are typically also behave like ideal solutions okay. So let us take this script again and source and so it is a nice code so we can save it we can save as configurational entropy change dot r so we can use it for future. So this is another example of plotting so what is the purpose of this exercise okay so let us go and look at. So the first point to note is that there are more than one way to do things for example variable assignment can be done using the less than and dash symbol or using equal to you can print values to the console just by printing the variable name or saying print explicitly or if you want to get information about functions there is more than one way I did not show that let me show so you can also use this command called arg okay. So it says that it is a function and it takes x and base is the exponential so there are two arguments that you can give for log one is the x for which you are computing the function and the base of the logarithm that you want to compute. So there are more than one way of getting information about the function so help is one and args is another so there are many many different ways and comments are marked in the script using the hash symbol that you saw sometimes it is very useful to mark these comments for somebody else who is going to look at your script and or also no symbols like pi so that is the point of this exercise. So we have seen that R can be quite powerful calculator and plotter so and we are going to see more examples of this because much of the analysis descriptive analysis of data can be done in terms of plotting and that is also very useful to understand the information for us. So we are going to see more and more examples of this and this is one of the strengths of R that it can give you good visualization tools for looking at data. So we are going to look at this aspect more in the modules that follow. Thank you.