This chapter discusses aspects of heat conduction. The equilibrium heat conduction on a rod. In this chapter, Arrays will be discussed.

Similar documents
Programming in Fortran 90 : 2017/2018

R s s f. m y s. SPH3UW Unit 7.3 Spherical Concave Mirrors Page 1 of 12. Notes

The Codesign Challenge

Mathematics 256 a course in differential equations for engineering students

CMPS 10 Introduction to Computer Science Lecture Notes

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Brave New World Pseudocode Reference

Computer models of motion: Iterative calculations

High level vs Low Level. What is a Computer Program? What does gcc do for you? Program = Instructions + Data. Basic Computer Organization

A Binarization Algorithm specialized on Document Images and Photos

Intro. Iterators. 1. Access

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

Notes on Organizing Java Code: Packages, Visibility, and Scope

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

3D vector computer graphics

Outline. Midterm Review. Declaring Variables. Main Variable Data Types. Symbolic Constants. Arithmetic Operators. Midterm Review March 24, 2014

Analysis of Continuous Beams in General

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

AP PHYSICS B 2008 SCORING GUIDELINES

Overview. CSC 2400: Computer Systems. Pointers in C. Pointers - Variables that hold memory addresses - Using pointers to do call-by-reference in C

AMath 483/583 Lecture 21 May 13, Notes: Notes: Jacobi iteration. Notes: Jacobi with OpenMP coarse grain

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Parallel matrix-vector multiplication

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

Reducing Frame Rate for Object Tracking

Problem Set 3 Solutions

TN348: Openlab Module - Colocalization

K-means and Hierarchical Clustering

Lecture 5: Multilayer Perceptrons

Support Vector Machines

Life Tables (Times) Summary. Sample StatFolio: lifetable times.sgp

Array transposition in CUDA shared memory

Hermite Splines in Lie Groups as Products of Geodesics

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search


A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS

X- Chart Using ANOM Approach

9. BASIC programming: Control and Repetition

REFRACTION. a. To study the refraction of light from plane surfaces. b. To determine the index of refraction for Acrylic and Water.

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

An Optimal Algorithm for Prufer Codes *

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

A Fast Content-Based Multimedia Retrieval Technique Using Compressed Data

Cluster Analysis of Electrical Behavior

Pass by Reference vs. Pass by Value

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

Assembler. Building a Modern Computer From First Principles.

Solutions to Programming Assignment Five Interpolation and Numerical Differentiation

3D Virtual Eyeglass Frames Modeling from Multiple Camera Image Data Based on the GFFD Deformation Method

Math Homotopy Theory Additional notes

Motivation. EE 457 Unit 4. Throughput vs. Latency. Performance Depends on View Point?! Computer System Performance. An individual user wants to:

Steps for Computing the Dissimilarity, Entropy, Herfindahl-Hirschman and. Accessibility (Gravity with Competition) Indices

User Authentication Based On Behavioral Mouse Dynamics Biometrics

Esc101 Lecture 1 st April, 2008 Generating Permutation

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

Circuit Analysis I (ENGR 2405) Chapter 3 Method of Analysis Nodal(KCL) and Mesh(KVL)

Module Management Tool in Software Development Organizations

Wishing you all a Total Quality New Year!

Multiblock method for database generation in finite element programs

A mathematical programming approach to the analysis, design and scheduling of offshore oilfields

Range images. Range image registration. Examples of sampling patterns. Range images and range surfaces

Cell Count Method on a Network with SANET

The Greedy Method. Outline and Reading. Change Money Problem. Greedy Algorithms. Applications of the Greedy Strategy. The Greedy Method Technique

CE 221 Data Structures and Algorithms

Outline. CIS 110: Introduction to Computer Programming. Review: Interactive Sum. More Cumulative Algorithms. Interactive Sum Trace (2)

On Some Entertaining Applications of the Concept of Set in Computer Science Course

An Iterative Solution Approach to Process Plant Layout using Mixed Integer Optimisation

LLVM passes and Intro to Loop Transformation Frameworks

Priority queues and heaps Professors Clark F. Olson and Carol Zander

Improvement of Spatial Resolution Using BlockMatching Based Motion Estimation and Frame. Integration

Type-2 Fuzzy Non-uniform Rational B-spline Model with Type-2 Fuzzy Data

