 Welcome, this is the course on dealing with materials data, we are going to discuss the collection analysis and interpretation and we are using R to do this data analysis. In this section we are going to use R as a calculator and plotter. So we are going to use R for understanding data, how to plot data and how to interpret data and so on and so forth. But before we do all that I just want to show you that R can be used simply as a calculator and plotter. So we will take some specific examples from simple material science and engineering and try to use R to do some calculations and plotting. So like I mentioned earlier R is an interpreted language and so you can use it exactly like a calculator, you type in some computation and you will immediately get the answer. And so here are a couple of examples that I want to do, homologous temperature is a concept. So it is a temperature of a material as a fraction of its melting temperature and homologous temperature is a fraction of the temperature of material as a fraction of its melting temperature in Kelvin. So if you know the melting temperature of a material in Kelvin and then any temperature of interest if you keep that material what homologous temperature that corresponds to. Basically what we are saying is that homologous temperature is a way of normalizing for the melting temperatures. So otherwise it becomes difficult to interpret results for example and it is very funny. For example if you take ice if you are at minus 1 degree Celsius where you might think that it is very cold but for ice it is very high temperature, low temperature for ice might be minus 20 or minus 40 or something like that. So we want to get rid of this dependence on where the melting temperature is. So in Kelvin scale everything is positive and we are going to say the given temperature divided by the melting temperature of the material then you can compare different materials. For example if homologous temperature is 0.5 for 2 different materials then both of them are at a temperature which is 50% of their respective melting temperatures. So this concept is very useful. So let us say that we want to calculate the homologous temperature. Let us consider aluminum which has a melting temperature of 660 degree Celsius and lead which has a melting temperature of 327 degree Celsius. And let us say both of them are at room temperature and let us assume that the room temperature is 30 degree Celsius. What are the homologous temperatures of aluminum and lead? So this is what we want to do like I said we have the nodes. So this is the nodes and the nodes gives you all these commands but I am also going to type it so that you can work with me. Let us say that temperature of melting for aluminum is equal to 650. Temperature of melting for lead is equal to 327. So you might see in my notes that I have this colon so this is a habit from writing scripts in octave but it is not essential. So you do not have to put the columns and the room temperature and so we need to transform all these temperatures which are in degree Celsius to Kelvin. So I am going to add a 273 to them. So T0 is 273 and I am going to call this room temperature that is 30 and so let us calculate the homologous temperature for aluminum which is nothing but oh okay before that room temperature in Kelvin is nothing but room temperature plus T0 right okay. Now the homologous temperature for aluminum is nothing but so melting temperature of aluminum and we need to convert it into Kelvin and melting temperature the homologous temperature for lead is the same thing. So I can actually do this I can use the up key to get the previous command and modify it right so it just needs these two modifications. So homologous temperature of lead is nothing but room temperature in Kelvin divided by the melting temperature of lead in Kelvin. So now you want to know what is the homologous temperature of aluminum it is 0.33 right and what is lead assuming that we are at room temperature and room temperature is 30 for aluminum it is 0.33 and for lead we are already above 0.5 right and that is what is shown here also okay. Now suppose you want to calculate the temperature which is 0.5 homologous for aluminum well it is rather simple so you multiply by the so 461.5 right so that is the homologous temperature for aluminum 0.5 homologous temperature for aluminum. So this is the first example so we are just using it like a calculator except that it is a more advanced calculator in the sense that you are giving variable names and you can deal with these variable names and whenever you want the answer you can just ask for the computer or to give you the values and it will give you those values. The second problem okay so I said that it is both calculator and plotter so let us take another problem okay this is a problem on diffusivity. Diffusivity of materials is typically given in terms of the pre-exponential constant D0 and the activation energy Q. If these quantities are given the and if you know the temperature in Kelvin at any temperature the diffusivity is D0 exponential minus Q by RT or is the universal gas constant which is 8.314 kilojoule per mole per Kelvin we are assuming that this Q is given per mole but if it is given paratom this will just become KBT okay where KB is the Boltzmann constant 1.38 in 10 power minus 27 joule Kelvin okay. So this is the diffusivity and so typically values of D0 and Q are tabulated and then for any temperature then you can calculate diffusivity. Let us take a particular system so this is copper this is for self diffusion of copper that is copper diffusing in copper itself. The D0 is known to be 10 power minus 4 meter square per second and Q is 196 kilojoule and so let us say we want to calculate the diffusivity at 400 degree Celsius and also plot the diffusivity as a function of temperature from 200 to 600 degree C. So we want to do two things one is that given these values you can calculate diffusivity so this is just a continuation of the previous problem you can use R as a calculator you can just put these values and then evaluate the value at 400 so you will get that and you can also plot diffusivity because we said R can also be a plotter plotting means we have to have table we have to have temperature from 200 to 600 and for each temperature corresponding to 200 for example 250 for example 300 for example and so on you also have to get the diffusivity once you have this table of temperature versus diffusivity then you can plot it as usual. So that is what we want to do next and so here is my nodes so this is the diffusivity problem so let us start doing it so and this problem I want to do in the R studio because then it is easy to see the plots. So what do we want to do we know that D0 is nothing but and Q is given to be 196 remember this is kilojoule so I am going to make it joule by multiplying power 3 and then R is 8.314 so we wanted to calculate D at 400 but remember we need to turn it into Kelvin because temperature is in Kelvin so D is nothing but D0 into exponential so this is another advantage with R studio so we did not know whether there is a command called exp but you know it is there and if you go there it even gives you the information log computes logarithms by default natural logarithms and so on. So you have the information about exponential so this is on minus Q by RT into T is 400 we wanted to calculate and T0 so I do not know if it is visible to you but if I take the cursor here it highlights here if I take the next one it highlights here and if I take next one it highlights here so all the parenthesis are complete so you can calculate and as you can see you know the values what are the variables we have defined and what their values are so even without printing D here I can already see that it is 6.1 10 power minus 20 so it is already come but of course you can just say D and then it will give you that answer but R studio environment is nice because as you are doing you can see what is happening. Now we want to plot right for plotting we want to get the temperatures from 200 to 600 so I am going to do let us say temperature and we want to increase let us say 10 degrees right. Now capital T we want which is nothing but this T plus T0 so as you can see T is temperature 210 to 220 etc and then capital T already made it into Kelvin 473 483 493 etc. Once we have it so we can calculate D which is nothing but D0 into exponential minus Q by RT right and so let us calculate D so it is available so the D values are given now what do we do we say plot T versus D and here is a plot. So you can see that the diffusivity of course it exponentially increases with increasing temperature because it is minus 1 by T so as you can see that 400 to 800 473 to 873 Kelvin 200 to 600 degree Celsius the self-diffusivity of copper this is how it looks so by so it is similar here and I think there is a mistake in this we will correct it Q should be in kilojoules so of course the next thing that you want to do let us say that I want to write a small script and what is the script is going to be so I am going to say D0 equal to 1 e power minus 4 Q is equal to 196 kilojoules and R is equal to 8.314 and then we can repeat the rest of the commands exactly as here T0 is equal to 273 and T is equal to 200 to 610 and capital T now you see when I type capital T it highlights in a different color that is because for true and false there are logical values so the T is already true and false are represented by T and F so I cannot use capital T so I am going to say T in K T in K is nothing but T plus T0 okay now we can say the diffusivity is nothing but T0 into exponential see that is the other nice thing if I open a parenthesis it closes a parenthesis by itself by R into T in kelvin okay so we have calculated then we want to say plot T comma D okay so now I am going to save this file save as and I am going to save it in scripts and let us call it as couple diffusivity dot R yeah replace okay now I can run this right this is a script I can run this I will get the plot there is also another way which is to so suppose I want to run it in the R console so I do not have this right so go to reverse this I have to look at materials data scripts so you have to give the full path but the nice thing is if you know the first few letters and then press on tab it completes it autocomplete so you do not have to type the entire name of the directory for example so if you do let us go to this what the error is okay yeah I should not have yes so we are able to get this and so you can also use the script and use the command source to run it I just want to show this clarification when we were running this cu diffusivity dot R we did get an error message and we glossed it over I just want to show you how that error comes about and how to fix it my cursor is on this line D is D0 exponential minus Q by R and the temperature in Kelvin so if I just say run as you can see it means run the current line or selection so if I have selected something then it would run the selection or if the cursor just stays there it will just run that line so if I now say run it says the error object D0 not found that is because we are just trying to execute this line and it does not know what the parameters are D0 for example it does not know or T in K it does not know things like that so to avoid that you can say source and if you say source then it sources everything which means from the first line it goes through so you can see that the plotting is done so this is something that we have noticed and when I was going back and forth between the R console and R studio and sometimes when I was trying to execute instead of source I used run and because run meant just that line it gave that error on the other hand you can mask everything and then say run and then it will execute it or you can just say source and then it will execute it so either way it can be done this is just to show you some of you might have been wondering what is that error message and why it came about so this is the reason it comes about so when you the source and run are close to each other so when you do you have to be careful as to what you are doing or if you notice the error message then you know that you have been using run instead of source and so it is just running one line instead of running the entire script so this is just to explain why you saw some strange error messages in the session. Thank you.