In: Computer Science
From thermal physics, as objects absorb energy, their physical dimensions expand. This phenomenon is known as thermal expansion. Write a Python program that calculates the change in length of the following elements: silicon, cadmium, lead, gold, iron, and mercury. Assume that the temperature ranges from 273 K to 373 K. Write a program that defines a function to calculate the change in length at each increment in temperature. Increment the temperature by a step size of 1 K for all calculations. Plot the change in length versus the change in temperature for all metals.
Please answer using Jupyter notebook in python 3
Solution:
Change in length expression given as
Where
is change in length ,
is Thermal expension Coefficient
is change in temperature
values not same for different metals
values in micro meter ()for above metals in below table
Silicon | 5.6 |
cadmium | 30 |
lead | 29 |
gold | 24 |
iron | 12 |
mercury | 61 |
#importing matplotlib for plot of graph
import matplotlib.pyplot as plt
#name1=['silicon','cadmium','lead','gold','iron','mercury']#input("Enter name of metrial ")
#Thermal Expansion Coefficients in micro meter [5.6,30,29,24,12,30] of respective list element of name1
def changel(name,l):
list=[]
for i in name:
if i=="silicon":
#cl=alpha*l* change in temperature
cl=5.6*l*100
list.append(cl)
elif i=="cadmium":
cl=30*l*100
list.append(cl)
elif i=="lead":
cl=29*l*100
list.append(cl)
elif i=="gold":
cl=24*l*100
list.append(cl)
elif i=="iron":
cl=12*l*100
list.append(cl)
elif i=="mercury":
cl=61*l*100
list.append(cl)
return list
name1=['silicon','cadmium','lead','gold','iron','mercury']
leng=int(input("enter length of material in meter "))
list1= changel(name1,leng) #call function changel()
res = "\n".join("{} {}".format(x, y) for x, y in zip(name1, list1))
print('change in length in micrometer')
print('-------------------------')
print(res)
#importing matplotlib for plot of graph
#import matplotlib.pyplot as plt
plt.plot(list1,'g*', 100, 'ro') #change in temperatur is 100
plt.show() #plot is change in length for all metal as y and change in temperature as x axis
above is code implementation for given problem statement as temparature change 273k to 373k that will be taken here 100. and length values is also taking as user input and name is list type for storing different metals name since values is different for each other. also plot of change in length with temperature is ploted here temperature change is 100 { we can include many values of change in temperature}
Output1.
The above image is ouput of above code implementation for length value L =200 meter
and showing the change in length for different metals with from above mention table and change in temperature is 100.
Output2.
The above image is details about output for above implented code for taking length value of metal from user as 400 meter
and corresponding change in length calculated values shown and also plot of change in length with change in temperature.
change in temperature is shown with red color and change in length is with green color in the plot.