Electrical analysis of light-weight, triangular weave reflector antennas

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

USING GRAPHING SKILLS

Algorithm To Convert A Decimal To A Fraction

y and the total sum of

Setup and Use. Version 3.7 2/1/2014

Subspace clustering. Clustering. Fundamental to all clustering techniques is the choice of distance measure between data points;

A SYSTOLIC APPROACH TO LOOP PARTITIONING AND MAPPING INTO FIXED SIZE DISTRIBUTED MEMORY ARCHITECTURES

MOTION BLUR ESTIMATION AT CORNERS

APPLICATION OF MULTIVARIATE LOSS FUNCTION FOR ASSESSMENT OF THE QUALITY OF TECHNOLOGICAL PROCESS MANAGEMENT

Six-Band HDTV Camera System for Color Reproduction Based on Spectral Information

Analysis on the Workspace of Six-degrees-of-freedom Industrial Robot Based on AutoCAD

Efficient Distributed File System (EDFS)

Setup and Use. For events not using AuctionMaestro Pro. Version /7/2013

Solitary and Traveling Wave Solutions to a Model. of Long Range Diffusion Involving Flux with. Stability Analysis

SENSITIVITY ANALYSIS IN LINEAR PROGRAMMING USING A CALCULATOR

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Design and Analysis of Algorithms

Today s Outline. Sorting: The Big Picture. Why Sort? Selection Sort: Idea. Insertion Sort: Idea. Sorting Chapter 7 in Weiss.

LS-TaSC Version 2.1. Willem Roux Livermore Software Technology Corporation, Livermore, CA, USA. Abstract

LOOP ANALYSIS. The second systematic technique to determine all currents and voltages in a circuit

A New Approach For the Ranking of Fuzzy Sets With Different Heights

Transcription:

1 Heat Flow n a Rod Ths chapter dscusses aspects of heat conducton. The equlbrum heat conducton on a rod. In ths chapter, Arrays wll be dscussed. Arrays provde a mechansm for declarng and accessng several data tems wth only an ndex. Ths smplfes the task of varable namng and data management. If we had to assgn a name to each of the temperatures, t wll provde a very nflexble program and dffcult to mantan. It s desrable to wrte subprograms that accept arrays as arguments, operate on them, and the change be vsble at the pont of call. 1.1 Heat Conducton Ths chapter dscusses aspects of equlbrum heat conducton on a rod. At the molecular level, heat energy s caused by the random moton of molecules. When two objects of dfferent temperatures are n contact, the faster movng atoms of the warmer object vbrate aganst nearby slower movng atoms of the cooler object. Ths causes the atoms of the cooler object to vbrate more rapdly and n turn effect other slower movng atoms. The moton of molecules results n the warmer objects losng energy and declnng n temperature, and the cooler object ganng energy and ncreasng n temperature. Heat always transfers from warmer objects to cooler objects. Ths method of heat transfer s called conducton. The heat energy of a secton of the rod changes n tme only due to heat energy flowng across the edges of the secton of the rod. The conservaton of heat energy states that the rate of change of the heat energy n tme s equal to the heat energy flowng across the boundares per unt tme. Materals that are able to conduct heat are called conductors. Not all materals conduct heat at the same rate. Metals are good conductors because they transfer heat quckly, and ar s a poor conductor because t transfers heat slowly. Materals that conduct heat poorly are called nsulators, and materals that totally prevent heat flow are called perfect nsulators. The coeffcent K of heat conducton ndcates a materal relatve rate of conducton compared to slver. Slver has a coeffcent of heat conducton of 1

