In [29]:

```
#intiation of all variables
# Chapter 4
print"Example 4.1, Page:113 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 1")
print("NOTE=>This question is fully theoritical hence cannot be solve using scilab.")
```

In [30]:

```
#cal of heat supplied
#intiation of all variables
# Chapter 4
print"Example 4.2, Page:114 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 2")
T1=(400.+273.);#temperature of source in K
T2=(15.+273.);#temperature of sink in K
W=200.;#work done in KJ
print("in carnot engine from thermodynamics temperature scale")
print("Q1/Q2=T1/T2")
print("W=Q1-Q2=200 KJ")
print("from above equations Q1 in KJ is given by")
Q1=(200*T1)/(T1-T2)
print("Q1="),round(Q1,2)
print("and Q2 in KJ")
Q2=Q1-200
print("Q2=Q1-200"),round(Q2,2)
print("so heat supplied(Q1) in KJ"),round(Q1,1)
```

In [31]:

```
#cal of power required for driving refrigerator
#intiation of all variables
# Chapter 4
print"Example 4.3, Page:115 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 3")
T1=315.;#temperature of reservoir 1 in K
T2=277.;#temperature of reservoir 2 in K
Q2=2.;#heat extracted in KJ/s
print("from thermodynamic temperature scale")
print("Q1/Q2=T1/T2")
Q1=Q2*(T1/T2)
print("so Q1=Q2*(T1/T2)in KJ/s"),round(Q1,2)
print("power/work input required(W)=Q1-Q2 in KJ/s ")
W=Q1-Q2
print("power required for driving refrigerator=W in KW"),round(W,3)
```

In [32]:

```
#cal of heat transferred to refrigerant and low temperature reservoir
#intiation of all variables
# Chapter 4
print"Example 4.4, Page:115 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 4")
T1=(827.+273.);#temperature of high temperature reservoir in K
T2=(27.+273.);#temperature of low temperature reservoir in K
T3=(-13.+273.);#temperature of reservoir 3 in K
Q1=2000.;#heat ejected by reservoir 1 in KJ
print("we can writefor heat engine,Q1/Q2=T1/T2")
Q2=Q1*(T2/T1)
print("so Q2=Q1*(T2/T1) in KJ"),round(Q2,2)
We=Q1-Q2
print("so We=in KJ"),round(We,2)
print("for refrigerator,Q3/Q4=T3/T4 eq 1")
T4=T2;#temperature of low temperature reservoir in K
print("now We-Wr=300")
Wr=We-300.
print("so Wr=We-300 in KJ"),round(Wr,2)
print("and Wr=Q4-Q3=1154.55 KJ eq 2 ")
print("solving eq1 and eq 2 we get")
Q4=(1154.55*T4)/(T4-T3)
print("Q4=in KJ"),round(Q4,2)
Q3=Q4-Wr
print("and Q3=in KJ"),round(Q3,2)
Q=Q2+Q4
print("total heat transferred to low teperature reservoir(Q)=in KJ"),round(Q,2)
print("hence heat transferred to refrigerant=Q3 in KJ"),round(Q3,2)
print("and heat transferred to low temperature reservoir=Q in KJ"),round(Q,2)
```

In [33]:

```
#cal of minimum power required
#intiation of all variables
# Chapter 4
print"Example 4.5, Page:116 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 5")
T1=(25+273.15);#temperature of inside of house in K
T2=(-1+273.15);#outside temperature in K
Q1=125;#heating load in MJ/Hr
print("COP_HP=Q1/W=Q1/(Q1-Q2)=1/(1-(Q2/Q1))")
print("also we know K=Q1/Q2=T1/T2")
K=T1/T2
print("so K=T1/T2"),round(K,2)
COP_HP=1/(1-(1/K))
print("so COP_HP=1/(1-(Q2/Q1)=1/(1-(1/K))"),round(COP_HP)
print("also COP_HP=Q1/W")
W=Q1/COP_HP
W=1000*W/3600
print("W=Q1/COin MJ/Hr"),round(W,2)
print("or W=1000*W/3600 in KW"),round(W,2)
print("so minimum power required(W)in KW "),round(W,2)
```

In [34]:

```
#cal of power required
#intiation of all variables
# Chapter 4
print"Example 4.6, Page:117 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 6")
T1=(-15.+273.15);#inside temperature in K
T2=(35.+273.);#atmospheric temperature in K
Q2=40.;#refrigeration capacity of storage plant in tonnes
print("cold storage plant can be considered as refrigerator operating between given temperatures limits")
print("capacity of plant=heat to be extracted=Q2 in KW")
print("we know that,one ton of refrigeration as 3.52 KW ")
Q2=Q2*3.52
print("so Q2=Q2*3.52 in KW"),round(Q2,2)
COP_carnot=1/((T2/T1)-1)
print("carnot COP of plant(COP_carnot)="),round(COP_carnot,2)
print("performance is 1/4 of its carnot COP")
COP=COP_carnot/4
print("COP=COP_carnot/4")
print("also actual COP=Q2/W")
print("W=Q2/COP in KW")
W=Q2/COP
print("hence power required(W)in KW"),round(W,2)
```

