Professional Documents
Culture Documents
Let us try and solve a simple set of non-linear equations, which are tedious to solve by
hand.
Enter the two equations given above and then see them in formatted equations as well.
Solve them and see how many blocks were created. You know the answer already if you
have understood blocking.
Let us try and solve a complex equation using Functions. You must remember this one, as
we have practiced this in our last class
Function f_Darcy(Re,RR)
f=8*((8/Re)^12+((2.457*ln(1/((7/Re)^0.9+0.27*(RR))))^16+(37530/Re)
^16)^(-1.5))^(1/12)
f_Darcy=f
end
If you have done everything right, the output should look like this:
EXAMPLE - 3
Another simple equation using Functions. This time, try and solve the equation by yourself
first.
Function PR(v,T)
R = 188.9 [J/kg-K]
a = 70.89 [N-m^4/kg^2]
b = 0.0006059 [m^3/kg]
PR = R*T/(v-b)-a/(v*(v+b)+b*(v-b))
End
Another simple conditioning using Procedure. Try and practice the formatting without seeing
as well.
Call Test(X, Y: Product, Ratio, 88, 32) "Alternative call to the Test
Procedure"
EXAMPLE - 5
The following example develops a function named Nusselt which uses logic to provide the
appropriate value of the nondimensional Nusselt number for fully-developed flow in a
circular pipe subjected to a constant heat flux given the Reynolds number (Re), Prandtl
number (Pr), and the relative roughness (RR). The function uses correlations presented in
Nellis and Klein (2009). For laminar flow (Re < 2300), the Nusselt number is a constant,
Nu = 4.36.
The function begins by assigning Nusselt a value consistent with laminar flow and the using
the Return statement to return to the main program if Re < 2300.
For turbulent flow (Re > 2300), the friction factor is computed according to:
and used to compute the Nusselt number according to the Gnielinski correlation:
Note that the Gnielinski correlation is only valid for 2300 < Re < 5x106. The function
continues by using the above equations to assign Nusselt a value that is consistent with
turbulent flow. The Return statement is used to return to the calling program if the
Reynolds number is less than 5x106.
Finally, the function returns a value of -9 when the Reynolds number provided is greater
than 5x106 in order to indicate that the correlation is not valid.
"Reynolds number must be out of range"
Nusselt = -9 [-] "value if Re is out of range"
end
The function is tested at various Reynolds numbers:
After solution:
EXAMPLE - 6
Function Fact(N)
F:=1 "factorial"
i:=0 "counter"
10: i:=i+1 "increment counter"
F:=F*i "multiply factorial by counter"
If (i<N) Then GoTo 10 "see if counter has reached N"
Fact:=F "assign factorial"
End
Y= Fact(7) "Fact(7)=5040"
Y2=Factorial(7) "EES built-in factorial function"
Function Fact(N)
Fact:=1 "factorial"
If (N=0) then Return "check for N=0"
Repeat
Fact:=Fact*N "start with argument"
N:=N-1; "decrement argument by one"
Until (N<=1)
End
EXAMPLE - 7
For extending the limit on N from above 100, we can use the following example.
Furthermore, we can see how to define array table window for Functions. We can use this
for numerical differentiation.
The following example computes the temperature of an object that is initially at T ini and is
subjected to convection and radiation from an environment at T∞. The surface area of the
object is As and the total heat capacity is C. The convective heat transfer coefficient is h
and the object is assumed to have an emissivity of ε = 1. Assuming that the object is at a
uniform temperature, the time rate of change of its temperature is given by:
x3.5 – 4.5x2 + 3x = 25
First, solve by hand using these relations, basically the Newton’s method:
Again, solve by hand first, and then solve that logic by using EES.
Now, try two equations, using the same Newton’s method, but by building a Jacobian
matrix.
The final solution should look like this. Do this one on your own. You can solve them
directly, but try and solve by hand first. Then code it in EES as shown in the class.