1. Heat Flow n a Rod 2 100. The composton of a materal effects ts conducton rate. If a copper rod and an ron rod are joned together end to end, and the ends placed n heat sources, the heat wll conduct through the copper end more quckly than the ron end because copper has a K value of 92, whereas, ron has a K value of 11. The heat energy flowng across the secton s boundares per unt tme s the heat flux φ(x, t). If φ(x, t) > 0 heat s flowng to the rght. Fourer (1768-1830) consdered the above propertes and summarzed them n Fourer s law of heat conducton. T emp(x, t) φ(x, t) = K L Whch states that the heat flux (φ) s proportonal to the temperature dfferences per unt length. The proportonalty constant s the Thermal conductvty K. 1.2 The Model The physcal model s a rod of constant cross sectonal area A. Wthout any loss of generalty orent the rod n the x drecton, from x = 0 to x = L. The left end of the rod s subjected to a lamp at 472Kelvn where as the rght end s embedded n ce at 270Kelvn. 1.2.1 A Secton Model The rod s naturally subdvded n sectons, whch may be of dfferent materal. Conservaton of energy mples the heat flowng out of one secton s the same as that one flowng nto the other secton next to t. φ left A = φ rght A where the heat flux φ secton measures the amount of thermal transfer per unt surface area flowng from ths secton to the secton next t. We can restate the above equaton as: φ left A φ rght A = 0. Whch states that the net change of energy due to heat transfer across the boundary of the sectons s zero. Substtutng Fourer s law nto the conservaton of energy equaton yelds whch s satsfed for each secton boundary. K left T left L left A + K rght T rght L rght A = 0 Replace T left (t) = T sec (t) T w (t) and T rght (t) = T e (t) T sec (t) nto the above equaton to yeld: K left T sec T w L left + K rght T e T sec L rght = 0. Or equvalently, ( K left Kleft T w + K ) rght T sec + K rght T e = 0. L left L left L rght L rght

1. Heat Flow n a Rod 3 We can solve for T c to get: T c = K left L left T w + K rght L rght T e K left L left + K. rght L rght Consder the homogeneous-unform problem. The thermal conductvty s gven by K o, and L rght = L left = L. Thus, T sec = T w + T e. 2 1.3 Method The temperature equlbrum equaton suggest a method of soluton. The equlbrum temperature dstrbuton of the rod can determned by assumng an orgnal dstrbuton and teratng untl the temperature s at equlbrum. Use the known values of T e and T w and use temperature equlbrum equaton to determne T sec. The calculatons are terated untl an equlbrum heat dstrbuton for the rod s obtaned. Consder a subdvson of the rod nto N equal sectons. Then L = N+1. The boundares of each block, the grd ponts, are dentfed by ther coordnate x, = 1,, N + 1 The heat conducton rates are assgned to each subsecton at the half-coordnate locaton, K, = 1,, N. The temperatures T, = 1,, N + 1 are determned at each boundary pont. The boundary condtons specfy T 1 = 472 and T N = 270. The unknowns are the temperatures at the grd ponts: T, = 2,, N. Therefore, the Algorthm consst on: Assume a value for T, = 2,, N compute a new value as follows: T = K 1T 1 + K T +1 K 1 + K, = 2,, N. L In teraton form, we assume we know T (old), = 1, and calculate T (new), = 1,, N for teratng untl convergence to equlbrum. As follows: Algorthm 1 Equlbrum Heat Iteraton: loop whle (t has not converged) Loop on from = 2 to N T (new) T (old) = (old) (old) K 1T +KT 1 +1 K 1+K, = T (new) End Loop on

1. Heat Flow n a Rod 4 end loop Convergence can be tested comparng T (old) temperatures over each teraton and test whether t s below a predetermned tolerance. Let T = T (new) T (old) tolerance. Thus the above Algorthm can be rewrtten as: wth T (new). In other words, we compute the dfference n. Thus we would lke to know f Maxer = max 2 N T T ol where tol s a prescrbed Algorthm 2 Equlbrum Heat Iteraton: loop whle (Maxer T ol) Maxer = 0.0 Loop on from = 2 to N T (new) = (old) (old) K 1T +KT 1 +1 K 1+K, Maxer =max(maxer, T (new) T (old) = T (new) T (old) ) End Loop on end loop In the next secton we dscuss concepts n C++ that allow the mplementaton of Algorthm 2. Array constructs and how they work wth countng for loops wll be hghlghted and vod functon. 1.4 Implementaton A look at the Algorthm 2 reveals that n order to represent the the Temperature and the conductvty n a straght forward manner, t s desrable to to ndex varables. In the mathematcal world varables wth ndces are known as vectors or arrays. Programmng languages have borrowed from the mathematcal language to provde the concept of an array whch allows the ndexng of varables. These provde a way of combnng ndexed varables nto a sngle name and referred to t by the approprate ndex. Countng for loops n C++ provdes the ablty to work naturally wth arrays. C++ for loops allows the mplementaton of the loop on on Algorthm 2. We stll need to be able to represent ndex varables. 1.4.1 Arrays Arrays provde a mechansm for declarng several data tems wth only one name, and accessng each one of them wth only an ndex. Ths smplfes sgnfcantly the task of varable namng and data