In [35]:

```
#cal of carnot cycle efficiency for given temperature limits
#intiation of all variables
# Chapter 4
print"Example 4.7, Page:117 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 7")
T1=(1150.+273.);#temperature of source in K
T2=(27.+273.);#temperature of sink in K
print("highest efficiency is that of carnot engine,so let us find the carnot cycle efficiency for given temperature limits")
n=1-(T2/T1)
print("n="),round(n,2)
n=n*100
print("or n=n*100 %"),round(n,2)
```

In [36]:

```
#cal of power required
#intiation of all variables
# Chapter 4
print"Example 4.8, Page:117 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 8")
T1=(27.+273.);#temperature of source in K
T2=(-8.+273.);#temperature of sink in K
Q=7.5;#heat leakage in KJ/min
Q=Q/60.
print("here heat to be removed continuously from refrigerated space(Q)in KJ/s"),round(Q,2)
print("for refrigerated,COP shall be Q/W=1/((T1/T2)-1)")
W=Q*((T1/T2)-1)
print("W=in KW"),round(W,2)
print("so power required(W)in KW"),round(W,2)
```

In [37]:

```
#cal of intermediate temperatures
#intiation of all variables
# Chapter 4
print"Example 4.9, Page:118 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 9")
T1=1100;#temperature of high temperature reservoir in K
T4=300;#temperature of low temperature reservoir in K
print("here W1:W2:W3=3:2:1")
print("efficiency of engine,HE1,")
print("W1/Q1=(1-(T2/1100))")
print("so Q1=(1100*W1)/(1100-T2)")
print("for HE2 engine,W2/Q2=(1-(T3/T2))")
print("for HE3 engine,W3/Q3=(1-(300/T3))")
print("from energy balance on engine,HE1")
print("Q1=W1+Q2=>Q2=Q1-W1")
print("above gives,Q1=(((1100*W1)/(1100-T2))-W1)=W1*(T2/(1100-T2))")
print("substituting Q2 in efficiency of HE2")
print("W2/(W1*(T2/(1100-T2)))=1-(T3/T2)")
print("W2/W1=(T2/(1100-T2))*(T2-T3)/T2=((T2-T3)/(1100-T2))")
print("2/3=(T2-T3)/(1100-T2)")
print("2200-2*T2=3*T2-3*T3")
print("5*T2-3*T3=2200")
print("now energy balance on engine HE2 gives,Q2=W2+Q3")
print("substituting in efficiency of HE2,")
print("W2/(W2+Q3)=(T2-T3)/T2")
print("W2*T2=(W2+Q3)*(T2-T3)")
print("Q3=(W2*T3)/(T2-T3)")
print("substituting Q3 in efficiency of HE3,")
print("W3/((W2*T3)/(T2-T3))=(T3-300)/T3")
print("W3/W2=(T3/(T2-T3))*(T3-300)/T3")
print("1/2=(T3-300)/(T2-T3)")
print("3*T3-T2=600")
print("solving equations of T2 and T3,")
T3=(600.+(2200./5.))/(3.-(3./5.))
print("we get,T3=in K"),round(T3,2)
T2=(2200.+3.*T3)/5.
print("and by eq 5,T2 in K"),round(T2,2)
print("so intermediate temperature are 700 K and 433.33 K")
```

In [38]:

```
#cal of COP
#intiation of all variables
# Chapter 4
print"Example 4.10, Page:119 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 10")
T1=800.;#temperature of source in K
T2=280.;#temperature of sink in K
print("efficiency of engine,W/Q1=(800-T)/800")
print("for refrigerator,COP=Q3/W=280/(T-280)")
print("it is given that Q1=Q3=Q")
print("so,from engine,W/Q=(800-T)/800")
print("from refrigerator,Q/W=280/(T-280)")
print("from above two(Q/W)may be equated,")
print("(T-280)/280=(800-T)/800")
T=2.*280.*800./(800.+280.)
print("so temperature(T)in K"),round(T,2)
print("efficiency of engine(n)is given as")
n=(800.-T)/800.
print("n="),round(n,2)
print("COP of refrigerator is given as")
COP=280./(T-280.)
print("COP="),round(COP,2)
```

In [39]:

```
#cal of max and min temp of cycle,volume
#intiation of all variables
# Chapter 4
import math
print"Example 4.11, Page:120 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 11")
n_carnot=0.5;#efficiency of carnot power cycle
m=0.5;#mass of air in kg
p2=7.*10**5;#final pressure in pa
v2=0.12;#volume in m^3
R=287.;#gas constant in J/kg K
Q_23=40.*1000.;#heat transfer to the air during isothermal expansion in J
Cp=1.008;#specific heat at constant pressure in KJ/kg K
Cv=0.721;#specific heat at constant volume in KJ/kg K
print("let thermodynamic properties be denoted with respect to salient states;")
print("n_carnot=1-T1/T2")
print("so T1/T2=1-0.5")
1-0.5
print("so T1/T2=0.5")
print("or T2=2*T1")
print("corresponding to state 2,p2*v2=m*R*T2")
T2=p2*v2/(m*R)
print("so temperature(T2) in K="),round(T2,2)
print("heat transferred during process 2-3(isothermal expansion),Q_23=40 KJ")
print("Q_23=W_23=p2*v2*log(v3/v2)")
v3=v2*math.exp(Q_23/(p2*v2))
print("so volume(v3) in m^3="),round(v3,4)
T1=T2/2
print("temperature at state 1,T1 in K="),round(T1,2)
print("during process 1-2,T2/T1=(p2/p1)^((y-1)/y)")
print("here expansion constant(y)=Cp/Cv")
y=Cp/Cv
print("so pressure(p1)=p2/(T2/T1)^(y/(y-1)) in pa")
p1=p2/(T2/T1)**(y/(y-1))
print("p1 in bar")
p1=p1/10**5
print("thus p1*v1=m*R*T1")
v1=m*R*T1/(p1*10**5)
print("so volume(v1) in m^3="),round(v1,2)
print("heat transferred during process 4-1(isothermal compression)shall be equal to the heat transferred during process2-3(isothermal expansion).")
print("for isentropic process,dQ=0,dW=dU")
print("during process 1-2,isentropic process,W_12=-m*Cv*(T2-T1)in KJ")
print("Q_12=0,")
W_12=-m*Cv*(T2-T1)
print("W_12=-105.51 KJ(-ve work)")
print("during process 3-4,isentropic process,W_34=-m*Cv*(T4-T3)in KJ")
print("Q_31=0,")
T4=T1;
T3=T2;
W_34=-m*Cv*(T4-T3)
print("ANS:")
print("W_34=+105.51 KJ(+ve work)")
print("so for process 1-2,heat transfer=0,work interaction=-105.51 KJ")
print("for process 2-3,heat transfer=40 KJ,work intercation=40 KJ")
print("for process 3-4,heat transfer=0,work interaction=+105.51 KJ")
print("for process 4-1,heat transfer=-40 KJ,work interaction=-40 KJ")
print("maximum temperature of cycle=585.36 KJ")
print("minimum temperature of cycle=292.68 KJ")
print("volume at the end of isothermal expansion=0.1932 m^3")
```

In [40]:

```
#cal of heat from from heat engine and to heat engine
#intiation of all variables
# Chapter 4
print"Example 4.12, Page:122 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 12")
W=840.;#work done by reservoir in KJ
print("let us assume that heat engine rejects Q2 and Q3 heat to reservior at 300 K and 200 K respectively.let us assume that there are two heat engines operating between 400 K and 300 K temperature reservoirs and between 400 K and 200 K temperature reservoirs.let each heat engine receive Q1_a and Q1_b from reservoir at 400 K as shown below")
print("thus,Q1_a+Q1_b=Q1=5*10^3 KJ...............eq1")
print("Also,Q1_a/Q2=400/300,or Q1_a=4*Q2/3...............eq2")
print("Q1_b/Q3=400/200 or Q1_b=2*Q3...............eq3")
print("substituting Q1_a and Q1_b in eq 1")
print("4*Q2/3+2*Q3=5000...............eq4")
print("also from total work output,Q1_a+Q1_b-Q2-Q3=W")
print("5000-Q2-Q3=840")
print("so Q2+Q3=5000-840=4160")
print("Q3=4160-Q2")
print("sunstituting Q3 in eq 4")
print("4*Q2/3+2*(4160-Q2)=5000")
Q2=(5000.-2.*4160.)/((4./3.)-2.)
print("so Q2=in KJ"),round(Q2,2)
Q3=4160.-Q2
print("and Q3= in KJ"),round(-Q3,2)
print("here negative sign with Q3 shows that the assumed direction of heat is not correct and actually Q3 heat will flow from reservoir to engine.actual sign of heat transfers and magnitudes are as under:")
print("Q2=4980 KJ,from heat engine")
print("Q3=820 KJ,to heat engine")
```

