Professional Documents
Culture Documents
1801ME07 1801ME14
The objective is to programme the equations for heating and cooling parts with all custom functions.
The error function is custom made, by using Horner’s Method. The non-integrable function has been
expressed as a series of terms inside an exponential function, as shown below:
def erf(z):
t = 1.0 / (1.0 + 0.5 * abs(z))
# using Horner's method
ans = 1 - t * exp(-z*z - 1.26551223 +
t * (1.00002368 +
t * (0.37409196 +
t * (0.09678418 +
t * (-0.18628806 +
t * (0.27886807 +
t * (-1.13520398 +
t * (1.48851587 +
t * (-0.82215223 +
t * (0.17087277))))))))))
if z >= 0.0:
return ans
else:
return -ans
# Custom ierfc
def ierfc(x):
t = (exp(-x*x) - x*(1-erf(x)))/sqrt(pi)
return t
The two heat transfer regimes, namely: heating and cooling have their equations as follows:
res = (2*h/k)*sqrt(alpha) * \
(sqrt(t)*ierfc(inside1) - sqrt(t-tp)*ierfc(inside2))
return res
The equation function is the function which takes in the parameters at each iteration, and first of all
decides the heat transfer regime: heating or cooling based on the value of tp. Then it calls the
heating or the cooling equation depending on the same.
The plot function takes h, k tp and alpha [(𝛼) 𝑖𝑠 𝑤𝑟𝑖𝑡𝑡𝑒𝑛 𝑎𝑠 𝑎𝑙𝑝ℎ𝑎 𝑖𝑛 𝑡ℎ𝑒 𝑐𝑜𝑑𝑒] as arguments, and
using a loop based on t, readies the array x which actually hosts all the used values of t. Now, by
calling equation function, gets the value of 𝛥𝑇(𝑧, 𝑡), which are again, appended to some array(s). For
z = 0, the values of 𝛥𝑇(0, 𝑡) get appended to the array y0, the ones corresponding to z = 0.009 get
appended to the array y1 and the ones for z = 0.02 get appended to the array y2.
The plt.plot lines actually plot the graphs by taking the values of the array x as x coordinate, and the
values of y0, y1, and y2 as the y coordinates, and plots 3 different curves for the three different
values of z.
# ------------------------------------------------------
# Constant Values
# alpha = 1.11 * (10**(-4))
# k = 385
# h = 10**12
tp = 10**(-6)
h = 9708777
k = 398
alpha = 111
# ------------------------------------------------------
def getErf(x):
return erf(x)
def erf(z):
t = 1.0 / (1.0 + 0.5 * abs(z))
# using Horner's method
ans = 1 - t * exp(-z*z - 1.26551223 +
t * (1.00002368 +
t * (0.37409196 +
t * (0.09678418 +
t * (-0.18628806 +
t * (0.27886807 +
t * (-1.13520398 +
t * (1.48851587 +
t * (-0.82215223 +
t *
(0.17087277))))))))))
if z >= 0.0:
return ans
else:
return -ans
# Custom ierfc
def ierfc(x):
Amartya Mondal ME547 Assignment Anway Bhattacharyya
1801ME07 1801ME14
t = (exp(-x*x) - x*(1-erf(x)))/sqrt(pi)
return t
res = (2*h/k)*sqrt(alpha) * \
(sqrt(t)*ierfc(inside1) - sqrt(t-tp)*ierfc(inside2))
return res
# z=0
plot(h, k, tp, alpha)