1. Heat Flow n a Rod 5 management. If we had to assgn a name to each of the temperatures, t wll provde a very nflexble program and dffcult to mantan. Consder the followng program that reads the ntal temperature for 5 sectons of the rod. #nclude <ostream.h> // Ths program reads fve numbers and then prnts them back to the user. vod man() // program Temper.cpp float temp0, temp1, temp2, temp3, temp4; cn >> cn >> cn >> cn >> cn >> "Please enter a temperature" << endl; temp0; "Please enter a temperature" << endl; temp1; "Please enter a temperature" << endl; temp2; "Please enter a temperature" << endl; temp3; "Please enter a temperature" << endl; temp4; "Here are the numbers you entered:" << endl; temp0 << endl; temp1 << endl; temp2 << endl; temp3 << endl; temp4 << endl; // end program Temper.cpp There are fve separate varables used for almost dentcal purposes n ths program. One output statement s used fve tmes, another fve vrtually dentcal output statements occur together, as do fve vrtually dentcal nput statements. The program exhbts the repetton that should be ncorporated nto a for loop. Unfortunately, ths s not possble because the repeated statements use slghtly dfferent varables. An array s an ndexed collecton of objects. The elements of an array must be of the same type. The subscrpt that ndexes the array s used to access ndvdual elements n the array. Usng an array of 5 elements to store the nput, nstead of fve named varables wll allow ths. #nclude <ostream.h> // Ths program reads fve numbers and then prnts them back to the user. vod man() // program Temper.cpp float temp[5];

1. Heat Flow n a Rod 6 "Please enter a temperature" << endl; cn >> temp[0]; "Please enter a temperature" << endl; cn >> temp[1]; "Please enter a temperature" << endl; cn >> temp[2]; "Please enter a temperature" << endl; cn >> temp[3]; "Please enter a temperature" << endl; cn >> temp[4]; "Here are the numbers you entered:" << endl; temp[0] << endl; temp[1] << endl; temp[2] << endl; temp[3] << endl; temp[4] << endl; // end program Temper.cpp The number 5 n parentheses n the declaraton of the array temp sgnfes that temp s an array of 5 element. Each entry n the array s an storage locaton and can be treated as an ndvdual varable. float temp[5] declared fve varables: temp[0] through temp[4]. In order to access an array element, the ndex of the desred element s wrtten n parentheses after the array name. Each entry of an array behaves exactly lke a varable. Everythng known about ndvdual varables apples to elements of sngle-dmenson arrays. We can now smplfy the sample program usng for loops. #nclude <ostream.h> // Ths program reads fve numbers and then prnts them back to the user. vod man() // program Temper.cpp float temp[5]; for( nt ndex = 0; ndex < 5; ndex++) "Please enter a temperature" << endl; cn >> temp[ndex]; "Here are the numbers you entered:" << endl; for( ndex = 0; ndex < 5; ndex++) temp[ndex] << endl; // end program Temper.cpp Please note that the program could be changed easly to allow to nput 20 temperatures nstead of

1. Heat Flow n a Rod 7 5. Ths can be accomplshed by changng the array declaraton so the array can stored 20 tems, and changng both for loops so they run from 0 to 19, nstead of 4. Intalzaton Arrays can be ntalzed at the tme of declaraton. The array can be ntalzed smply by supplyng a lst of elements at the tme of ts declaraton, one per element. For nstance: float cx[4] = 1.5, 2.5, 3.5, 4.5 nt cndx[5] = 3, 4, 5, 1, 2 The ntalzer can also fgure out the sze of an array when omtted by takng t from the number of tems of the lst. float cx[] = 0.5, 1.5, 2.5, 3.5, 4.5 // sze s 5 nt cndx[] = 3, 4, 5, 0, 1, 2 //sze s 6 1.4.2 The Rod We now are able to wrte C++ code to mplement Algorthm 2. // Implementaton of Algorthm 2 to obtan the equlbrum temperature. nt N=20; float tmpold[n+1], tmpnew[n+1], K[N]; float Maxerr, Tol; /*... */ tmpold[0] = 472.0; tmpold[20] = 270.0; do Maxerr = 0.0; for( nt nd = 1; nd < N; nd++) tmpnew[nd] = (K[nd-1]*tmpold[nd-1] +K[nd]*tmpold[nd+1]/ (K[nd-1] + K[nd] ); Maxerr = max ( Maxerr, abs( tmpnew[nd] - tmpold[nd])); tmpold[nd] = tmpnew[nd]; whle (Maxerr >= Tol ); /*... */ The values for K the heat conductvty, the ntal values of temperature, and the tolerance T ol should be receved as nput. As we saw before, t s convenent to wrte ndvdual functons to receve such user nput. In fact the calculatons for Algorthm 2 should also be done n a subprogram. We dscuss how Arrays nteract wth functons and subprograms n the next secton.