In [41]:

```
#cal of energy taken by engine from reservoir
#intiation of all variables
# Chapter 4
print"Example 4.13, Page:123 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 13")
T2=(77+273);#temperature of reservoir 2
T1=(1077+273);#temperature of reservoir 1
T3=(3+273);#temperature of reservoir 3
print("arrangement for heat pump and heat engine operating togrther is shown here.engine and pump both reject heat to reservoir at 77 degree celcius(350 K)")
print("for heat engine")
print("ne=W/Q1=1-T2/T1")
print("so (Q1-Q2)/Q1=")
1-T2/T1
print("and Q2/Q1=")
1-0.7407
print("Q2=0.2593*Q1")
print("for heat pump,")
print("COP_HP=Q4/(Q4-Q3)=T4/(T4-T3)")
T4=T2;
T4/(T4-T3)
print("Q4/Q3=")
4.73/3.73
print("Q4=1.27*Q3")
print("work output from engine =work input to pump")
print("Q1-Q2=Q4-Q3=>Q1-0.2593*Q1=Q4-Q4/1.27")
print("so Q4/Q1=")
(1-0.2593)/(1-(1/1.27))
print("so Q4=3.484*Q1")
print("also it is given that Q2+Q4=100")
print("subtituting Q2 and Q4 as function of Q1 in following expression,")
print("Q2+Q4=100")
print("so 0.2539*Q1+3.484*Q1=100")
print("so energy taken by engine from reservoir at 1077 degree celcius(Q1)in KJ")
Q1=100/(0.2539+3.484)
print("Q1=100/(0.2539+3.484)in KJ"),round(Q1,2)
print("NOTE=>In this question expression for calculating Q1 is written wrong in book which is corrected above.")
```

In [42]:

```
#cal of T_sink in degree celcius
#intiation of all variables
# Chapter 4
print"Example 4.14, Page:124 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 14")
Q_source=2000;#heat supplied by heat engine in KJ/s
T_source=1500;#temperature of source in K
T_R=(15+273);#temperature of reservoir in K
Q_sink=3000;#heat received by sink in KJ/s
print("let temperature of sink be T_sink K")
print("Q_sink_HE+Q_sink_R=3000 ........eq 1")
print("since complete work output from engine is used to run refrigerator so,")
print("2000-Q_sink_HE=Q_sink_R-Q_R .........eq 2")
Q_R=3000-2000
print("by eq 1 and eq 2,we get Q_R in KJ/s"),round(Q_R)
print("also for heat engine,2000/1500=Q_sink_HE/T_sink")
print("=>Q_sink_HE=4*T_sink/3")
print("for refrigerator,Q_R/288=Q_sink_R/T_sink=>Q_sink_R=1000*T_sink/288")
print("substituting Q_sink_HE and Q_sink_R values")
print("4*T_sink/3+1000*T_sink/288=3000")
print("so temperature of sink(T_sink)in K")
T_sink=3000/((4/3)+(1000/288))
print("so T_sink="),round(T_sink,2)
T_sink=T_sink-273
print("T_sink in degree celcius"),round(T_sink,2)
```

In [45]:

```
#cal of heat transferred to refrigerant and low temperature reservoir
#intiation of all variables
# Chapter 4
print"Example 4.15, Page:124 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 15")
T1=(500.+273.);#temperature of source in K
T2=(200.+273.);#temperature of sink in K
T3=(450.+273.);#temperature of body in K
print("let the output of heat engine be W.so W/3 is consumed for driving auxiliary and remaining 2*W/3 is consumed for driving heat pump for heat engine,")
n=1-(T2/T1)
print("n=W/Q1="),round(n,2)
print("so n=W/Q1=0.3881")
COP=T3/(T3-T2)
print("COP of heat pump=T3/(T3-T2)=Q3/(2*W/3)"),round(COP,2)
print("so 2.892=3*Q3/2*W")
print("Q3/Q1="),round(2*COP*n/3,4)
print("so ratio of heat rejected to body at 450 degree celcius to the heat supplied by the reservoir=0.7482")
```

In [48]:

```
#intiation of all variables
# Chapter 4
print"Example 4.16, Page:125 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 16")
print("NOTE=>In question no. 16,condition for minimum surface area for a given work output is determine which cannot be solve using python software.")
```

In [47]:

```
#intiation of all variables
# Chapter 4
print"Example 4.17, Page:126 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 4 Example 17")
print("NOTE=>In question no. 17 expression for (minimum theoretical ratio of heat supplied from source to heat absorbed from cold body) is derived which cannot be solve using python software.")
```

In [ ]:

```
```