/* --------------------------------------------------------------------- // Figure 9.23: Temperature along a cooling fin. // Figure 9.22: Fin program: the compute_temp function. // --------------------------------------------------------------------- */ #include "tools.h" void print_table ( float N, float FinC, float WallTm, float AirTm ); float compute_temp( float x, float N, float FinC, float WallTm, float AirTm ); void main( void ) { float len; /* Length of the cooling fin, in meters. */ const float FinC = 26.5; /* Fin constant. */ const float WallTm = 500.0; /* Wall temperature, degrees C. */ const float AirTm = 20.0; /* Air temperature, degrees C. */ banner(); puts( " Temperature Along a Rectangular Cooling Fin" ); printf( " Please enter the length of the fin (m): " ); scanf( "%g", &len ); print_table( len, FinC, WallTm, AirTm ); bye(); } /* ------------------------------------------------------------------ ** Print a table of temperatures for a fin that is N meters long. ** N must be greater than 0. */ void print_table ( float N, float FinC, float WallTm, float AirTm ) { float x; /* Current distance from wall. */ float temp; /* Temperature at distance x from wall. */ const float step = .005; /* Step size for loop. */ const float epsilon = step/2.0; /* For floating comparison to end loop. */ printf( "\n Distance from base (m) Temperature (C) \n" " ---------------------- --------------- \n" ); for (x = 0.0; x < N + epsilon; x += step) { temp = compute_temp( x, N, FinC, WallTm, AirTm ); printf( "%12.3f %24.1f \n", x, temp ); } printf( " ---------------------- --------------- \n" ); } /* ------------------------------------------------------------------ ** Compute and return the temperature at distance x from the wall. ** x must be between 0.0 meters and the length of the fin. */ float compute_temp( float x, float N, float FinC, float WallTm, float AirTm ) { return AirTm + (WallTm - AirTm) * cosh( FinC*(N-x) ) / cosh( FinC*N ); }