1. Heat Flow n a Rod 8 Warnng The C++ declaraton float temp[5] there are a total of fve storage locatons dedcated to the array. In C++, the lower ndex s 0 and the hgher ndex s 4(=5-1). A very common problem encountered by programmers s to attempt to access entres of an array that are not n the range defned for the array. In whch case, accessng outsde of the array boundares wll most lkely corrupt the program data. Its results are completely unrelable. Ths s a common cause of crashes n programs. Sgnfcantly, nether the compler nor the computer wll forewarn the user of such an event. 1.4.3 Subprograms It s good programmng practce to attack problems by subdvdng them nto smpler parts, solvng the parts, and then combnng the parts nto an overall soluton. The concept of vod functon has been dscussed earler to acheve modularzaton n C++ programs. Communcaton from a subprogram can also be acheved by provdng t wth some references to some of ts arguments. Arrays can be arguments to functons. It s possble to pass a sngle entry n an array, a secton of the array, or the whole array to a subprogram. Let us consder the mplementaton of Algorthm 2 as a vod functon: vod equlb( float tmpold[], float tmpnew[], float K[], Tol, N) // Implementaton of Algorthm 2 to obtan the equlbrum temperature. // Set sde condtons tmpold[0] = 472; tmpold[n] = 270; float Maxerr; do Maxerr = 0.0; for(nt nd = 1; nd < N; nd++) tmpnew[nd] = (K[nd-1]*tmpold[nd-1] +K[nd]*tmpold[nd+1]/ (K[nd-1] + K[nd] ); Maxerr = max( Maxerr, abs( tmpnew[nd] - tmpold[nd])); tmpold[nd] = tmpnew[nd]; whle (Maxerr >= Tol ); The frst thng to note s that the arrays tmpold[] and tmpnew[] are not beng passed by reference. It s sgnfcant n that what s passed by a functon s the value of the name of the array. The value of the name of the array s the address of the frst element of the array. Therefore, when the called functon modfes array elements n ts scope, t s actually modfyng the array elements n ts orgnal memory locaton. In the callng program one would call the vod functon equlb by ncludng the statement equlb(tmp1, tmp2, Kheat, 10**(-3), 20); n the approprate place of the program. Before the nvocaton, the

1. Heat Flow n a Rod 9 varable tmp1 has the ntal guess of the temperature. After the nvocaton, the varable tmp1 has the result of Algorthm 2. 1.4.4 Dstance Measurng Sensor Lab 1. The descrpton of the Long Dstance Measurng Sensor can be found at http://sharp-world.com/ecg The devce name s GP2Y0A02YK. Look at the specfcaton sheet for ths devce. And measure the coordnates of at least 10 ponts on Fgure 3: Analog Output Object vs Dstance of Relatve Object correspondng to dstances of 15 to 150 cm. 2. Wrte a program that reads a voltage for the standard nput and produces a dstance whch s to be wrtten to the standad output. Your program should use two arrays to store the dstance and voltage coordnates for the Fgure. Your program should use lnear nterpolaton to compute the approxmate dstance. Your program should be save n the cs2503programs drectory n the fle named: dstancesensor.cpp. Verfy that the results you get are near the curve n Fgure 3. 3. Once your program s workng correctly modfy your program so the nput s from a fle Voltagetest.dat and the output s to the fle ObjectDstance.dat. 4. Copy your fles Voltagetest.dat and ObjectDstance.dat nto your publc html/cs2503reports drectory 5. create the report fle dstancesensorreport.html whch explans the lab and ncludes relatve lnks to the fles VoltageTest.dat and ObjectDstance.dat. 6. Modfy your cs2503.html to place a lnk to dstancesensorreport.html. 7. Hand n dstancesensor.cpp, Voltagetest.dat, ObjectDstance.dat, dstancesensorreport.html, and cs2503.html. 1.5 Vsualzaton At each tme nterval, the output of the program that solves the Heat n the rod problem s smply the (x, y) pars where x s the coordnate of a secton and y s the temperature. Ths s just lots of numbers. Starng at lots of numbers could get overwhelmng when tryng to glean any meanng from them. Hence vsualzaton of the data becomes necessary. There are two output procedures n the tme rod heat program. One outputs the heat coeffcents and the other outputs the temperatures. #nclude <fstream.h> ostream fout; // output stream fout has not been bounded to a fle name!! /* Subprogram outkof: vod functon wth no sde effects -t changes nothng n the orgnal program! Desgned for output of par of data ponts; The Coordnate locaton of secton end ponts, and The Heat Coeffs for each secton. */

