Question: Comupute the temperature vs time in Python code The following code has errors which will not allow to continue : def RK45(h,x0,n): if (x0 <59):

Comupute the temperature vs time in Python code

The following code has errors which will not allow to continue:

def RK45(h,x0,n):

if (x0<59):

W=4320000# [J/s]

xk1=f(x0)

xk2=f(x0+0.5*xk1*h)

xk3=f(x0+0.5*xk2*h)

xk4=f(x0+xk3*h)

xn=x0+(h/6.0)*(xk1+2.0*xk2+2.0*xk3+xk4)

elif (x0>61):

W=0

xk1=f(x0)

xk2=f(x0+0.5*xk1*h)

xk3=f(x0+0.5*xk2*h)

xk4=f(x0+xk3*h)

xn=x0+(h/6.0)*(xk1+2.0*xk2+2.0*xk3+xk4)

xk1=f(x0)

xk2=f(x0+0.5*xk1*h)

xk3=f(x0+0.5*xk2*h)

xk4=f(x0+xk3*h)

xn=x0+(h/6.0)*(xk1+2.0*xk2+2.0*xk3+xk4)

def f(x):

cp=4186.0

ro=1.0

U=12558.0

S=1.20

tin=17.0

ta=20.0

V=80.0

if (t>=0.0 and t<=7.0):

Q=0.0

elif(t>7.0 and t<=9.0):

Q=70.0

elif(t>9.0 and t<=14.0):

Q=40.0

elif(t>14.0 and t<=15.0):

Q=30.0

elif(t>15.0 and t<=19.0):

Q=10.0

elif(t>19.0 and t<=20.0):

Q=50.0

elif(t>20.0 and t<=24.0):

Q=10.0

f=(Q/V)*(tin-x)-(U*S*(x-ta))/(V*ro*cp)+W/(V*ro*cp)

h=0.001

n=24

n1=int(n/h)

x0=60

t=0

W=0

for i in range (0,n1):

RK45(h,x0,n)

x0=xn;

t=t+h;

print("time:\t",t,"Temperature:\t",xn)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!