1. Heat Flow n a Rod 10 vod outkof(float x[], float k[], nt N) // Desgned to output /* Input Parameters x real of dmenson(n+1) // Coordnate locaton of secton ends. K real of dmenson(n) // Heat Coeffs for each secton. N nteger // Number of rod sectons. End of Input Parameters */ // Local varables: nt ; // s used for countng float zero = 0.0; char fnm[] = "Kvalues.dat"; // fnm s a character strng -of length 12. // It wll hold the name of the output fle. // End Local varables. // Bound an output stream to the fle named n fnm: fout.open(fnm); // output stream fout s bounded to fle named // n the character strng fnm. // Output s sent to fle attached to unt: fout << x[0] << ", " << zero <<endl; // Outsde of the rod the heat coef 0. for( = 0; < N ; ++ ) // For each secton: fout << x[] << ", " << k[]<< endl; // coordnate, coeffcent -left end fout << x[+1] << ", " << k[]<< endl; // coord. and Coeffs. at rght end fout << x[n] << ", " << zero<< endl; // Outsde of the rod the heat coef 0. // End of Output. fout.close(); // Close fle currently bounded to fout. "created output fle: " << fnm << endl; // End of subprogram outkof. There are several thngs to note n ths procedure. The fle s made ready to be vewed through matlab. ostream fout; // output stream fout has not been bounded to a fle name!! /*...... */ char fnm[] = "Kvalues.dat"; // fnm s a character strng -of length 13. // It wll hold the name of the output fle. /*...... */ fout.open(fnm); // output stream fout s bounded to fle named // n the character strng fnm. /*...... */ fout.close(); // Close fle currently bounded to fout. The fle name s actually entered through a character varable. Ths would have permtted the name to be nput from the nput lne at run tme.

1. Heat Flow n a Rod 11 The values of the coordnate and the heat coeffcent are output as pars: fout << x[] << ", " << k[]<< endl; // coordnate, coeffcent -left end fout << x[+1] << ", " << k[]<< endl; // coord. and Coeffs. at rght end One par for each end of a segment of the rod. And one par for both ends of the rod. fout << x[0] << ", " << zero<< endl; // Outsde of the rod the heat coef 0. fout << x[n] << ", " << zero<< endl; // Outsde of the rod the heat coef 0. matlab plot command requres only an x-y par to dsplay the nformaton. #nclude <fstream.h> ostream fout; // output stream fout has not been bounded to a fle name!! /* Subprogram outtmp: vod functon wth no sde effects -t changes nothng n the orgnal program! Desgned for output of par of data ponts; The Coordnate locaton, and The Temperature value for each coordnate. The current tme step number s used to name the output fle. */ vod outtmp( float x[], float temper[], nt N, nt & tmestep) /* Input Parameters temper and X are real of sze (N+1) // Temperature and coordnate locaton. N nteger // Number of rod sectons. tmestep nteger // Counter for the tme steps. End of Input Parameters */ nt nteg=10; // Output wll be produced only every nteg tme steps. f ( ( tmestep / nteg ) * nteg == tmestep ) // then nt j =tmestep; // Local varable: j = 10 +j/nteg; // Need a two dgt number //n order to label output fles sequentally. nt frstdgt, secondgt; frstdgt = j/10; secondgt = j - frstdgt * 10; // Create a unque fle name to bound to output stream. // fnm s a character stng of length 10. // It wll hold the name of the output fle. char fnm[] = "temp45.dat"; // locatons 45 of the strng to be changed. fnm[4] = 0 + frstdgt; fnm[5] = 0 + secondgt; /* Frst output fle name s temp10.dat, next s temp11.dat, and so on. */

1. Heat Flow n a Rod 12 // Bound fle name fnm to output stream fout fout.open(fnm); for( nt = 0; < N+1; ++) // Wrte For each coordnate locaton: fout << x[] << ", " << temper[]<<endl; // Output the coordnate and temperature fout.close(); // Close fle name bounded wth output flestream. "created fle: "<< fnm<< endl; // End of subprogram outtmp. Here we tackle the need to output several fles from one program. nt nteg=10; /*... */ nt j =tmestep; // Local varable: j = 10 +j/nteg; // Need two dgt number to label output fles sequentally. nt frstdgt, secondgt; frstdgt = j/10; secondgt = j - frstdgt * 10; The nt varable j represents a two dgt sequence of numbers startng from 10. frstdgt, secondgt of the nt varable j are extracted. The two dgts The names are created at run tme and they nclude numbers to allow sequencng. // Create a unque fle name to bound to output stream. // fnm s a character stng of length 10. // It wll hold the name of the output fle. char fnm[] = "temp45.dat"; // locatons 45 of the strng to be changed. fnm[4] = 0 + frstdgt; fnm[5] = 0 + secondgt; /* Frst output fle name s temp10.dat, next s temp11.dat, and so on. */ The code allows the creaton of a dfferent fle name each tme the program nvokes ths vod functon. Hence fnm becomes a character varable that has a unque name labeled sequentally every tme the subprogram s nvoked. It s used as the name of the output fle. Note the use of sngle quotes for a sngle character. a s a character strng of length 2, a and the end of strng character. a s just the character a. C++ allows some arthmetc operatons among char varables. Hence, 0 +5 s the character for 5.

1. Heat Flow n a Rod 13 Example 1.1: the fle tmemakemove 1.5.1 Anmaton For the creaton of MPEG anmatons the PPM-raw fle type s recommended. The mage fle format can be changed by loadng the mage nto xv and smply savng t wth the desred format. Usng xv one can generate a sequence of mages n hdf, tf, pnm, etc fle formats, whch were generated wth such tools as avs or the scanner. Assume that there are 15 mages n the fles example000.pnm, example001.pnm, through example014.pnm. In order to encode an mpeg move wth these fles as ndvdual frames, each of the mages n the sequence s converted nto an fle wth the ppm-raw format. Ths s acheved wth the xv tool by smply savng mages n fles wth the correct type. Once ths has been accomplshed, the ndvdual frames are ready to be encoded nto the mpeg anmaton. Ths s done through the mpeg encode command. It requres a parameter fle that descrbes the characterstcs of the encodng. Look at the example fle tmemakemove.. The command /local/bn/mpeg encode tmemakemove encodes the sequence of ppm nto a temp.mpg anmaton. The command /local/bn/mpeg play2 allows vewng of temp.mpg fles. 1.6 Alternate Move Assgnment In ths assgnment we wll practce wth the PLOT command of matlab. We wll use some of the features of xv to mprove the dsplays of matlab. Snce we are unable to use the mpeg1 encoder for ths class, we wll nclude the ndvdual frames as nlne mages n a project report. 1. Change drectory nto your es2503programs drectory. 2. Save the three fles: tme heat rod.cpp, and tme n data nto your es2503programs drectory. The program tme heat rod.cpp calculates the temperature dstrbuton n a rod as t changes n tme. The fle tme n data provdes ntal data for the program. Please note each lab secton wll be gven a dfferent set of data. 3. Comple the program: % CC -lm tme heat rod.cpp Execute the program wth the ntal data: % a.out < tme n data It should alert you at the fles that t created: Kvalue.dat and a sequence of temp10.dat through temp17.dat or more. We are gong to create a plot for each of the temp fles wth the Kvalues. 4. Start up matlab and use the plot command to plot the par of values for Kvalue.dat and temp10.dat on the same plot. Please note that the Kvalue and temp10 arrays are not of the same sze. Export the plot at temp10.jpg. 5. Use xv to load the plot temp10.jpg, half ts sze, and save t as temp10.jpg. 6. Use the plot command to plot the par of values for Kvalue.dat and temp11.dat on the same plot. Use xv to load the plot temp11.jpg, half ts sze, and save t as temp10.jpg.

1. Heat Flow n a Rod 14 7. Repeat these steps for 12 through 17. 8. Now you should have fles temp10.jpg through temp17.jpg n your drectory. Vew them n xv to make sure they look rght. 9. At ths pont we would have encode t as an mpeg1 move. We would nclude each frame as an n-lned mage. 10. Copy temp10.jpg through temp17.jpg to your publc html/es2503/ drectory. 11. In your publc html/es2503/ drectory, create a fle temp frames.html whch ncludes all the ndvdual frames temp10.jpg through temp17.jpg as n-lned mages. 12. Change drectory to your publc html/es2503reports drectory, and create a fle named move.html to present your report for ths assgnment that ncludes a relatve lnk to your fle temp frames.html. 13. Modfy your es2503.html fle to nclude a lnk to your report fle move.html. 14. Hand n temp10.ppm through temp17.ppm, temp frames.html, and both the fles move.html and your modfed es2503.html usng the handn command. 15. Clean up your home drectory and any of your publc areas to make sure that no fles contanng your program or porton thereof are accessble by any user. 16. Submt a Journal relatng your experences wth ths assgnment. 1.7 Move Assgnment In ths assgnment we wll practce wth the PLOT command of matlab. We wll use some of the features of xv to grab the dsplays of matlab and to save them as.ppm fles usng the ppm-raw format. We wll encode the resultng fles nto an mpeg anmaton whch wll be lnked nto the home pages. 1. Change drectory nto your es2503programs drectory. 2. Save the three fles: tme heat rod.cpp, tme n data, and tme make move nto your es2503programs drectory. The program tme heat rod.cpp calculates the temperature dstrbuton n a rod as t changes n tme. The fle tme n data provdes ntal data for the program. Please note each lab secton wll be gven a dfferent set of data. 3. Comple the program: % CC -lm tme heat rod.cpp Execute the program wth the ntal data: % a.out < tme n data It should alert you at the fles that t created: Kvalue.dat and a sequence of temp10.dat through temp17.dat. We are gong to create a plot for each of the temp fles wth the Kvalues. 4. Start up matlab and use the plot command to plot the par of values for Kvalue.dat and temp10.dat on the same plot. Export the plot at temp10.jpg. 5. Use xv to load the plot temp10.jpg, half ts sze, and save t as temp10.ppm usng the ppm-raw format. 6. Use the plot command to plot the par of values for Kvalue.dat and temp11.dat on the same plot. Use xv to load the plot temp11.jpg, half ts sze, and save t as temp11.ppm 7. Repeat these steps for 12 through 17.

1. Heat Flow n a Rod 15 8. Now you should have fles temp10.ppm through temp17.ppm n your drectory. Vew them n xv to make sure they look rght. 9. We are fnally ready to encode the move. Type pwd n a termnal wndow. The output s your present workng drectory. Edt the fle tme make move and replace t nto the lne that request your present workng drectory. Make sure that you do not have spurous blanks. Add a blank lne at the end of the scrpt. 10. Once the fle tme make move s saved, ssue the command: % mpeg encode tme make move You should have now a fle temp.mpg. You can vew t usng: % mpeg play temp.mpg 11. Hand n temp10.ppm through temp17.ppm, tme make move, and temp.mpg. 12. Copy the fle temp.mpg to your publc html/es2503/ drectory. 13. Change drectory to your publc html/es2503reports drectory, and create a fle named move.html to present your report for ths assgnment that ncludes a relatve lnk to your fle temp.mpg. 14. Modfy your es2503.html fle to nclude a lnk to your report fle move.html. 15. Hand n both the fles move.html and your modfed es2503.html usng the handn command. 16. Clean up your home drectory and any of your publc areas to make sure that no fles contanng your program or porton thereof are accessble by any user. 17. Submt a Journal relatng your experences wth ths assgnment.