Open Collections

UBC Theses and Dissertations

UBC Theses Logo

UBC Theses and Dissertations

A system for writing interactive engineering programs in APL Samson, Brian R. 1985

Your browser doesn't seem to have a PDF viewer, please download the PDF to view this item.

Item Metadata

Download

Media
831-UBC_1985_A7 S24.pdf [ 2.59MB ]
Metadata
JSON: 831-1.0062946.json
JSON-LD: 831-1.0062946-ld.json
RDF/XML (Pretty): 831-1.0062946-rdf.xml
RDF/JSON: 831-1.0062946-rdf.json
Turtle: 831-1.0062946-turtle.txt
N-Triples: 831-1.0062946-rdf-ntriples.txt
Original Record: 831-1.0062946-source.json
Full Text
831-1.0062946-fulltext.txt
Citation
831-1.0062946.ris

Full Text

A SYSTEM FOR WRITING INTERACTIVE ENGINEERING PROGRAMS IN APL by BRIAN R. SAMSON BASc, University of British Columbia, 1981 A THESIS IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF APPLIED SCIENCE in THE FACULTY OF GRADUATE STUDIES The Department of Civil Engineering We accept this thesis as conforming to the required standard THE UNIVERSITY OF BRITISH COLUMBIA OCTOBER 1985 ® Brian R. Samson, 1985 In presenting this thesis in partial fulfilment of the requirements for an advanced degree at the University of British Columbia, I agree that the Library shall make it freely available for reference and study. I further agree that permission for extensive copying of this thesis for scholarly purposes may be granted by the head of my department or by his or her representatives. It is understood that copying or publication of this thesis for financial gain shall not be allowed without my written permission. Department of / iE'nA/nffrtnfi The University of British Columbia 1956 Main Mall Vancouver, Canada V6T 1Y3 Date A " 0rf /9%< DE-6(3/81) ABSTRACT As the use of computers in engineering becomes more significant and widespread, there is a growing need for interactive computer programs which can be used with a minimum of user preparation. This thesis presents and demonstrates a system for writing interactive engineering programs in APL, a programming language. A good interactive program is sensitive to the needs of the user, and generally includes help features, default options, escape features and check features. To include all of these features in a conventionally organized program is complicated and tedious, especially for longer programs with many interaction events between the program and the user. The system presented here makes it fairly simple to include all of the above features, and provides two additional benefits: 1. The logic of the program becomes more prominent, hence easier to follow and check. 2. The program tends to be highly modular in form, making it more •readable and easier to test and debug. ii T A B L E O F C O N T E N T S C H A P T E R P A G E 1. INTRODUCTION 1 2. B A C K G R O U N D 4 2.1 General Requirements 4 2.2 Literature Review 5 2.3 The U B C Commerce System 7 2.4 The Use of A P L 9 3. T H E C . E . SYSTEM 10 3.1 The Interaction Event 10 3.2 The Phase Tables 14 3.3 Writing, Entering and Editing the Phase Tables 16 3.4 The Execute Function 17 3.5 The Correlate Function 13 4. A GUIDE TO USING T H E C . E . S Y S T E M 19 4.1 Basic Ideas 19 4.2 Program Structure 19 4.2.1 Prompt Table 21 4.2.2 Default Table 21 4.2.3 Help Table 22 4.2.4 Check Table 22 4.2.5 Action Table 23 4.2.6 Flow Control Table 23 4.3 Further Suggestions 24 4.4 Simple Example 25 4.5 Entering and Running the Program 25 iii C H A P T E R P A G E 5. A C O M P R E H E N S I V E E X A M P L E 28 5.1 Description 28 5.2 Program Method 29 5.2.1 Moments of the Random Variables 29 5.2.2 Mean, Variance and Skewness of a General Function 31 5.2.3 Estimating Partial Derivatives 32 5.2.4 Program Outline 33 5.3 Program Listing 34 5.4 Programming Details 41 5.4.1 Descriptions of Functions 41 5.4.2 Flow Control Procedures 41 5.5 A Sample Run 42 6. CONCLUSIONS A N D F U T U R E D E V E L O P M E N T S 48 LIST O F R E F E R E N C E S 49 APPENDIX - S E L E C T E D P R O G R A M LISTINGS 50 iv LIST O F T A B L E S T A B L E P A G E 4.1 A SIMPLE EXAMPLE 26 5.1 EXAMPLE: PROMPT TABLE 35 5.2 EXAMPLE: DEFAULT TABLE 36 5.3 EXAMPLE: HELP TABLE 37 5.4 EXAMPLE: CHECK TABLE 38 5.5 EXAMPLE: ACTION TABLE 39 5.6 EXAMPLE: FLOW CONTROL TABLE 40 5.7 A SAMPLE RUN 43 v LIST O F FIGURES FIGURES P A G E 3.1 THE PHASES OF AN INTERACTION EVENT 13 4.1 THE PHASES OF AN INTERACTION EVENT (REPEATED) 20 vi A C K N O W L E D G E M E N T The author wishes to thank Dr . S. O. Russell for his guidance in the preparation of this thesis, and the Natural Sciences and Engineering Research Council for financial support. vii 1 C H A P T E R 1 I N T R O D U C T I O N In the field of engineering there are countless examples of problems which could quickly and easily be solved by computer program, if only the required program existed in a form that was readily usable. Such examples include: pipe flow calculations, uncertainty estimation, culvert sizing, backwater calculations and runoff estimates using unit hydrograph methods. These are just a few examples from the area of water resources, and there are many others from each of the branches of engineering. When an engineer is faced with solving such a problem, he assembles the necessary information (equations, techniques, data, etc.) and then either computes a solution by hand, or writes a computer program to do it, whichever is less time-consuming or costly. If the engineer decides to write a computer program, usually the end result is a program which is specific to the particular problem for which it was written. In addition, the engineer who wrote the program is often the only person who is familiar enough with it to run it. This lack of versatility arises because the engineer generally wants answers as quickly as possible, and cannot afford the programming time required to make the program versatile and user-friendly. After serving its initial purpose, the program, often lacking adequate documentation, is usually stored somewhere. If, some time later, the need arises for a similar program, the old program may be resurrected and, if necessary, altered to fit the new problem. This can be very time-consuming, especially if the person who wrote the original program is not available, or does not have a good memory. 2 Ideally, a solution to this dilemma would be to have a library of computer programs which can solve many of the problems that a group of users, say a consulting firm, often encounter. These programs would have to be interactive and user-friendly, and preferably would require the user to read little or no documentation. When an engineer is faced with a certain task, he looks up the appropriate program in the library, and solves the problem interactively with the computer. This sounds fine, but there still remains the difficulty of producing versatile, interactive programs. Generally, the part of the program which does the computations requires less time and effort to write than the part which controls the dialogue and interaction. A good interactive program will contain most or all of the following features: 1. The program will provide explanations at the request of the user. 2. The program will be capable of assuming default values if no response is provided by the user. 3. The user can leave the program at any time. 4. The program will check user input for validity or other conditions, and if necessary, send an appropriate message to the user. 5. The program will allow for easy correction of entry errors. 3 6. The program will be responsive to the user's needs and will not easily crash as a result of user entry error. It is quite time-consuming and complicated to include all of these features in a conventionally-organized program, especially for programs containing a lot of interaction with the user. This is not good for engineers, who often are not skilled programmers. This thesis presents a programming system, hereafter referred to as the C . E . (Civil Engineering) System, which simplifies and speeds up the process of writing the interactive part of the program. The C . E . System is easy to learn and use, and should be useful to engineers who want their programs to be more interactive and easier for others to use. Chapter 2 provides background information and reviews two previously developed systems for writing interactive computer programs. The C . E . System is explained in Chapter 3, while specific instructions for use are provided in Chapter 4, a self-contained guide to using the C . E . System. Chapter 5 presents a comprehensive example consisting of a program to estimate the uncertainty of any function of random variables. 4 CHAPTER 2 BACKGROUND 2.1 General Requirements Computer users today are often not programmers, and may not be interested in becoming involved in computers beyond knowing what is necessary to use certain programs. There is a need for a high quality human/computer interface which will not discourage users not experienced in computers or computer languages. The user of an interactive program preferably should not be faced with error messages from the computer operating system or language software system. The manufacturers of micro-computers, in an attempt to reach the widest possible market, now offer operating systems which are amazingly simple and "friendly". In one case, the human/computer interface has been reduced to the most basic communication level, the user simply points to what he wants. However, computer software designers face an increasingly complex task in their efforts to make things easier for the end-users of the software. Most of the effort and skill required to write a good interactive program generally goes into writing the interactive or dialogue part, rather than the part which does the calculations or data processing. A tool which would facilitate the writing of the interactive part would decrease the time and cost required to develop interactive programs, and would also enable less highly skilled programmers to construct effective interactive dialogue. There are many difficulties to be overcome when designing interactive computer programs. One problem is that a computer-guided program intended 5 for very inexperienced users would be too slow and frustrating for experienced users. On the other hand, inexperienced users might become uncertain or confused if faced with a very streamlined, user-guided program. One solution to this problem is to structure the program so that it is fairly easy to adapt the dialogue part of the program to the various experience levels of the users. Also, programs can be designed which allow the user to speed up the dialogue by opting for more streamlined routes through the dialogue, containing fewer prompts and error correction facilities. The system presented in this thesis simplifies the task of writing versatile human/computer dialogue, and also allows for easy editing of the dialogue. Another advantage of the C . F_. Sytem is that it allows the programmer to first write a simplified working version, to which he can later easily add help messages, default options, input checking routines, and more complete prompts. 2.2 Literature Review There have been a number of systems developed to simplify the task of writing interactive programs. Two recently developed systems will be outlined in this section. The first such tool is the M A C A I D system, which has been developed in the last few years at MacMaster University (Ahmed, 1980). M A C A I D utilizes a "master driver" program, and tables of text which contain the dialogue. M A C A I D is intended to be used to construct interactive instructional-type programs. The feasibility of using the M A C A I D system for writing interactive engineering programs was investigated, but the following obstacles were encountered: 6 1. Due to differences in computer facilities, it took several days of debugging to just get MACAID running. 2. MACAID is a fairly large program designed for some objectives not relevant to the goals of this thesis, (eg. instructional programs were not the specific aim). It became evident that the effort required to adapt MACAID was not worthwhile. 3. Learning to write programs using the MACAID system seemed almost as difficult as learning a new computer language. A simpler system was required. Eventually it was decided that MACAID did not meet the necessary requirements. Another tool for writing interactive programs has been developed by the Faculty of Commerce and Business Administration at U.B.C. Their system employs a master table which contains both the program logic and references to other tables where text and executable lines are stored. (Benbasat, 1981, p. ID. This system seemed to hold promise, and has been used as a strong basis for the C. E. System, which is designed to be used for writing interactive engineering programs. The main objective of the U.B.C. Commerce System, and the C. E. System as well, is to improve the design of the human/computer interface "from being an ad hoc process to being structured and planned". (Benbasat, 1981, p. 4). 7 2.3 The U B C Commerce System The fundamental idea behind the Commerce system is that a human/computer dialogue can be seen as a series of "interaction events". An interaction event generally consists of a prompt by the computer, a response from the user, and any computer action or processing which occurs prior to the next prompt. An organised collection of these interaction events makes up an interactive program, which also must contain a system of flow control which defines all possible event sequences through the dialogue which a user may choose. The interaction event itself can be broken down into "phases". Generally there are up to seven phases in each interaction event, although not all of them will necessarily be used in every event. These seven phases are: 1. Prompt: The computer asks the user to supply data or instructions. 2. Input: The user responds, or uses a default option. 3. Escape: Allows the user to leave the program if he wishes. 4. Help: If requested by the user, an explanation is provided of what the computer is prompting for. 5. Check: The user input is checked for errors, validity, or any other condition. 6. Act ion: Any related processing is carried out by the computer. 7. Flow Control : The program determines which event to proceed to next. One interaction event consists of moving once through the phases in the order they are listed above. To determine the order in which the interaction events are executed, there are three basic types of flow control: 3 1. The next event is pre-set, regardless of user input or the results of any processing. 2. The next event is selected, depending on user input or the results of some processing. 3. The next event is pre-set unless a certain condition is met, in which case a branch to a different event occurs. At first, these concepts seem to merely add complexity to the problem of writing an interactive program. However, these ideas can be used to impose a structure on the program which makes it more organized, and easier to write and modify. Both the Commerce System and the C. E. System are based on the concepts described so far, but the two systems differ in the way they implement the ideas. This section will outline the Commerce implementation, while the description of the C. E. System will be covered in the next chapter. In the Commerce system, the program logic is contained in an "event description table" made up of words which are references to other tables which contain the actual program information. The order of the words in the event description table determines the order in which the program information is executed. Each entry in the event description table refers to certain lines in a particular information table. There are several information tables, with each one containing information of the same type (eg. text) or of the same phase (eg. check). In theory, this system is good, and in practice it works, but when the author attempted to write a program using it, it was found to be somewhat 9 complicated. The C. E. implementation is simpler in that it does not use an event description table, and has one table for each of six phases (prompt, default, help, check, action, flow control). 2.4 The Use of APL APL, first defined in 1962 by K. E. Iverson, is a general purpose language which is particularly suited to matrix manipulation. Learning APL consists mainly of learning the uses and rules of its extensive built-in operators. These operators, depicted by symbols, result in a language which is terse and powerful, although the programs can be difficult to read. The most unique characteristic of APL is its use of the "workspace" concept. When a user interacts with the computer via the APL interpreter, he does so in a particular workspace. In this workspace the user stores functions (programs) and variable names with their current values. Functions are executed simply by naming them, and lines entered by the user are executed immediately. This conversational environment where all functions and variables in the workspace are easily and automatically integrated, in addition to the powerful array manipulation operators in APL, make the language very suitable for implementing the programming tool described in this thesis. 10 CHAPTER 3 THE C. E. SYSTEM The Interaction Event The Civ i l Engineering system of designing interactive programs is based on the concept of a sequence of interaction events, each consisting of ordered phases, but the implementation is somewhat different from that of the Commerce System. The program is written one interaction event at a time, and the flow control determines the order in which the events are executed. Each interaction event consists of six phases: 1. Prompt Phase The computer displays a prompt, generally asking the user for input (data, commands, etc.) and the user enters his response. If the user enters: i) "back", then the next phase executed will be the prompt phase of the previous event. This option is provided so that the user can make changes to input he has already entered in previous events. ii) "escape", then the program stops execution. This is provided so the user can easily leave the program at any time. iii) nothing (eg. just presses return), then the program proceeds to the default phase. iv) "help", then the program proceeds to the help phase. v) characters other than "back", "escape" or "help", then the program proceeds to the check phase. 11 2. Default Phase If the user enters nothing in response to a prompt (just presses return), then this phase is executed. The programmer uses this phase if he wants to give the user the option of just pressing return in response to a particular prompt. The programmer may define certain lines which will be executed if the user enters nothing. In many events there may be no default option, in which case if the user just presses return he will be advised that there is no default, and the prompt w i l l be re-issued. After the default phase is executed, the program proceeds to the action phase. 3. Help Phase If the user enters "help" in response to a prompt, then this phase is executed. The programmer uses this phase to provide the user with an explanation of what is required in response to the prompt. After this phase is executed, the program returns to the prompt phase. 4. Check Phase If the user enters characters other than "back", "escape" or "help" in response to a prompt, then this phase is executed. The programmer uses this phase to check whether the user input meets certain conditions, which the programmer specifies. If the user input is not satisfactory, then the program returns to the prompt phase of the same event. If the user input is satisfactory, then the program proceeds to the action phase. 12 5. Action Phase In this phase, any required processing or calculations are carried out. Subroutines (APL functions) are generally used to perform the calculations. 6 . Flow Control Phase After the action phase is complete, the number of the next event is determined in the flow control phase. The next event may be pre-set, or may depend on the user input or the results of the action phase. After the flow control phase, the next event starts, beginning with the prompt phase. The flow control within each interaction event is the same regardless of the particular event or program where it occurs. Figure 3.1 on the following page summarizes the six phases which make up every interaction event. Figure 3.1 applies to every interaction event, and so a universal program, called a driver, has been written to control the flow within each interaction event. It remains for the programmer to write the actual lines contained in each phase of the events, as well as the flow control which governs the order in which the events are executed. The executable lines are organized in tables (character arrays), one for each of the six phases, and each phase table contains lines corresponding to that particular phase of every interaction event in the program. A number at the beginning of each line in the phase table indicates the event to which that line belongs. Thus the entire dialogue of a particular program is contained in six character arrays. FIGURE 3.1 THE PHASES OF AN INTERACTION EVENT I f i n p u t not s a t i s f a c t o r y I f i n p u t s a t i s f a c t o r y To prompt ghase o f n e x t e v e n t Flow C o n t r o l Phase 7 The a r r o w s r e p r e s e n t p o s s i b l e p a t h s between p h a s e s . A s t a t e m e n t on an a r r o w i n d i c a t e s t h e c o n d i t i o n under w h i c h t h a t p a t h i s f o l l o w e d . An a r r o w w i t h o u t a s t a t e m e n t i n d i c a t e s a p a t h a l w a y s t a k e n between two p h a s e s . o j 14 The Phase Tables When using the C . E . System, a programmer writes each interaction event as a unit. However, the program lines are stored in tables according to the phase of the interaction event to which the lines belong. There is one table for each of the six phases (prompt, default, help, check, action, flow control). The interaction events which make up the program are numbered sequentially, and each line in each phase table is numbered to indicate the event to which the line belongs. In each phase table, up to 10 lines can have the same event number. Thus for each interaction event the programmer writes the prompt lines in the prompt table, the default lines in the default table, etc. Generally, the programmer would write the program out by hand first, and then store each complete phase table in the A P L workspace. The phase tables are stored as character arrays with the abbreviated names: prom, defa, help, chec, acti and flow. Specific information regarding each phase table follows. Refer to the simple example on page 26. The Prompt Table The prompt table is used to prompt for and receive information from the user. Al l input from the user is assigned to the character variable called 'answer'. The programmer may also assign the input to any other variable name, as in the example. The first three spaces of each line in every phase table are reserved for the interaction event number. The last line in each phase table must have a zero in the event number columns to indicate the end of the table. (This last line is not executed). 15 The Default Table This table contains lines which are automatically executed if the user defaults in response to a prompt. Usually the lines in this table are used to assign values to variables. For any event where the programmer does not wish to provide the user with a default option, he uses the line "default = 0", as in the example. The Help Table The lines in this table are executed if the user enters "help" in response to a prompt. The table may contain explanations or examples, whatever the programmer wishes to have displayed. The programmer can also include a system of keeping track of how many times the user enters "help" while running the program. For any of the phase tables, the maximum number of lines which can be used for a particular event is ten. If more lines are required, the programmer can use a separate function. The Check Table In this table, the programmer specifies any checks to be made on the user input. Lines in this table are always written in pairs. The first line of the pair is a check line which, when executed, results in a value of either one (if true) or zero (if false). If the value of the check line is one, then the second line of the pair is executed. If the value of the check line is zero, then the second line of the pair is not executed. Certain user input may be unacceptable and in this case the programmer may want to return the user to the prompt phase of the event. To accomplish this, the line "check = 0" is used as the second line of the pair. This is a signal to the driver program that the user is to be re-prompted for the input. (See example). .16 The Action Table This table carries out any calculations or other processing which the programmer wants executed before the next interaction event begins. To keep the table reasonably brief and readable, the programmer should use functions for those events where more than one or two lines of programming are required. The Flow Control Table In this table, the number of the event to be executed next is assigned to the variable names "next". The number of the next event may be pre-set or it may depend on user input or the results of calculations. The programmer may also want to repeat an event until a certain condition is met. All of these situations can be handled with an assignment line which uses the A PL compression symbol, as in the example. Writing, Entering, and Editing the Phase Tables Each phase table is a two-dimensional character array with a four character name (prom, defa, help, chec, acti, or flow). A function has been written to assist the programmer in entering each table into the workspace. A convenient way to write a program using the C. E . System is to first write only the Prompt, Action, and Flow Control tables. These three tables are enough to create a basic working version of the program which is easier to handle and debug. Once this brief version is running, the Default, Help and Check tables can be added to make the program more interactive, user-friendly, and foolproof. A function has been written to assist the programmer in editing the phase tables. More specific instructions for writing a program are given in Chapter 4 entitled "A 17 Guide to Using the C. E. System", which is meant to be a self-contained guide. Those interested in using the C. E. System should be able to use the guide without having to read this entire thesis. The Execute Function Once the phase tables have been written and entered into the workspace, the program is run by executing the lines in their proper order. As stated previously, the function which accomplishes this is called a driver. For phase tables written using the C. E. System a driver function ("execute") has been written which is based on the logic illustrated in Figure 3.1. Event number one is executed fi r s t , starting with the prompt phase and then moving to other phases depending on user input. In each phase, all lines with the current event number are executed in sequence. For some events, the programmer may want to use the prompt phase simply to display a message not requiring user input. The driver function senses those events where no user response is required, and moves on to the action phase of the event. The driver function continues to execute the lines in the phase tables until the final flow control phase line, which stops execution. When the user enters "back" in response to any prompt, the driver function automatically moves back to the prompt phase of the event preceding the current one. This is not necessarily the event that was executed immediately previous to the current one, but is the event which has the next lower number. It would be possible to design the driver function so that it would trace backward through the events in the reverse order to the way they were actually 18 executed. However, this might lead to confusion in those instances where the user had already used the "back" option previously in the same run. For this reason, when the user enters "back", the driver function simply moves backward one event in the phase tables (eg. to the next lowest event number). The user can back up all the way to the first event if he wishes. The Correlate Function So that the execute function does not have to repeatedly search each phase table to determine which rows belong to the current event, the correlate function has been written. After the phase tables have been written and entered into the workspace, the programmer must run the correlate function before his program can be executed by the driver. The correlate funciton runs through the phase tables once, and records v/hich row numbers in each phase table correspond to the different event numbers. The results of the correlate function are stored in a three-dimensional array which is used by the driver to determine which rows of each phase table to execute as part of each event. This saves execution time when the driver program is run. 19 CHAPTER 4 A GUIDE TO USING THE C. E. SYSTEM 4.1 Basic Ideas 1. An interactive program can be written as a series of interaction events between the computer and the user. A basic interaction event consists of a prompt from the computer, a response from the user, and any processing done by the computer before the next prompt is issued. 2. The interaction event can be split into six phases: prompt; default; help; check; action; flow control. Figure 4.1 on the following page represents an interaction event, showing the function of each of the phases. The arrows show how the program user moves through the phases. Each interaction event starts with the prompt phase, and the user response determines the next phase. 4.2 Program Structure Once written, the program consists of six phase tables which define the dialogue, and any number of subroutines or functions which perform calculations or processing. The phase tables are in the form of character arrays with the first three columns of each row used for the event number, and the remaining columns used for any executable line in APL. To write the program, start with event number one. Write the prompt (the message you want the user to see) in the prompt table, then default in the FIGURE 4.1 THE PHASES OF AN INTERACTION EVENT From flow c o n t r o l phase of previous event To prompt phgse of previous event Program stops execution I f input not s a t i s f a c t o r y I f input s a t i s f a c t o r y To prompt phase of next event Flow Control Phase \_7 nothing User enters "help" User enters characters other thp.n "back", "escape", or "help"  The arrows represent p o s s i b l e paths between phases. A statement on an arrow i n d i c a t e s the c o n d i t i o n under which that path i s fol l o w e d . An arrow without a statement i n d i c a t e s a path always taken between two phases. IN) Q 21 default table, then the help message in the help table, etc. Specific comments for writing each table follow below. 4.2.1 Prompt Table (Named "prom"; for programming convenience, each phase table name has been abbreviated to four characters). The prompt phase of each event generally consists of the prompt itself, followed by a line which accepts input, eg. 1 'Enter your high estimate of the variable x'. 1 answer = xhigh = $// The number occupying the first three spaces of each line is the event number. All lines with the same event number will be executed together in sequence. All input is initially in character form ($//) and always is assigned to the variable called "answer". If the programmer wishes to also assign the input to his own variable name ( xhigh in the above example) he may do so. 4.2.2 Default Table (named "defa") In some interaction events, the programmer may want to give the user the option of just pressing the return key, in which case the program will automatically assume a value for the input requested. This is accomplished by placing a line such as the following in the default table, eg. 1 xhigh = 1000 If the user just hits return in response to the prompt of event number one, then the lines with event number one in the default table will be executed. In the example, the variable xhigh will be assigned the value 1000. If the programmer 22 does not want to give the user a default option for a pariticular event, he uses the line: 1 default = 0 In this case if the user just hits return he will be sent a message that there is no default available, and he will be re-prompted for the required input. 4.2.3 Help Table (named "help") If the user wants an explanation of any prompt he is given, he may enter "help" in which case the help table lines for that particular event are executed, eg. 1 'Your high estimate of x is the value which' 1 'you are 90% sure will not be exceeded.' If the user enters "help" in response to the prompt for event number one, the above message is displayed and then the prompt is repeated. 4.2.4 Check Table (named "chec") The programmer may want to check that the input just entered by the user satisfies certain conditions before proceeding further. The check table is different from the other phase tables in that lines are always written in pairs. The first line of a pair is always a condition. If the condition is true (eg. equal to one when evaluated), the second line of the pair is executed. If the condition is false (eg. equal to zero when evaluated), then the second line is not executed, eg. 1 ($EX xhigh) $ LT 0 1 'Your high estimate of x must be greater than zero'. For any particular prompt, certain user response may be unacceptable, and the programmer may want to display an appropriate message, then repeat the 23 prompt. The following pair of lines written in the check table would cause the prompt to be repeated if xhigh is negative. 1 ($EX xhigh) $ LT 0 1 check = 0 The second line is interpreted by the execution program to mean "go back to the prompt phase of this interaction event". 4.2.5 Action Table (named "acti") The action table contains any lines which the programmer wants executed before proceeding to subsequent events. Generally this will consist of any calculations to be carried out using information just entered by the user. If more than one or two lines are required, the programmer should use a subroutine since this keeps the phase tables brief and easier to read, eg. 1 v = xlow variance xhigh In this line, "variance" is a program which calculates the approximate variance of x using the high and low estimates xhigh and xlow. 4.2.6 Flow Control Table (named "flow") This table is used to determine which event to execute next. The variable "next" is assigned a value which is the number of the event which is to be executed next. For some events the next event may be predetermined, eg. 1 next = 2 For other events, the number of the next event may be determined by the user input or the outcome of the action phase. In these cases, the compression operator (%) can be used to assign the appropriate value to "next". 24 eg. 1 next = ((xhigh $ E Q xlow), (xhigh $NF_ xlow)) %2, 3 In this example, if xhigh equals xlow, then event number two is executed next, but if xhigh is not equal to xlow, then event number three is executed next. After the flow control phase for event number one is written, the programmer writes the next interaction event, starting again with the prompt phase. When writing a program, one would usually start by writing just the essential phases required to get the program running, eg. prompt, action and flow control. This simplifies things since the programmer can concentrate on the necessary elements and leave the default, help and check tables for later, after the basic program is running. The last line of each phase table must have the number zero in the space normally occupied by the event number (eg. the first three columns). If the programmer chooses to leave the default, help and check tables to be written after the basic program is running, then these tables should each have one line, consisting of a zero anywhere in the firs t three spaces. Further Suggestions To repeat an event a certain number of times, the programmer can use a counting variable which is increased by one each time the event is executed. The flow control phase is then used to check whether the required number of repetitions have been executed, and controls the branching accordingly. (The next event number is set equal to the current event number until the repetitions are complete). 25 4.4 Simple Example Table 4.1 on the following page contains a very simple program used to find the sum of two numbers. Note that if an event does not require a particular phase, the programmer simply does not put any lines with that event number in that phase table. 4.5 Entering and Running the Program The following objects are necessary to run any program writting using the C. E. System: correlate execute multch multchar edit locate phase These objects should be copied from the workspace BSAM.INTER. To enter the phase tables in the workspace, use the lines: prom = multchar (for the prompt table) defa = multchar (for the default table) help = multchar (etc) where "multchar" is a function which helps you create the phase tables. To edit phase tables, use the lines: prom - edit prom (for the prompt table) defa = edit defa (for the default table) and follow the instruction you are given by the function "edit". TABLE A . l A SIMPLE EXAMPLE The phase tables: Comments: p r o m 1 ' E n t e r t h e f i r s t n u m b e r . ' 1 answer=n1=$# 2 ' E n t e r t h e s e c o n d n u m b e r ( d e f a u l t 1s z e r o ) . ' 2 a n s w e r = n 2 = $ # 3 ' A n s w e r b e i n g c a l c u l a t e d . ' O O O O O O O O O O O O O O O O O O O O O O O O This i s j u s t a message to the user, and requires no response. d e f a 1 d e f a u l t = 0 2 n 2 = ' 0 ' 0 0 0 0 0 0 This means there i s no d e f a u l t i n t h i s case. n2 w i l l be given the value 0 i f the user enters nothing. h e l p 1 ' E n t e r t h e f i r s t o f t h e t w o n u m b e r s t o b e a d d e d t o g e t h e r . ' 2 ' E n t e r t h e s e c o n d o f t h e t w o n u m b e r s t o b e a d d e d t o g e t h e r . ' 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c h e c 1 ( + % n 1 $ E P ' 1 2 3 4 5 6 7 8 9 0 . ' ) $ L T ( $ , , n 1 ) 1 ' E n t e r j u s t t h e n u m b e r , n o o t h e r c h a r a c t e r s . ' 1 ( + % n 1 $ E P ' 1 2 3 4 5 6 7 8 9 0 . ' ) $ L T ( $ , , n 1 ) 1 c h e c k = 0 2 ( + % n 2 $ E P ' 1 2 3 4 5 6 7 8 9 0 . ' ) $ L T ( $ . , n 2 ) 2 ' E n t e r j u s t t h e n u m b e r , n o o t h e r c h a r a c t e r s . ' 2 ( + % n 2 $ E P ' 1 2 3 4 5 6 7 8 9 0 . ' ) $ L T ( $ , , n 2 ) 2 c h e c k = 0 O O O O O O O O O O O O O O O O O O O O O O O O This checks that the user entry i s j u s t a number. If the user has entered anything other than, or i n a d d i t i o n to, a number, the prompt w i l l be repeated. a c t 1 3 n 1 s u m n 2 0 0 0 0 0 0 f 1 o w 1 n e x t = 2 2 n e x t = 3 3 $ > 0 0 0 0 0 0 "sum" i s a f u n c t i o n ( l i s t e d below), which adds the numbers nl and n2. Event 2 i s to be executed next. Event 3 i s to be executed next. " s u m < # > " " x s u m y ; x ; y [ 1 ] t o t a l = ( $ E X x ) + $ E X y [ 2 ] ' T h e s u m o f t h e t w o n u m b e r s I s ' , $ F M t o t a l [ 3 ] $ > 0 27 Once the phase tables have been entered, type "correlate", invoking the function "correlate" which sorts through the phase tables and records which row numbers in each table correlate to the various events. Then the program is ready to run, which is done by typing "execute". If any phase table is edited, resulting in row additions, row deletions, or changes in event numbers, then "correlate" must be run again. 28 C H A P T E R 5 A C O M P R E H E N S I V E E X A M P L E Description To examine the effectiveness of the C. E. System for writing interactive engineering programs, a fairly extensive example program was written. The program can be used to estimate the expected value, variance and skewness of any given function of random variables. The first, second and third moments of the parameter distributions are combined mathematically to yield estimated moments of the function. This function moments program is useful whenever a user is evaluating a function whose parameters have uncertain values (cost estimating functions for example). For all but the simplest of functions, the calculations required to estimate the function moments are difficult or impossible to do by hand. But without carrying out these calculations, it is not possible to accurately estimate the effect of a parameter's variability on the moments of the function. Using the program presented here, the user gets his answer after a few minutes of interaction with the computer. In addition, the user can quickly make several runs while varying his parameter estimates or correlation coefficients, and quickly get an idea of sensitivities. The benefits of using the C. E. System to write this function moments program are as follows: i) It is relatively easy to incorporate interactive features such as help, default, escape, check and entry correction. 29 ii) The program is organized into numbered events and phase tables, which make the logic of the program more prominent, hence easier to follow and check. iii) The program is modular in form, making it more readable and easier to test and debug. 5.2 Program Method 5.2.1 Moments of the Random Variables (Parameters) The first two moments of a parameter's distribution function can be estimated from the following formulas: Where: L is a low estimate of the parameter, likely to be exceeded 90% of the time. M is the most likely estimate of the parameter, likely to be exceeded 50% of the time. H is a high estimate of the parameter, likely to be exceeded only 10% of the time. These two equations are reasonably accurate for most distributions with central tendency, although they are less accurate for extremely skewed distributions. (Davidson, 1976, p. 1070) mean = t (L + 2M + H) variance = The third central moment (skewness) of a parameter's distribution function can be estimated using the following procedure. Knowing the low (L), most likely 30 (M), and high (H) estimates of the parameter (eg. those values which have a 90%, 50%, and 10% chance of being exceeded, respectively), we can find a value x such that if x is added to L, M and H, the resulting distribution Y, is log normal. ie . ln(H*-x) - In(M^) = |n(Mf>) - In[L + x) or H + x M+ X S o l v i n g for X g/ves X by frtkma omhloas . L+X 1 J J 2 X - H L - M 2M-H - L The following 5 steps can be used to estimate the third central moment (skewness) from the percentage points of a distribution: 1. Calcuate o\ = H - L = approximate standard deviation of Y 2.0,5 2. Calculate X * ML- M 2 = shift of Y 2M-u-L 3. Calculate CT y = Iz. + x / = approximate standard deviation of In Y -to" 4. Calculate my *(Mfx) e M = mean of Y (Ang, 1975, p. 103-105) 5. Calculate zcJ'« 3 fly f °y = third moment (skewness) of Y (Benjamin, 1970, p. 269) 31 5.2.2 Mean, Variance and Skewness of a General Function For a function of several random variables Y = g(xi, x2, ..,xn) the mean, variance and skewness can be estimated by the following equations: J f ' / X n *•< j - ' ax- ax- ' ' J the mean of parameter Xj covariance of Xj with Xj variance of Xj third moment of X[ third moment of the function Y = g(Xi, X 2 , Xn) and the partial derivatives are evaluated at yd^ , ytt^ , ••• , /i/n These expressions are obtained from a truncated Taylor's series expansion of the general function g about the expected values yUx. , and by using the moment definitions. (Siddall, 1972, p. 49 - 51). Where: Cov (Xj, Xj) = Var (Xj) A' -32 5.2.3 Estimating Partial Derivatives The first and second partial derivatives (evaluated at the parameter means) are estimated numerically by calculating the effect on the function of small changes in each of the parameters. For example: 1. To estimate ^5 ; Let: A = function g evaluated at ylcx t yU^ , .. ., yUx B = function g evaluated at yUx , . . . , /.ooiyu^. , . . . ,y^x djj_ z B-A d>{i .001 yUx. To estimate <3zg ) (it j) Let: A - function g evaluated at yU.x , •. • , yU-x B = function g evaluated at yUx ) . . . /.oo/^u^, i ... )yuxn C = function g evaluated at ytcx , ... , /.oo/ydy. / . .. , D = function g evaluated at ,  00//Mxl , • • • , 't>W//U.y., • • •, /^yn 3%. D-C B-A . 001/x.x. .001 yU^ • 001 yUyj D-B C-A -OOlyU-Xj .00/yCCX. A - 3 - C / D .001 A, .00000/ 33 3. To estimate 3  zcj f Let: A = function g evaluated at yUx ,...,ft-x B = function g evaluated at yic^ , . /-oo//ux J , ., j yUXr) C = function g evaluated at yUx / . . . /-ooz /t^. t ... t yU>je C-B B-A dX* , 0 0 , .oooooz/t*. 5.2.4 P r o g r a m O u t l i n e The program is capable of estimating the first three moments of any explicit function of up to ten random variables. As many as five different functions can be stored in one workspace. A function can take the form of either a single mathematical expression, or a subroutine containing a series of calculations. The user of the program supplies the function, the names of all the variables, his low, probable, and high estimates of each of the parameters, and his estimatesof the correlation coefficients between each pair of parameters. The program returns the moments of the function and its parameters as well as the calculated covariances and partial derivatives. The program consists of 13 interaction events: 1. User enters name of function to be evaluated. 2. User enters description and units of dependent variable. 3. User enters names of all parameters. 4. User enters descriptions and units for all parameters. 5. User defines the function. 34 6,7. User enters low, probable, and high estimates of parameters. 8-11. User enters correlation coefficients. 12. Moments of parameters calculated, derivatives calculated. 13. Moments of function calculated results displayed. Program Listing The following six pages show the six phase tables, with comments added for explanation purposes. Each event starts with the prompt phase, and the driver program determines which of the other phases are executed, based generally on the user response. TABLE 5.1 EXAMPLE: THE PROMPT TABLE p r o m 1 ' E n t e r t h e n a m e o f t h e d e p e n d e n t v a r i a b l e t o b e e v a l u a t e d . ' 1 ' T h i s i s g e n e r a l l y a n a b b r e v i a t i o n a n d m u s t h a v e ' 1 ' n o m o r e t h a n t h r e e c h a r a c t e r s . ' 1 a n s w e r = a n s w e r O = $ # 2 ' T h e d e p e n d e n t v a r i a b l e ' . a n s w e r O , ' h a s n o t y e t b e e n d e f i n e d ' 2 ' E n t e r a b r i e f d e s c r i p t i o n o f t h e d e p e n d e n t v a r i a b l e ' . a n s w e r O , ' . ' 2 a n s w e r = a n s w e r 1 - % M 2 ' E n t e r t h e u n i t s t o b e u s e d f o r t h e d e p e n d e n t v a r i a b l e ' , a n s w e r O , ' . ' 2 a n s w e r = a n s w e r 2 = $ # 3 ' E n t e r t h e n a m e s o f a l l o f t h e v a r i a b l e s r e q u i r e d t o ' 3 ' c a l c u l a t e t h e d e p e n d e n t v a r i a b l e ' . a n s w e r O , ' . E n t e r t h e m a l l o n ' 3 ' o n e l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . E a c h n a m e m u s t ' 3 ' c o n s i s t o f n o m o r e t h a n t h r e e c h a r a c t e r s . ' 3 a n s w e r = a n s w e r 3 = $ # 4 ' E n t e r a b r i e f d e s c r i p t i o n o f t h e v a r i a b l e ' , i n d e p [ n d e p ; c o u n t ; ] , ' . ' 4 a n s w e r = a n s w e r 4 = $ # 4 ' E n t e r t h e u n i t s t o b e u s e d f o r t h e v a r i a b l e ' , i n d e p [ n d e p ; c o u n t ; ] , ' . ' 4 a n s w e r = a n s w e r 5 = $*' 5 ' E n t e r t h e e x p r e s s i o n o r t h e n a m e o f t h e f u n c t i o n t o b e u s e d t o ' 5 ' c a l c u l a t e ' , d e p e n [ n d e p ; ] , ' . I f e n t e r i n g a n e x p r e s s i o n , e n t e r ' 5 ' t h e r i g h t s i d e o n l y . ( T h e e x p r e s s i o n m u s t b e i n A P L l a n g u a g e ' 5 ' a n d i s l i m i t e d t o a m a x i m u m o f 8 0 c h a r a c t e r s i n l e n g t h . ) ' 5 a n s w e r = a n s w e r 6 = $ # 6 ' Y o u w i l l n e x t b e a s k e d t o e n t e r y o u r l o w . m o s t l i k e l y , a n d h i g h e s t i m a t e s ' 6 ' o f e a c h o f t h e p a r a m e t e r s . T h e l o w e s t i m a t e i s t h e n u m b e r y o u a r e 9 0 % s u r e ' 6 ' w i l l b e e x c e e d e d . T h e m o s t l i k e l y e s t i m a t e i s t h e n u m b e r w h i c h h a s a 5 0 % ' G ' c h a n c e o f b e i n g e x c e e d e d . T h e h i g h e s t i m a t e h a s o n l y a 10% c h a n c e o f b e i n g ' G ' e x c e e d e d . F o r e a c h p a r a m e t e r , t h e t h r e e n u m b e r s s h o u l d b e e n t e r e d o n o n e ' 6 ' l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . T h e t h r e e n u m b e r s m a y b e e n t e r e d i n ' 6 ' a n y o r d e r . I f a n y o f t h e p a r a m e t e r s i s c e r t a i n , y o u m a y s a v e t i m e 1 f y o u ' 6 ' w i s h b y e n t e r i n g j u s t o n e n u m b e r . ' 7 ' E n t e r y o u r e s t i m a t e s o f t h e p a r a m e t e r ' , i n d e p [ n d e p ; c o u n t ; ] 7 ' D e s c r i p t i o n : ' , d e s 1 n d [ n d e p ; c o u n t ; ] 7 ' U n i t s t o b e u s e d : ' . u n i n d ( n d e p ; c o u n t ; ] 7 a n s w e r = a n s w e r 7 = $ # 8 ' D o y o u w i s h t o e n t e r o r c h a n g e a n y c o r r e l a t i o n c o e f f i c i e n t s ? ' 8 ' E n t e r y e s o r n o . ' 8 a n s w e r = a n s w e r 8 = $ # 9 ' E n t e r t h e c o r r e l a t i o n c o e f f i c i e n t s i n t h e t a b l e b e l o w . J u s t l e a v e ' 9 ' b l a n k a n y z e r o c o e f f i c i e n t s . M a k e s u r e t h a t a n y n u m b e r s y o u ' 9 ' e n t e r a r e w i t h i n t h e i r p r o p e r c o l u m n b o u n d a r i e s ' 9 ' a s d e f i n e d b y t h e c o l u m n h e a d i n g s . ' 9 ' ' 9 h e a d i n g 1 0 i n d e p [ n d e p ; c o u n t ; ] , ' : ' , ( 5 2 $ F M t a b 1 e [ c o u n t ; ] ) 1 0 a n s w e r = a n s w e r 1 0 = $ # 1 0 a n s w e r 9 [ c o u n t ; ] = 5 5 $ T A a n s w e r 1 0 11 ' c o e f f i c i e n t s b e i n g s t o r e d ' 12 ' m e a n s a n d v a r i a n c e s o f I n d e p e n d e n t v a r i a b l e s b e i n g c a l c u l a t e d ' 13 ' e x p e c t e d v a l u e a n d v a r i a n c e o f ' , d e p e n [ n d e p ; ] , ' b e i n g c a l c u l a t e d . ' 0 TABLE 5.2 EXAMPLE: THE DEFAULT TABLE d e f a 1 d e f a u l t = 0 2 a n s w e r 1 = a n s w e r 2 = ' n o t g i v e n ' 3 d e f a u l t = 0 4 a n s w e r 4 = a n s w e r 5 = ' n o t g i v e n ' 5 d e f a u l t = 0 7 d e f a u 1 t = 0 8 d e f a u l t = 0 0 TABLE 5 .3 EXAMPLE: THE HELP TABLE h e l p 1 ' T y p e i n t h e n a m e o f t h e q u a n t i t y y o u w i s h c a l c u l a t e d . ' 1 ' I f t h i s i s t h e f i r s t t i m e y o u h a v e e n t e r e d t h i s n a m e , ' 1 ' t h e n y o u w i l l b e a s k e d t o e n t e r t h e e x p r e s s i o n r e q u i r e d . ' 1 ' I f t h e e x p r e s s i o n h a s a l r e a d y b e e n s t o r e d t h e n y o u w i l l ? 1 ' n e x t b e a s k e d f o r y o u r e s t i m a t e s o f t h e p a r a m e t e r s . ' 2 ' T h e d e s c r i p t i o n m a y b e j u s t t h e f u l l n a m e o f t h e v a r i a b l e , ' 2 ' o r m a y b e m o r e d e t a i l e d , a l t h o u g h n o m o r e t h a n 5 0 c h a r a c t e r s ' 2 ' w i l l b e s t o r e d . ' 2 ' F o r t h e u n i t s , u p t o 2 0 c h a r a c t e r s w i l l b e s t o r e d . ' 2 ' T h e m a i n p u r p o s e o f a s k i n g f o r t h e s e d e s c r i p t i o n s i s t h a t ' 2 ' t h e y w i l l b e u s e d t o i n f o r m o r r e m i n d f u t u r e u s e r s . ' 2 ' e g . : F o r t h e v a r i a b l e n a m e d 0 t h e d e s c r i p t i o n c o u l d b e ' ' f l o w ' ' ' 2 ' a n d t h e u n i t s c o u l d b e ' ' (m@>3 ) / s ' ' . ( Y o u w o u l d n o t e n t e r ' 2 ' t h e q u o t a t i o n m a r k s t h o u g h . ) ' 3 ' F o r e x a m p l e , i f t h e e x p r e s s i o n w e r e y = x 1 * x 2 / x 3 , t h e i n d e p e n d e n t ' 3 ' w o u l d b e x 1 , x 2 , a n d x 3 , s o y o u w o u l d e n t e r ' ' x 1 , x 2 , x 3 ' ' o r ' 3 ' ' ' x 1 x 2 x 3 ' ' ( w 1 t h o u t t h e q u o t a t i o n m a r k s t h o u g h ) . ' 4 ' E n t e r a n y d e s c r i p t i o n a n d u n i t s y o u c h o o s e , a l t h o u g h o n l y t h e ' 4 ' f i r s t 5 0 c h a r a c t e r s w i l l b e s t o r e d f o r t h e d e s c r i p t i o n , 2 0 f o r ' 4 ' t h e u n i t s . T h e m a i n p u r p o s e o f a s k i n g f o r t h e s e d e s c r i p t i o n s ' 4 ' i s t h a t t h e y w i l l b e u s e d a s i n f o r m a t i o n o r r e m i n d e r s f o r ' 4 ' f u t u r e u s e r s . ' 5 ' F o r e x a m p l e , i f y o u r e x p r e s s i o n w e r e y = x 1 * x 2 / x 3 , y o u w o u l d ' 5 ' e n t e r ' ' x 1 * x 2 / x 3 ' ' ( w 1 t h o u t t h e q u o t a t i o n m a r k s ) . ' 5 ' I f t h e e x p r e s s i o n i s m o r e t h a n 8 0 c h a r a c t e r s l o n g , p l a c e i t ' 5 ' i n a s e p a r a t e f u n c t i o n . ' 8 ' I f t h e p a r a m e t e r s o f t h e f u n c t i o n a r e a l l l i n e a r l y i n d e p e n d e n t , ' 8 ' t h e n t h e c o r r e l a t i o n c o e f f i c i e n t s a r e a l l z e r o . ' 8 ' I n g e n e r a l , a c o r r e l a t i o n c o e f f i c i e n t c a n t a k e o n a n y v a l u e ' 8 ' b e t w e e n _ 1 . 0 a n d +1 .0, a n d 1 s a m e a s u r e o f t h e d e g r e e o f ' 8 ' l i n e a r c o r r e l a t i o n b e t w e e n t w o r a n d o m v a r i a b l e s . ' O TABLE 5.4 EXAMPLE: THE CHECK TABLE c h e c 1 ( $ , , a n s w e r ) $ G T 3 1 ' V a r i a b l e n a m e s m u s t h a v e n o m o r e t h a n t h r e e c h a r a c t e r s . ' 1 ( $ , , a n s w e r ) $ G T 3 1 c h e c k = 0 2 ( $ , , a n s w e r 1 ) $ G T 5 0 2 ' T h e d e s c r i p t i o n y o u h a v e j u s t e n t e r e d h a s b e e n t r u n c a t e d t o 5 0 c h a r a c t e r s . ' 2 ( $ , , a n s w e r 2 ) $ G T 2 0 2 ' T h e u n i t s y o u h a v e j u s t e n t e r e d h a v e b e e n t r u n c a t e d t o 2 0 c h a r a c t e r s . ' 4 ( $ , , a n s w e r 4 ) $ G T 5 0 4 ' T h e d e s c r i p t i o n y o u h a v e j u s t e n t e r e d h a s b e e n t r u n c a t e d t o 5 0 c h a r a c t e r s . ' 4 ( $ , , a n s w e r 5 ) $ G T 2 0 4 ' T h e u n i t s y o u h a v e j u s t e n t e r e d h a v e b e e n t r u n c a t e d t o 2 0 c h a r a c t e r s . ' 5 ( $ , , a n s w e r G ) $ G T 8 0 5 ' T h e e x p r e s s i o n y o u h a v e j u s t e n t e r e d h a s m o r e t h a n 8 0 c h a r a c t e r s . ' 5 ( $ , , a n s w e r 6 ) $ G T 8 0 5 c h e c k = 0 7 ( ( $ , , $ E X a n s w e r 7 ) $ G T 3 ) | ( ( $ , , $ E X a n s w e r 7 ) $ E 0 2 ) 7 ' E n t e r t h r e e n u m b e r s o n l y : y o u r l o w , m o s t l i k e l y , a n d h i g h e s t i m a t e s . ' 7 ( ( $ , , $ E X a n s w e r 7 ) $ G T 3 ) | ( ( $ , . $ E X a n s w e r 7 ) $ E 0 2 ) 7 c h e c k = 0 8 ( ( + % ( 3 $ , a n s w e r 8 ) $ E 0 ' y e s ' ) $ N E 3 ) & ( ( + % ( 2 $ , a n s w e r 8 ) $ E 0 ' n o ' ) $ N E 2 ) 8 ' Y o u m u s t e n t e r e i t h e r y e s o r n o . ' 8 ( ( + % ( 3 $ , a n s w e r 8 ) $ E Q ' y e s ' ) $ N E 3 ) & ( ( + % ( 2 $ , a n s w e r s ) $ E 0 ' n o ' ) $ N E 2 ) 8 c h e c k = 0 O CO TABLE 5 . 5 EXAMPLE: THE ACTION TABLE a c t i 1 n d e p = s e a r c h d e p a n s w e r O 2 a n s w e r 1 s t o r e d e p a n s w e r 2 3 n i n d = s o r t i n d a n s w e r 3 4 d e s i n d [ n d e p ; c o u n t ; ] = 5 0 $ T A a n s w e r 4 4 u n i n d [ n d e p ; c o u n t ; ] = 2 0 $ T A a n s w e r 5 4 c o u n t = c o u n t + 1 5 e x p r [ n d e p ; ] = 8 0 $ T A a n s w e r 6 7 $ E X ( i n d e p [ n d e p ; c o u n t ; ] , ' = ' , a n s w e r 7 ) 7 c o u n t = c o u n t + 1 9 a n s w e r 9 = 1 0 5 5 $ , ' ' 9 t a b ! e = ( n i n d , n i n d ) $ T A c o e f [ n d e p ; ; ] 1 0 c o u n t = c o u n t + 1 11 s t o r e c o e f a n s w e r 9 12 m e v a r 12 d e r i v 13 e x v a r 13 r e s u l t s 0 TABLE 5 . 6 EXAMPLE: THE FLOW CONTROL TABLE f 1 ow 1 n e x t = ( ( s t o r e d $ E O O ) , ( s t o r e d $ N E O ) ) % 2 , 6 1 c o u n t s 1 2 n e x t = 3 3 n e x t = 4 3 c o u n t = 1 4 n e x t = ( ( c o u n t $ G T n 1 n d ) , ( c o u n t S L E n 1 n d ) ) % 5 , 4 5 n e x t = 6 5 c o u n t = 1 S n e x t = 7 7 n e x t = ( ( c o u n t S L E n i n d ) , ( c o u n t $ G T n 1 n d ) ) % 7 , 8 8 n e x t = ( ((+7.(3$ , a n s w e r 8 ) $ E 0 ' y e s ' ) $ G E 2 ) , ( ( + % ( 3 $ , a n s w e r 8 ) $ E 0 ' y e s ' ) $ L T 2 ) )%9, 12 9 c o u n t = 1 9 n e x t = 1 0 1 0 n e x t = ( ( c o u n t $ L E n 1 n d ) , ( c o u n t $ G T n 1 n d ) ) % 1 0 , 1 1 11 n e x t = 1 2 12 n e x t = 1 3 13 $ > 0 O O 41 5.4 Programming Details 5.4.1 Descriptions of Functions: SEARCHDEP: STOREDEP: SORTIND: STORECOEF: MEVAR: DERIV: EXVAR: RESULTS: checks whether the dependent variable just named by the user is in storage, or whether a new expression is to be entered, stores the description and units of the dependent variable, stores the names of the parameters, stores the correlation coefficients entered by the user, calculates the mean, variance and skewness of each parameter, based on the percentage points (low, probable and high estimates) provided by the user. estimates all first and second partial derivatives of the function. estimates the expected value, variance and skewness of the function. displays the results of the calculations. Listings of these functions are provided in the Appendix. 5.4.2 Flow Control Procedures Usually the lines in the flow control table consist of either a simple assignment statement (eg. next = 2) or a branching statement (eg. next = ((stored $EQ 0), (stored $NE • ) ) % 2, 6). The simple assignment statement is used when the next event is pre-set, regardless of the results of the present event (unless the user enters "escape"). The branching statement is used when the results of the present event determine which event to execute next. If an event is to be 42 repeated a certain number of times, often a counting variable will be required. The counter is given its initial value (usually 0 or 1) in the flow table of the previous event, and is incremented each time the current event action phase is repeated. The flow control phase tests whether the event has been repeated a sufficient number of times. A Sample Run The following run demonstrates many of the features which have been built into the function moments program. This run shows that it is practically impossible to make the program crash, although this depends on how thorough the programmer has been in providing check and default features. User input is indicated with an arrow to the left of the line. TABLE 5 .7 A SAMPLE RUN ) L O A D I N T E R S A V E D 1 3 : 5 9 : 4 2 0 5 % 0 3 % 8 4 W S S I Z E I S 1 0 3 5 1 6 * * * * * * * * * * * B S A M : I N T E R * * * * * * * * * * 1 ) T h i s w o r k s p a c e c a n b e u s e d t o e s t i m a t e t h e m e a n , v a r i a n c e , a n d s k e w n e s s o f a n y g i v e n f u n c t i o n o f r a n d o m v a r i a b l e s . i i ) T h e p r o g r a m w i l l s t o r e u p t o 5 d i f f e r e n t f u n c t i o n s , a n d e a c h f u n c t i o n m a y c o n t a i n u p t o 10 p a r a m e t e r s . i i i ) T o b e g i n e x e c u t i o n , t y p e t h e w o r d ' e x e c u t e ' . i v ) T o e r a s e a l l o f t h e m a t h e m a t i c a l f u n c t i o n s s t o r e d b y t h e p r o g r a m , t y p e t h e w o r d ' c l e a r ' ( n o t w h i l e t h e m a i n p r o g r a m i s e x e c u t i n g t h o u g h ) . v ) I f y o u a r e u n c e r t a i n a s t o h o w t o r e s p o n d t o a n y p a r t i c u l a r p r o m p t , t y p e t h e w o r d ' h e l p ' . v i ) I f a t a n y t i m e y o u w i s h t o e s c a p e f r o m t h e m a i n e x e c u t i o n p r o g r a m , t y p e t h e w o r d ' e s c a p e ' . v i i ) U s e t h e M T S l o g c o m m a n d t o k e e p a r e c o r d o f a t e r m i n a l s e s s i o n . v i i i ) W h e n d a t a e n t r y i s c o m p l e t e ( a f t e r e n t r y o f c o r r e l a t i o n c o e f f i c i e n t s ) , t h e o u t p u t b e g i n s a l m o s t i m m e d i a t e l y , s o b e r e a d y w i t h t h e p a u s e k e y i f y o u w i s h t o v i e w t h e r e s u l t s a s t h e y a p p e a r . i x ) I f , a t a n y t i m e y o u w o u l d l i k e t o s e e t h i s i n t r o d u c t i o n a g a i n , t y p e t h e w o r d ' I n t r o ' . e x e c u t e E n t e r t h e n a m e o f t h e d e p e n d e n t v a r i a b l e t o b e e v a l u a t e d . T h i s i s g e n e r a l l y a n a b b r e v i a t i o n a n d m u s t h a v e n o m o r e t h a n t h r e e c h a r a c t e r s . h e l p T y p e i n t h e n a m e o f t h e q u a n t i t y y o u w i s h c a l c u l a t e d . I f t h i s i s t h e f i r s t t i m e y o u h a v e e n t e r e d t h i s n a m e , t h e n y o u w i l l b e a s k e d t o e n t e r t h e e x p r e s s i o n r e q u i r e d . I f t h e e x p r e s s i o n h a s a l r e a d y b e e n s t o r e d t h e n y o u w i l l n e x t b e a s k e d f o r y o u r e s t i m a t e s o f t h e p a r a m e t e r s . E n t e r t h e n a m e o f t h e d e p e n d e n t v a r i a b l e t o b e e v a l u a t e d . T h i s i s g e n e r a l l y a n a b b r e v i a t i o n a n d m u s t h a v e n o m o r e t h a n t h r e e c h a r a c t e r s . - > y T h e d e p e n d e n t v a r i a b l e y h a s n o t y e t b e e n d e f i n e d E n t e r a b r i e f d e s c r i p t i o n o f t h e d e p e n d e n t v a r i a b l e y . —*- c o s t E n t e r t h e u n i t s t o b e u s e d f o r t h e d e p e n d e n t v a r i a b l e y . d o l i a r s E n t e r t h e n a m e s o f a l l o f t h e v a r i a b l e s r e q u i r e d t o c a l c u l a t e t h e d e p e n d e n t v a r i a b l e y . E n t e r t h e m a l l o n o n e l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . E a c h n a m e m u s t c o n s i s t o f n o m o r e t h a n t h r e e c h a r a c t e r s , b a c k T h e d e p e n d e n t v a r i a b l e y h a s n o t y e t b e e n d e f i n e d E n t e r a b r i e f d e s c r i p t i o n o f t h e d e p e n d e n t v a r i a b l e y . - 9 - h e l p E n t e r t h e u n i t s t o b e u s e d f o r t h e d e p e n d e n t v a r i a b l e y . — > h e l p T h e d e s c r i p t i o n m a y b e j u s t t h e f u l l n a m e o f t h e v a r i a b l e , o r m a y b e m o r e d e t a i l e d , a l t h o u g h n o m o r e t h a n 5 0 c h a r a c t e r s w i l l b e s t o r e d . F o r t h e u n i t s , u p t o 2 0 c h a r a c t e r s w i l l b e s t o r e d . T h e m a i n p u r p o s e o f a s k i n g f o r t h e s e d e s c r i p t i o n s i s t h a t t h e y w i l l b e u s e d t o i n f o r m o r r e m i n d f u t u r e u s e r s . e g . : F o r t h e v a r i a b l e n a m e d 0 t h e d e s c r i p t i o n c o u l d b e ' f l o w ' a n d t h e u n i t s c o u l d b e ' ( m @ > 3 ) / s ' . ( Y o u w o u l d n o t e n t e r t h e q u o t a t i o n m a r k s t h o u g h . ) T h e d e p e n d e n t v a r i a b l e y h a s n o t y e t b e e n d e f i n e d E n t e r a b r i e f d e s c r i p t i o n o f t h e d e p e n d e n t v a r i a b l e y . c o s t E n t e r t h e u n i t s t o b e u s e d f o r t h e d e p e n d e n t v a r i a b l e y . d o l 1 a r s E n t e r t h e n a m e s o f a l l o f t h e v a r i a b l e s r e q u i r e d t o c a l c u l a t e t h e d e p e n d e n t v a r i a b l e y . E n t e r t h e m a l 1 o n o n e l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . E a c h n a m e m u s t c o n s i s t o f n o m o r e t h a n t h r e e c h a r a c t e r s . —>• h e 1 p F o r e x a m p l e , i f t h e e x p r e s s i o n w e r e y = x 1 * x 2 / x 3 , t h e i n d e p e n d e n t w o u l d b e x 1 , x 2 , a n d x 3 , s o y o u w o u l d e n t e r ' x 1 , x 2 , x 3 ' o r ' x 1 x 2 x 3 ' ( w i t h o u t t h e q u o t a t i o n m a r k s t h o u g h ) . E n t e r t h e n a m e s o f a l l o f t h e v a r i a b l e s r e q u i r e d t o c a l c u l a t e t h e d e p e n d e n t v a r i a b l e y . E n t e r t h e m a l l o n o n e l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . E a c h n a m e m u s t c o n s i s t o f n o m o r e t h a n t h r e e c h a r a c t e r s . --=»- x 1 x 2 x 3 E n t e r a b r i e f d e s c r i p t i o n o f t h e v a r i a b l e x 1 . — 1 n f 1 a t i o n E n t e r t h e u n i t s t o b e u s e d f o r t h e v a r i a b l e x1 p e r c e n t E n t e r a b r i e f d e s c r i p t i o n o f t h e v a r i a b l e x 2 . •-=>- i n t e r e s t E n t e r t h e u n i t s t o b e u s e d f o r t h e v a r i a b l e x 2 . -..?»- p e r c e n t E n t e r a b r i e f d e s c r i p t i o n o f t h e v a r i a b l e x 3 — E n t e r t h e u n i t s t o b e u s e d f o r t h e v a r i a b l e x 3 . E n t e r t h e e x p r e s s i o n o r t h e n a m e o f t h e f u n c t i o n t o b e u s e d t o c a l c u l a t e y I f e n t e r i n g a n e x p r e s s i o n , e n t e r t h e r i g h t s i d e o n l y . ( T h e e x p r e s s i o n m u s t b e i n A P L l a n g u a g e a n d i s l i m i t e d t o a m a x i m u m o f 8 0 c h a r a c t e r s i n l e n g t h . ) T h e r e i s n o d e f a u l t o p t i o n i n t h i s c a s e . E n t e r t h e e x p r e s s i o n o r t h e n a m e o f t h e f u n c t i o n t o b e u s e d t o c a l c u l a t e y . I f e n t e r i n g a n e x p r e s s i o n , e n t e r t h e r i g h t s i d e o n l y . ( T h e e x p r e s s i o n m u s t b e i n A P L l a n g u a g e a n d i s l i m i t e d t o a m a x i m u m o f 8 0 c h a r a c t e r s i n l e n g t h . ) h e l p F o r e x a m p l e , i f y o u r e x p r e s s i o n w e r e y = x i * x 2 / x 3 , y o u w o u l d e n t e r ' x 1 * x 2 / x 3 ' ( w i t h o u t t h e q u o t a t i o n m a r k s ) . I f t h e e x p r e s s i o n i s m o r e t h a n 8 0 c h a r a c t e r s l o n g , p l a c e i t i n a s e p a r a t e f u n c t i o n . E n t e r t h e e x p r e s s i o n o r t h e n a m e o f t h e f u n c t i o n t o b e u s e d t o c a l c u l a t e y I f e n t e r i n g a n e x p r e s s i o n , e n t e r t h e r i g h t s i d e o n l y . ( T h e e x p r e s s i o n m u s t b e i n A P L l a n g u a g e a n d i s l i m i t e d t o a m a x i m u m o f 8 0 c h a r a c t e r s i n l e n g t h . ) ( 3 * x 1 @ > 3 ) + ( 2 * x 2 ? > 2 ) + x 3 Y o u w i l l n e x t b e a s k e d t o e n t e r y o u r l o w , m o s t l i k e l y , a n d h i g h e s t i m a t e s o f e a c h o f t h e p a r a m e t e r s . T h e l o w e s t i m a t e i s t h e n u m b e r y o u a r e 9 0 % s u r e w i l l b e e x c e e d e d . T h e m o s t l i k e l y e s t i m a t e i s t h e n u m b e r w h i c h h a s a 5 0 % c h a n c e o f b e i n g e x c e e d e d . T h e h i g h e s t i m a t e h a s o n l y a 10% c h a n c e o f b e i n g e x c e e d e d . F o r e a c h p a r a m e t e r , t h e t h r e e n u m b e r s s h o u l d b e e n t e r e d o n o n e l i n e , s e p a r a t e d b y b l a n k s o r c o m m a s . T h e t h r e e n u m b e r s m a y b e e n t e r e d i n a n y o r d e r . I f a n y o f t h e p a r a m e t e r s i s c e r t a i n , y o u m a y s a v e t i m e i f y o u w i s h b y e n t e r i n g j u s t o n e n u m b e r . E n t e r y o u r e s t i m a t e s o f t h e p a r a m e t e r x1 D e s c r i p t i o n : i n f l a t i o n U n i t s t o b e u s e d : p e r c e n t 5 6 8 E n t e r y o u r e s t i m a t e s o f t h e p a r a m e t e r x 2 D e s c r i p t i o n : i n t e r e s t U n i t s t o b e u s e d : p e r c e n t 1 0 12 E n t e r t h r e e n u m b e r s o n l y : y o u r l o w , m o s t l i k e l y , a n d h i g h e s t i m a t e s . E n t e r y o u r e s t i m a t e s o f t h e p a r a m e t e r x 2 D e s c r i p t i o n : i n t e r e s t U n i t s t o b e u s e d : p e r c e n t >- 1 0 12 14 E n t e r y o u r e s t i m a t e s o f t h e p a r a m e t e r x 3 D e s c r i p t i o n : n o t g i v e n U n i t s t o b e u s e d : n o t g i v e n - . 1 . 3 .4 D o y o u w i s h t o e n t e r o r c h a n g e a n y c o r r e l a t i o n c o e f f i c i e n t s ? E n t e r y e s o r n o . h e 1 p I f t h e p a r a m e t e r s o f t h e f u n c t i o n a r e a l l l i n e a r l y i n d e p e n d e n t , t h e n t h e c o r r e l a t i o n c o e f f i c i e n t s a r e a l l z e r o . I n g e n e r a l , a c o r r e l a t i o n c o e f f i c i e n t c a n t a k e o n a n y v a l u e b e t w e e n _ 1 . 0 a n d + 1 . 0 , a n d i s a m e a s u r e o f t h e d e g r e e o f l i n e a r c o r r e l a t i o n b e t w e e n t w o r a n d o m v a r i a b l e s . D o y o u w i s h t o e n t e r o r c h a n g e a n y c o r r e l a t i o n c o e f f i c i e n t s ? E n t e r y e s o r n o . - 3 - y e s E n t e r t h e c o r r e l a t i o n c o e f f i c i e n t s i n t h e t a b l e b e l o w . J u s t l e a v e b l a n k a n y z e r o c o e f f i c i e n t s . M a k e s u r e t h a t a n y n u m b e r s y o u e n t e r a r e w i t h i n t h e i r p r o p e r c o l u m n b o u n d a r i e s a s d e f i n e d b y t h e c o l u m n h e a d i n g s . x 1 x 2 x 3 x 1 : . 0 0 . 0 0 . 0 0 1 x 2 : . 0 0 . 0 0 . 0 0 . 8 1 x 3 : . 0 0 . 0 0 . 0 0 . 5 . 7 1 c o e f f i c i e n t s b e i n g s t o r e d m e a n s a n d v a r i a n c e s o f i n d e p e n d e n t v a r i a b l e s b e i n g c a l c u l a t e d e x p e c t e d v a l u e a n d v a r i a n c e o f y b e i n g c a l c u l a t e d . R e s u l t s f o r e x p r e s s i o n : y = ( 3 * x 1 M ) + ( 2 * x 2 @ 2 ) + x 3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * E s t i m a t e s o f p a r a m e t e r s : L o w P r o b a b l e H i g h M e a n V a r i a n c e S k e w n e s s x 1 : 5 . 0 0 0 E 0 0 6 . 0 0 0 E O O 8 . 0 0 0 E O O 6 . 2 5 0 E O O 1 . 2 8 2 E O O 2 . 3 2 3 E O O x 2 : 1 . 0 0 0 E 0 1 1 . 2 0 0 E 0 1 1 . 4 0 0 E 0 1 1 . 2 0 0 E 0 1 2 . 2 7 8 E O O 0 . 0 0 0 E 0 0 x 3 : 1 . 0 0 0 E _ 0 1 3 . 0 0 0 E _ 0 1 4 . 0 0 0 E _ 0 1 2 . 7 5 0 E _ 0 1 1 . 2 8 2 E _ 0 2 _ 2 . 3 2 3 E _ 0 3 C o r r e l a t i o n c o e f f i c i e n t s : x 1 x 2 x 3 x 1 : 1 . 0 0 . 8 0 . 5 0 x 2 . 8 0 1 . 0 0 . 7 0 x 3 : . 5 0 . 7 0 1 . 0 0 C o v a r i a n c e s : B e t w e e n x 2 a n d : x 1 : 1 . 3 6 7 0 3 4 5 3 2 B e t w e e n x 3 a n d : x 1 : 0 . 0 6 4 0 7 9 7 4 3 G 8 x 2 : 0 . 1 1 9 6 1 5 5 2 1 5 F i r s t d e r i v a t i v e o f y w i t h r e s p e c t t o : x 1 : 3 5 1 . 9 1 4 1 7 9 7 x 2 : 4 8 . 0 2 4 x 3 : 1 S e c o n d d e r i v a t i v e o f y w i t h r e s p e c t t o x 1 a n d x 1 1 1 2 . G 1 2 5 w i t h r e s p e c t t o x 2 a n d x 1 0 x 2 4 . 0 0 0 0 0 0 0 0 1 w i t h r e s p e c t t o x 3 a n d x 1 0 x 2 0 x 3 0 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * E x p e c t e d v a l u e o f y i s 1 0 9 7 . 4 1 5 4 5 8 * V a r i a n c e o f y i s 3 0 2 3 0 3 . 2 5 3 3 * S t a n d a r d d e v i a t i o n o f y i s 5 4 9 . 8 2 1 1 1 0 3 * T h i r d m o m e n t o f y i s 1 0 1 2 5 0 1 6 1 . 1 * S k e w n e s s c o e f f i c i e n t o f y i s 0 . 6 0 9 1 6 0 1 5 9 1 + **************************************** 1 i s t E x p r e s s i o n s s t o r e d i n t h i s w o r k s p a c e : * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * y = ( 3 * x 1 @ 3 ) + ( 2 * x 2 @ 2 ) + x 3 Y o u m a y s t o r e u p t o 5 e x p r e s s i o n s i n e a c h w o r k s p a c e . 48 C H A P T E R 6 C O N C L U S I O N S A N D F U T U R E D E V E L O P M E N T S This thesis has presented and demonstrated a programming tool which can simplify and speed up the process of writing the dialogue portion of an interactive computer program. The author believes this tool has potential in the field of engineering to help engineers write high-quality interactive programs. Although at first it may seem that the method only complicates matters, once the few simple rules have been learned, the interactive part of a program can be written quickly and efficiently. It is estimated that the programmer would begin to save time almost immediately, probably with the second program written following the C . E . System. Most of the tedious, repetitive aspects of programming the dialogue are taken care of by the driver ("execute") program, and the programmer provides only the particular prompts, checks, action, etc. he wants in each interaction event. Future developments of the C . E . System would mainly consist of adapting the method to languages more commonly used with micro and mini-computers, for example, Basic, C , and Fortran. Since the C . E . System takes advantage of some unique features of APL, major alterations will be required to transfer the method to other languages. 49 LIST OF REFERENCES 1. AHMED, K., D. INGRAM and C. J. DICKINSON (1980) Software for Educational Computing: A General Purpose Driver for Computer-Assisted Instruction, Interrogation and System Simulation ('MACAID'), MTP Press, Lancaster England. 2. ANG, ALFREDO and WILSON TANG (1975) Probability Concepts in Engineering Planning and Design: Volume 1 - Basic Principles, John Wiley and Sons, New York. 3. BENBASAT, IZAK and YAIR WAND (1982) A Structured Approach to Designing Human/Computer Dialogues, UBC Faculty of Commerce and Business Administration, Working Paper No. 835. 4. BENJAMIN, J. R. and C. A. CORNELL(1970) Probability, Statistics, and Decision for Civil Engineers, McGraw-Hill, New York. 5. DAVIDSON, L. B. and D. O. Cooper (1976) "A Simple Way of Developing a Probability Distribution of Present Value", Journal of Petroleum Technology, September 1976. 6. SIDDALL, JAMES N. (1972) Analytical Decision - Making in Engineering Design, Prentice Hall, New Jersey. A P P E N D I X S E L E C T E D P R O G R A M LISTINGS PROGRAM LISTING: THE EXECUTE FUNCTION [ 5 ] [ 6 ] $ ' [ 7 ] $ " [ 8 ] $ • > [ 9 ] " e x e c u t e < # > " " e x e c u t e ; i i i i ; j j j j ; k k k k ; n n n n ; x x x x I ] $ * T h i s p r o g r a m e x e c u t e s t h e p h a s e t a b l e s . [ 2 ] $ * A n i n t e r a c t i o n e v e n t g e n e r a l l y c o n s i s t s o f 6 p h a s e s , [ 3 ] $ * a l t h o u g h n o t a l l S p h a s e s w i l l b e u s e d i n e a c h e v e n t . [ 4 ] $ * i i i i = t h e p h a s e n u m b e r : i i i = 1 m e a n s p r o m p t p h a s e . i i i = 2 m e a n s d e f a u l t p h a s e . i i i = 3 m e a n s h e l p p h a s e , i i i = 4 m e a n s c h e c k p h a s e . i i i = 5 m e a n s a c t i o n p h a s e . 1 0 ] $ * i i i i = 6 m e a n s f l o w c o n t r o l p h a s e . II] $ * j j j j = t h e e v e n t n u m b e r . 1 2 ] $ * E v e n t # 1 i s e x e c u t e d f i r s t . 1 3 ] $ * ' n e x t ' i s t h e n u m b e r o f t h e e v e n t t o f o l l o w t h e c u r r e n t o n e . 1 4 ] n e x t = 1 1 5 ] b a c k u p ^ O 1 6 ] $ * A n y r e s p o n s e f r o m t h e u s e r i s t e m p o r a r i l y 1 7 ] $ * s t o r e d i n t h e c h a r a c t e r a r r a y c a l l e d ' a n s w e r ' . 1 8 ] $ * k k k k i s t h e t h i r d c o o r d i n a a t e o f t h e a r r a y ' c o r r ' , 1 9 ] $ * i n w h i c h t h e r o w n u m b e r s c o r r e s p o n d i n g t o e a c h e v e n t - p h a s e a r e s t o r e d . [ 2 0 ] r e p 7 : k k k k = 1 [ 2 1 ] $ * a n s w e r i s i n i t i a l l y s e t t o ' n o r e s p r e q ' t o h a n d l e e v e n t s w h e r e [ 2 2 ] $ * n o r e s p o n s e i s r e q u i r e d f r o m t h e u s e r . [ 2 3 ] a n s w e r = ' n o r e s p r e q ' [ 2 4 ] j j j j = n e x t [ 2 5 ] $ * x x x x i s a v e c t o r w h i c h d e t e r m i n e s t h e p r o m p t t a b l e c o l u m n s t o b e e x e c u t e d [ 2 6 ] x x x x = 3 $ D R $ . ( $ , p r o m ) [ 2 ] [ 2 7 ] $ * n n n n i s t h e n u m b e r o f t h e p r o m p t t a b l e r o w t o b e e x e c u t e d . [ 2 8 ] r e p 5 : n n n n = ' ' $ , c o r r [ 1 ; j j j j ; k k k k ] [ 2 9 ] $ * I f n n n n = 0 t h e n t h e p r o m p t p h a s e i s c o m p l e t e . [ 3 0 ] $ > ( n n n n $ E 0 O ) % L 5 [ 3 1 ] $ * E x e c u t e l i n e n n n n o f t h e p r o m p t t a b l e . [ 3 2 ] $ E X p r o m [ n n n n ; x x x x ] [ 3 3 ] k k k k = k k k k + 1 [ 3 4 ] $ * E x e c u t e l i n e s u n t i l t h e p r o m p t p h a s e i s c o m p l e t e . [ 3 5 ] $ > r e p 5 [ 3 6 ] $ * I f t h e u s e r g i v e s n o r e s p o n s e . [ 3 7 ] L 5 : $ > ( ( $ , a n s w e r ) $ E Q 0 ) % L 7 [ 3 8 ] $ * I f n o r e s p o n s e i s r e q u i r e d . [ 3 9 ] $ > ( ( ( + % ( 1 1 $ , a n s w e r ) $ E Q ' n o r e s p r e q ' ) $ E 0 1 1 ) 5 ( b a c k u p $ E 0 1 ) ) % U 4 [ 4 0 ] b a c k u p = 0 [ 4 1 ] $ > ( ( + % ( 1 1 $ . a n s w e r ) $ E 0 ' n o r e s p r e q ' ) $ E 0 1 1 ) % L 6 [ 4 2 ] $ * I f t h e u s e r e n t e r s ' e s c a p e ' . [ 4 3 ] $ > ( ( + % ( 6 $ , a n s w e r ) $ E Q ' e s c a p e ' ) $ E 0 6 ) % 0 [ 4 4 ] $ * I f t h e u s e r e n t e r s ' h e l p ' . [ 4 5 ] $ > ( ( + % ( 4 $ . a n s w e r ) $ E Q ' h e l p ' ) $ E Q 4 ) % L 8 [ 4 6 ] $ * I f t h e u s e r e n t e r s ' b a c k ' . [ 4 7 ] $ > ( ( + % ( 4 $ , a n s w e r ) $ E Q ' b a c k ' ) $ G E 3 ) % L 4 [ 4 8 ] $ * I f t h e u s e r e n t e r s a n y t h i n g e l s e ( n u m b e r s , c h a r a c t e r s , e t c . ) . [ 4 9 ] $ > L 9 [ 5 0 ] $ * G o t o p r o m p t p h a s e o f p r e v i o u s e v e n t . [ 5 1 ] 1 4 : n e x t = j j j j - 1 [ 5 2 ] c o u n t = 1 [ 5 3 ] b a c k u p = 1 [ 5 4 ] $ > r e p 7 [ 5 5 ] $ * P r o c e e d t o a c t i o n p h a s e . [ 5 6 ] L 6 : i i i i =5 [ 5 7 ] $ > L 1 0 [ 5 8 ] $ * P r o c e e d t o h e l p p h a s e . [ 5 9 ] L 8 : i f 1 i =3 [ 6 0 ] $ > L 1 0 [ 6 1 ] L 7 : $ * D e f a u l t p h a s e b e g i n s h e r e . [ 6 2 ] k k k k = 1 [ 6 3 ] d e f a u l t = 1 [ 6 4 ] $ * x x x x d e t e r m i n e s t h e c o l u m n n u m b e r s o f d e f a t o b e e x e c u t e d . [ 6 5 ] x x x x = 3 $ D R $ . ( $ , d e f a ) [ 2 ] [ 6 6 ] $ * n n n n i s t h e l i n e n u m b e r o f d e f a t o b e e x e c u t e d . [ 6 7 ] r e p 4 : n n n n = ' ' $ , c o r r [ 2 ; j j j j ; k k k k ] [ 6 8 ] $ * I f n n n n = 0 t h e n t h e d e f a u l t p h a s e i s c o m p l e t e . [ 6 9 ] $ > ( n n n n $ E 0 O ) % L 1 7 [ 7 0 ] S E X d e f a [ n n n n ; x x x x ] [ 7 1 ] k k k k = k k k k + 1 [ 7 2 ] $ * C o n t i n u e t o e x e c u t e l i n e s u n t i l t h e d e f a u l t p h a s e i s c o m p l e t e . [ 7 3 ] $ > r e p 4 [ 7 4 ] L 1 7 : $ > ( d e f a u l t $ E 0 0 ) % L 1 8 [ 7 5 ] $ * P r o c e e d t o a c t i o n p h a s e . [ 7 6 ] $ > L 1 3 [ 7 7 ] L 1 8 : ' T h e r e i s n o d e f a u l t o p t i o n i n t h i s c a s e . ' [ 7 8 ] $ * P r o m p t p h a s e i s r e p e a t e d . [ 7 9 ] $ > r e p 7 [ 8 0 ] $ * C h e c k p h a s e b e g i n s h e r e . [ 8 1 ] L 9 : k k k k = 1 [ 8 2 ] c h e c k = 1 [ 8 3 ] $ * x x x x d e t e r m i n e s t h e c o l u m n n u m b e r s o f c h e c t o b e e x e c u t e d . [ 8 4 ] x x x x = 3 $ 0 R $ . ( $ , c h e c ) [ 2 ] [ 8 5 ] $ * n n n n i s t h e r o w n u m b e r o f c h e c t o b e e x e c u t e d . [ 8 6 ] r e p 8 : n n n n = ' ' $ , c o r r [ 4 ; j j j j ; k k k k ] [ 8 7 ] $ * I f n n n n = 0 t h e n t h e c h e c k p h a s e i s c o m p l e t e . [ 8 8 ] $ > ( n n n n $ E 0 O ) % L 1 5 [ 8 9 ] $ * c o n d i t i o n = 1 o r 0 , d e p e n d i n g o n w h e t h e r t h e t e s t l i n e [ 9 0 ] $ * i n t h e c h e c k a r r a y i s f a l s e o r t r u e , r e s p e c t i v e l y . [ 9 1 ] c o n d i 1 1 o n = $ E X c h e c [ n n n n ; x x x x ] [ 9 2 ] k k k k = k k k k + 1 [ 9 3 ] $ * I f t h e t e s t l i n e i s t r u e , t h e n t h e n e x t l i n e i n t h e c h e c k [ 9 4 ] $ * t a b l e i s e x e c u t e d . I f t h e t e s t l i n e i s f a l s e , t h e n t h e n e x t [ 9 5 ] $ * l i n e i n t h e c h e c k t a b l e i s s k i p p e d . [ 9 6 ] $ > ( c o n d i t i o n $ E 0 0 ) % L 1 6 [ 9 7 ] n n n n = ' ' $ , c o r r [ 4 ; j j j j ; k k k k ] [ 9 8 ] $ > ( n n n n $ E Q 0 ) % L 1 5 [ 9 9 ] S E X c h e c [ n n n n ; x x x x ] [ 1 0 0 ] L 1 6 : k k k k = k k k k + 1 to 1 0 1 ] $ > r e p 8 1 0 2 ] $ • I f c h e c k = 0 t h e n r e p e a t t h e p r o m p t p h a s e o f t h e s a m e e v e n t . 1 0 3 ] $ * I f c h e c k = 1 t h e n p r o c e e d t o a c t i o n p h a s e . 1 0 4 ] L 1 5 : $ > ( c h e c k $ E Q O ) % r e p 7 1 0 5 ] $ * C h e c k p h a s e i s c o m p l e t e . 1 0 6 ] $ > L 1 3 1 0 7 ] $ * H e l p , a c t i o n , a n d f l o w p h a s e s a r e a l l e x e c u t e d b y t h i s n e x t s e c t i o n . 1 0 8 ] L 1 0 : k k k k = 1 1 0 9 ] $ * x x x x i s a v e c t o r w h i c h d e t e r m i n e s t h e p h a s e t a b l e c o l u m n s t o b e e x e c u t e d 1 1 0 ] x x x x = 3 $ D R $ . ( $ , $ E X p h a s e [ 1 1 i i ; ] ) [ 2 ] 1 1 1 ] S * n n n n i s t h e n u m b e r o f t h e p h a s e t a b l e l i n e t o b e e x e c u t e d . 1 1 2 ] r e p 6 : n n n n = ' ' $ , c o r r [ 1 i i i : j j j j ; k k k k ] 1 1 3 ] $ * I f n n n n = 0 t h e n t n e p h a s e i s c o m p l e t e . 1 1 4 ] $ > ( n n n n $ E 0 0 ) % L 1 1 1 1 5 ] $ * E x e c u t e l i n e n n n n o f t h e p h a s e t a b l e . 1 1 6 ] S E X ( S E X p h a s e [ i i i i ; 1 ) [ n n n n ; x x x x ] 1 1 7 ] k k k k = k k k k + 1 1 1 8 ] $ * E x e c u t e l i n e s u n t i l t h e p h a s e i s c o m p l e t e . 1 1 9 ] $ > r e p 6 1 2 0 ] $ * I f i n a c t i o n p h a s e , p r o c e e d t o f l o w c o n t r o l p h a s e . 1 2 1 ] L 1 1 : $ > ( i i i i S E 0 5 ) 7 , L 1 2 1 2 2 ] $ * I f i n h e l p p h a s e , g o b a c k t o p r o m p t p h a s e . 1 2 3 ] $ > ( i i i i S E 0 3 ) % r e p 7 1 2 4 ] $ * I f i n f l o w c o n t r o l p h a s e , p r o c e e d t o n e x t p r o m p t p h a s e . 1 2 5 ] $ > ( i i i i S E 0 6 ) % r e p 7 1 2 6 ] L 1 2 : 1 i i i = 6 1 2 7 ] S > L 1 0 i 1 2 8 ] L 1 3 : i i i i = 5 1 2 9 ] $ > L 1 0 Co PROGRAM LISTING: THE CORRELATE FUNCTION " c o r r e l a t e < # > " " c o r r e I a t e ; x ; x x ; n o 1 ; n e v ; i ; n : k ; J [I] $ * T h i s p r o g r a m s t o r e s . In t h e a r r a y n a m e d 'corr' , t h e r o w [ 2 ] $ * n u m b e r s c o r r e s p o n d i n g t o e a c h e v e n t - p h a s e c o m b i n a t i o n . [ 3 ] $ * T h e a r r a y ' c o r r ' i s u s e d , w h e n t h e m a i n p r o g r a m i s e x e c u t i n g , [ 4 ] $ * t o d e t e r m i n e w h i c h r o w n u m b e r s a r e t o b e e x e c u t e d f o r a [ 5 ] $ * p a r t i c u l a r e v e n t - p h a s e . T h i s i s p r e f e r a b l e t o h a v i n g t h e m a i n [ 6 ] $ * p r o g r a m s e a r c h e a c h p h a s e t a b l e f o r e v e r y e v e n t . [ 7 ] x = 1 2 3 [ 8 ] x x = 3 $ D R $ . 7 0 [ 9 ] $ * T h e s i z e o f ' c o r r ' i s d e t e r m i n e d b y : [ 1 0 ] $ * [ft o f p h a s e s ; tt o f e v e n t s ; m a x . tt o f l i n e s i n a n y e v e n t - p h a s e ] [ I I ] c o r r = 6 13 1 0 $ , 0 [ 1 2 ] $ * i = p h a s e n u m b e r = f i r s t c o o r d i n a t e o f t h e a r r a y ' c o r r ' . [ 1 3 ] 1=1 [ 1 4 ] $* n=row n u m b e r o f p h a s e t a b l e [ 1 5 ] r e p 2 : n = 1 [ 1 6 ] $ * k = t h e t h i r d c o o r d i n a t e o f t h e a r r a y ' c o r r ' . [ 1 7 ] r e p O : k = 1 [ 1 8 ] $ * j = e v e n t n u m b e r = t h e s e c o n d c o o r d i n a t e o f t h e a r r a y ' c o r r ' . [ 1 9 ] j = $ E X ( $ E X p h a s e [ 1 ; ] ) [ n ; x ] [ 2 0 ] $ * T h e r o w n u m b e r o f t h e e v e n t - p h a s e i s s t o r e d i n ' c o r r ' . [ 2 1 ] r e p 1 : c o r r [ i ; j ; k ] =n [ 2 2 ] $ * I f t h e e v e n t n u m b e r o f t h e n e x t r o w i s t h e s a m e , t h e n [ 2 3 ] $ * n a n d k a r e i n c r e a s e d b y o n e . I f t h e e v e n t n u m b e r o f t h e n e x t [ 2 4 ] $ * r o w i s d i f f e r e n t , t h e n n i s i n c r e a s e d b y o n e . [ 2 5 ] $ > ( ( $ E X ( $ E X p h a s e [ 1 ; ] ) { n + 1 ; x ] ) $ N E j ) % L 1 [ 2 6 ] n = n + 1 [ 2 7 ] k = k + 1 [ 2 8 ] $ > r e p 1 [ 2 9 ] L 1 : n = n + 1 [ 3 0 ] $ * I f t h e e v e n t n u m b e r i s 0 , t h e n g o t o t h e n e x t p h a s e . [ 3 1] $ > ( ( $ E X ( $ E X p h a s e [ i ; ] ) [ n ; x ] ) $ E 0 0 ) % L 2 [ 3 2 ] $ > r e p O [ 3 3 ] $ * R e p e a t f o r e a c h o f t h e 6 p h a s e s . [ 3 4 ] L 2 : $ > ( i $ E Q 6 ) % 0 [ 3 5 ] i = i + 1 [ 3 6 ] $ > r e p 2 PROGRAM LISTING: FUNCTIONS USED IN THE COMPREHENSIVE EXAMPLE s e a r c h d e p < # > " " x x x x = s e a r c h d e p a n s w e r O ; i i i i ; n d e p ; s t r i n g ; J j j j ; 1 a s t ; x x x x I ] $ * T h i s p r o g r a m s e a r c h e s t h e a r r a y ' d e p e n ' ( w h i c h c o n t a i n s t h e 2 ] $ * n a m e s o f a l l o f t h e d e p e n d e n t v a r i a b l e s c u r r e n t l y s t o r e d ) 3 ] $ * f o r t h e d e p e n d e n t v a r i a b l e j u s t n a m e d b y t h e u s e r . 4 ] $ * I f t h e n a m e i s f o u n d , t h e n i t s p o s i t i o n i n t h e a r r a y ' d e p e n ' 5 ] $ * i s r e c o r d e d , a n d t h e n u m b e r o f p a r a m e t e r s c o r r e s p o n d i n g t o 6 ] $ * t h a t d e p e n d e n t v a r i a b l e i s d e t e r m i n e d . 7 ] $ * I f t h e n a m e i s n o t f o u n d , a n d t h e r e i s n o m o r e s p a c e 8 ] $ * a v a i l a b l e t o s t o r e a n e w e x p r e s s i o n ( u p t o 5 a r e p e r m i t t e d ) , 9 ] $ * t h e n t h e u s e r i s s e n t a n a p p r o p r i a t e m e s s a g e . 1 0 ] $ * I f t h e n a m e i s n o t f o n d , a n d t h e r e i s s p a c e a v a i l a b l e f o r a I I ] $ * n e w e x p r e s s i o n , t h e n t h e n e w n a m e i s a d d e d t o ' d e p e n ' . 1 2 ] $ * I f t h e n a m e i s f o u n d , b u t n o c o r r e s p o n d i n g p a r a m e t e r n a m e s 1 3 ] $ * a r e f o u n d i n ' i n d e p ' , t h e n a n a p p r o p r i a t e m e s s a g e i s s e n t 1 4 ] $ * t o t h e u s e r . 1 5 ] a n s w e r 0 = 3 $ T A a n s w e r 0 1 6 ] i i i 1 = 1 1 7 ] r e p 1 : $ > ( i i i i $ G T 5 ) % L 2 1 8 ] $ > ( ( + % a n s w e r O $ E Q d e p e n [ 1 1 i 1 ; ] ) $ E Q 3 ) % L 1 1 9 ] i i i i = i i i i + 1 2 0 ] $ > r e p 1 2 1] L 1 ; x x x x = 1 i i i 2 2 ] s t o r e d = 1 2 3 ] s t r i n g = , i n d e p [ i i i 1 ; ; ] 2 4 ] j j j j = 0 2 5 ] r e p 2 : 1 a s t = _ 1 $ T A s t r i n g 2 6 ] s t r i n g = _ 1 $ D R s t r i n g 2 7 ] $ > ( l a s t $ N E ' ' ) % L 3 2 8 ] J j j j = j j j j + 1 2 9 ] $ > ( j j j j $ G E 3 2 ) % L 6 3 0 ] $ > r e p 2 3 1 ] L 3 : n i n d = $ M A ( 3 0 - j j j j ) / 3 3 2 ] $ > 0 3 3 ] L 2 : k k k k = 1 3 4 ] s t o r e d = 0 3 5 ] r e p 3 : $ > ( ( + % d e p e n [ k k k k ; ] $ E 0 ' ' ) $ E Q 3 ) % L 4 3 6 ] k k k k = k k k k + 1 3 7 ] $ > ( k k k k $ G E 6 ) % L 5 3 8 ] $ > r e p 3 3 9 ] L 4 : x x x x = k k k k 4 0 ] d e p e n [ k k k k ; ] = a n s w e r O 4 1 ] $ > 0 4 2 ] L 5 : ' Y o u h a v e a l r e a d y s t o r e d f i v e e x p r e s s i o n s i n t h i s w o r k s p a c e , ' 4 3 ] ' a n d n o m o r e r o o m i s a v a i l a b l e . S t o p e x e c u t i o n b y t y p i n g e s c a p e ' 4 4 ] ' i n r e s p o n s e t o t h e n e x t p r o m p t . T h e n u s e t h e c l e a r o r e r a s e ' 4 5 ] ' c o m m a n d t o c l e a r e x p r e s s i o n s y o u n o l o n g e r n e e d . I f y o u d o n o t ' 4 6 ] ' w a n t t o e r a s e a n y o f t h e e x p r e s s i o n s s t o r e d , t h e n c o p y I N T E R ' 4 7 ] ' t o a n e w w o r k s p a c e . ' 4 8 ] x x x x = 5 4 9 ] $ > 0 5 0 ] L 6 : ' T h e r e i s n o e x p r e s s i o n s t o r e d f o r t h e v a r i a b l e y o u h a v e n a m e d . ' 5 1 ] ' Y o u m u s t s t o p e x e c u t i o n , e r a s e t h e v a r i a b l e n a m e f r o m s t o r a g e , ' 5 2 ] ' a n d r e - d e f i n e t h e v a r i a b l e a n d i t s e x p r e s s i o n . ' 5 3 ] $ > 0 " s t o r e d e p < # > " " a n s w e r 1 s t o r e d e p a n s w e r 2 [ 1 ] $ * T h i s p r o g r a m s t o r e s t h e d e s c r i p t i o n o f t h e d e p e n d e n t v a r i a b l e [ 2 ] $ * i n t h e a r r a y ' d e s d e p ' a n d t h e u n i t s i n t h e a r r a y ' u n d e p ' . [ 3 ] d e s d e p t n d e p ; ] = 5 0 $ T A a n s w e r 1 [ 4 ] u n d e p [ n d e p ; ] = 2 0 $ T A a n s w e r 2 [ 5 ] $ > 0 " s o r t i n d < # > " " y y y y = s o r t i n d a n s w e r ; i i i i ; j j j j ; x x x x ; y y y y ; z z z z : 1 i m i t : c o u n t [ I ] $ * T h i s p r o g r a m s o r t s t h e c h a r a c t e r s t r i n g c o n t a i n i n g t h e p a r a m e t e r [ 2 ] $ * n a m e s i n t o o n e s t r i n g p e r n a m e , a n d s t o r e s t h e m i n t h e a r r a y ' i n d e p ' . [ 3 ] $ * T h e p r o g r a m r e t u r n s t h e n u m b e r o f p a r a m e t e r n a m e s f o u n d . 14] i i i i = n d e p [ 5 ] y y y y = j j j j = o [ 6 ] 1 i m i t = 2 + $ . a n s w e r [ 7 ] c o u n t = 0 [ 8 ] r e p 1 : x x x x = 1 S T A a n s w e r [ 9 ] a n s w e r = 1 $ D R a n s w e r [ 1 0 ] c o u n t = c o u n t + 1 [ I I ] $ > ( c o u n t $ E Q l i m i t ) % 0 [ 1 2 ] $ > ( ( x x x x $ E 0 ' ' ) | ( x x x x $ E 0 ' , ' ) ) % r e p 1 [ 1 3 ] j j j j = j j j j + 1 [ 1 4 ] z z z z = " [ 1 5 ] r e p 2 : z z z z = z z z z . x x x x [ 1 6 ] x x x x = 1 $ T A a n s w e r [ 1 7 ] a n s w e r = 1 S D R a n s w e r [ 1 8 ] c o u n t = c o u n t + 1 [ 1 9 ] $ > ( c o u n t $ E Q l i m i t ) % 0 [ 2 0 ] $ > ( ( x x x x $ E 0 ' ' ) | ( x x x x S E O ' , ' ) ) % L 1 [ 2 1 ] $ > r e p 2 [ 2 2 ] L 1 : i n d e p t i i i i : j j j j ; ] = 3 $ T A z z z z [ 2 3 ] y y y y = j j j j • [ 2 4 ] $ > r e p 1 " s t o r e c o e f < # > " " s t o r e c o e f a n s w e r 9 ; i i 1 i ; a a a a ; j j j j [ I ] $ * T h i s p r o g r a m s t o r e s t h e c o r r e l a t i o n c o e f f i c i e n t s i n t h e a r r a y ' c o e f ' . [ 2 ] 1 i 1 1 = 1 [ 3 ] r e p 0 : j j j j = 0 [ 4 ] r e p 1 : a n s w e r 9 [ i i i i ; ] = 5 $ R 0 a n s w e r 9 [ i 1 i 1 ; ] [ 5 ] a a a a = 5 $ T A a n s w e r 9 [ i i 1 i ; ] [ 6 ] j j j j = j j j j + 1 [ 7 ] $ > ( ( + % a a a a $ E Q ' ' ) $ E 0 5 ) % L 1 [ 8 ] c o e f [ n d e p ; i 1 I i ; j j j j ] = c o e f [ n d e p ; j j j j ; i 1 i i ] = $ E X a a a a [ 9 ] L 1 ; $ > ( j j j j $ E 0 n i n d ) % L 2 [ 1 0 ] $ > r e p 1 [ I I ] L 2 : i 1 i i = i 1 i i + 1 [ 1 2 ] $ > ( i i i i $ G T n i n d ) % 0 [ 1 3 ] $ > r e p O " m e v a r < * ' > " " m e v a r ; j j j j ; i n d e x ; z z z z [ I ] $ * T h i s p r o g r a m e s t i m a t e s t h e m e a n s , v a r i a n c e s , a n d t h i r d m o m e n t s [ 2 ] $ * o f t h e p a r a m e t e r s . [ 3 ] $ * ' m i n d ' i s a v e c t o r c o n t a i n i n g t h e m e a n s o f t h e i n d e p e n d e n t v a r i a b l e s . [ 4 ] $ * ' v i n d ' i s a v e c t o r c o n t a i n i n g t h e v a r i a n c e s o f t h e i n d e p e n d e n t v a r i a b l e s . [ 5 ] $ * ' o r d e r ' i s a n i n d x 3 m a t r i x c o n t a i n i n g t h e o r d e r e d v a l u e s . [ 6 ] o r d e r = ( n i n d , 3 ) $ . 0 [ 7 ] m i n d = 1 0 $ , 0 [ 8 ] v i n d = 1 0 $ , 0 [ 9 ] t h m o m = 1 0 $ , 0 [ 1 0 ] j j j j = 1 [ I I ] $ * I f o n l y a s i n g l e v a l u e h a s b e e n e n t e r e d f o r t h e p a r a m e t e r , [ 1 2 ] $ * g o t o 1 i n e L 1 . [ 1 3 ] r e p 1 : $ > ( ( $ . $ , S E X i n d e p [ n d e p ; j j j j ; ] ) $ E 0 O ) % L 1 [ 1 4 ] $ * P u t t h e t h r e e e s t i m a t e s i n i n c r e a s i n g o r d e r . [ 1 5 ] i n d e x = $ G U $ E X i n d e p [ n d e p ; j j j j ; ] [ 1 6 ] z z z z = ( $ E X i n d e p [ n d e p ; J j j j ; ] ) [ i n d e x ] [ 1 7 ] o r d e r [ j j j j ; ] = z z z z [ 1 8 ] $ * C a l c u l a t e t h e m e a n . [ 1 9 ] $ E X ( i n d e p [ n d e p ; j j j j ; ] . ' = m i n d [ j j j j ] = 0 . 2 5 * z z z z [ 2 ] + + % z z z z ' ) [ 2 0 ] $ * C a l c u l a t e t h e v a r i a n c e . [ 2 1] v i n d f j j j j ] = ( ( z z z z [ 3 ] - z z z z [ 1 ] ) / 2 . 6 5 ) 0 2 [ 2 2 ] $ * T e s t f o r s y m m e t r y o f t h e p a r a m e t e r ' s d i s t r i b u t i o n . [ 2 3 ] $ > ( ( 2 * z z z z [ 2 ] ) $ E 0 ( z z z z [ 1 ] + z z z z [ 3 ] ) ) % L 4 [ 2 4 ] $ * C a l c u l a t e t h e s t a n d a r d d e v i a t i o n . [ 2 5 ] s t d e v = ( z z z z [ 3 ] - z z z z [ 1 ] ) / 2 . 6 5 [ 2 6 ] $ * C a l c u l a t e t h e s h i f t r e q u i r e d t o f i t a l o g n o r m a l d i s t r i b u t i o n . [ 2 7 ] s h i f t = ( ( z z z z [ 3 ] * z z z z [ 1 ] ) - z z z z [ 2 ] ® 2 ) / ( 2 * z z z z [ 2 ] ) - z z z z [ 3 ] + z z z z [ 1 ] [ 2 8 ] $ * C a l c u l a t e t h e s t a n d a r d d e v i a t i o n o f t h e l o g . [ 2 9 ] s t d l n = ( $ p ( ( z z z z [ 3 ] + s h i f t ) / z z z z [ 1 ] + s h i f t ) ) / 2 . 6 5 [ 3 0 ] $ * c a l c u l a t e t h e m e a n . [ 3 1 ] m e a n = ( z z z z [ 2 ] + s h i f t ) * « » 0 . 5 * s t d l n < 3 2 [ 3 2 ] $ * E s t i m a t e t h e t h i r d c e n t r a l m o m e n t [ 3 3 ] t h m o m [ j j j j ] = ( ( 3 * s t d e v @ 4 ) / m e a n ) + ( stdev<§>6)/mean@3 [ 3 4 ] $ > L 2 [ 3 5 ] L 1 : m i n d [ j j j j ] = $ E X i n d e p [ n d e p ; j j j j ; ] [ 3 6 ] o r d e r [ J j j j ; ] = 3 $ , m 1 n d [ j j j j ] [ 3 7 ] v i n d [ j j j j ] = 0 [ 3 8 ] L 4 : t h m o m [ j j j j ] = 0 [ 3 9 ] $ * R e p e a t f o r e a c h p a r a m e t e r . [ 4 0 ] L 2 : $ > ( j j J j $ E 0 n 1 n d ) ° / , L 3 [ 4 1 ] j j j j = j j j j + 1 [ 4 2 ] $ > r e p 1 [ 4 3 ] $ * C a l c u l a t e t h e c o v a r i a n c e s . [ 4 4 ] L 3 : c o v a r [ n d e p ; ; ] = ( 1 0 10 $ , 0 1 1 1 1 1 1 1 1 1 1 ) * c o e f [ n d e p ; ; ] * ( 1 0 1 $ , ( v i n d @ 0 . 5 ) ) + . * 1 1 0 $ , ( v i n d < a 0 . 5 ) [ 4 5 ] $ > 0 " d e r i v < # > " " d e r i v ; a a a a ; b b b b ; c c c c ; d d d d ; i i 1 i ; j j j j ; t t 1 1 ; t t t 2 [ I ] $ * T h i s p r o g r a m c a l c u l a t e s n u m e r i c a l l y t h e f i r s t a n d s e c o n d p a r t i [ 2 ] $ * d e r i v a t i v e s o f t h e e x p r e s s i o n w . r . t a l l o f i t s p a r a m e t e r s . [ 3 j i i 1 i = 1 [ 4 ] r e p 2 : j j j j = 1 [ 5 ] $ * t t t 1 = t h e m e a n o f p a r a m e t e r i i i i . [ 6 ] t t t 1 = $ E X i n d e p [ n d e p ; i i i i ; ] [ 7 ] $ * T h e c a s e w h e r e i i i 1 = j j j j i s h a n d l e d s e p a r a t e l y . [ 8 ] r e p 1 : $ > ( 1 i i i $ E O j j j j ) % L 1 [ 9 ] $ * t t t 2 = t h e m e a n o f p a r a m e t e r j j j j . [ 1 0 ] t t t 2 = $ E X i n d e p [ n d e p ; j j j j ; ] [ I I ] $ * a a a a = t h e e x p r e s s i o n e v a l u a t e d a t t h e p a r a m e t e r m e a n s . [ 1 2 ] a a a a = $ E X e x p r [ n d e p ; ] [ 1 3 ] $ * P a r a m e t e r i i i i i s i n c r e a s e d b y 0 . 1 % . [ 1 4 ] $ E X ( i n d e p [ n d e p ; i i i i ; ] , ' = 1 . 0 0 1 * ' , i n d e p [ n d e p ; i 1 i i ; ] ) [ 1 5 ] $ * T h e e x p r e s s i o n i s e v a l u a t e d a g a i n . [ 1 6 ] b b b b = $ E X e x p r [ n d e p ; ] [ 1 7 ] $ * P a r a m e t e r j j j j i s i n c r e a s e d b y 0 . 1 % . [ 1 8 ] $ E X ( 1 n d e p [ n d e p ; j j j J ; ] , ' = 1 . 0 0 1 * ' , 1 n d e p [ n d e p ; j j j j ; ] ) [ 1 9 ] $ * T h e e x p r e s s i o n i s e v a l u a t e d a g a i n . [ 2 0 ] d d d d = $ E X e x p r [ n d e p ; ] [ 2 1 ] $ * P a r a m e t e r i i i i i s r e s e t t o i t s m e a n v a l u e . [ 2 2 ] $ E X ( i n d e p [ n d e p ; i i i i ; ] , ' = t t t 1 ' ) [ 2 3 ] $ * T h e e x p r e s s i o n i s e v a l u a t e d a g a i n . [ 2 4 ] c c c c = $ E X e x p r [ n d e p ; ] [ 2 5 ] $ * P a r a m e t e r j j j j i s r e s e t t o i t s m e a n v a l u e . [ 2 6 ] $ E X ( i n d e p [ n d e p ; J j j j ; ] , ' = t t t 2 ' ) [ 2 7 ] $ * T h e s e c o n d d e r i v a t i v e i s e s t i m a t e d n u m e r i c a l l y . [ 2 8 ] s d e r [ n d e p ; i 1 1 i ; J j j j ] = s d e r [ n d e p ; j j j j ; i 1 i i ] = ( d d d d + a a a a - c c c c + b b b b ) / 1 E _ 6 [ 2 9 ] $ * j j j j i s i n c r e m e n t e d a n d t h e p r e v i o u s c a l c u l a t i o n s r e p e a t e d [ 3 0 ] $ * u n t i l j j j j = 1 1 i 1 . [ 3 1 ] j j j j = j j j j + 1 [ 3 2 ] $ > r e p 1 [ 3 3 ] $ * T h e c a s e w h e r e i i i i = j j j j . [ 3 4 ] $ + a a a a = t h e e x p r e s s i o n e v a l u a t e d a t t h e p a r a m e t e r m e a n s . [ 3 5 ] L 1 : a a a a = $ E X e x p r [ n d e p ; ] [ 3 6 ] $ * P a r a m e t e r i i i i i s i n c r e a s e d b y 0 . 1 % . [ 3 7 ] $ E X ( i n d e p [ n d e p ; i i 1 i ; ] , ' = 1 . 0 0 1 * t t t 1 ' ) [ 3 8 ] $ * T h e e x p r e s s i o n i s e v a l u a t e d a g a i n . [ 3 9 ] b b b b = $ E X e x p r [ n d e p ; ] [ 4 0 ] $ * P a r a m e t e r i i i i i s I n c r e a s e d b y a n o t h e r 0 . 1 % . [ 4 1 ] $ E X ( i n d e p [ n d e p ; i i 1 i ; ] , ' = 1 . 0 0 2 * t t t 1 ' ) [ 4 2 ] $ * T h e e x p r e s s i o n i s e v a l u a t e d a g a i n . [ 4 3 ] c c c c = $ E X e x p r [ n d e p ; ] [ 4 4 ] $ * T h e f i r s t d e r i v a t i v e i s e s t i m a t e d n u m e r i c a l l y . [ 4 5 ] f d e r [ n d e p ; 1 i i i ] = ( b b b b - a a a a ) / 0 . 0 0 1 *1111 [ 4 6 ] $ * T h e s e c o n d d e r i v a t i v e i s e s t i m a t e d n u m e r i c a l l y . [ 4 7 ] s d e r [ n d e p ; i i i i ; i i i 1 ] = ( a a a a + c c c c - 2 * b b b b ) / 1 E_6*1111<°>2 [ 4 8 ] $ * P a r a m e t e r 1 i i i i s r e s e t t o i t s m e a n v a l u e . [ 4 9 ] $ E X ( i n d e p [ n d e p ; i i i 1 ; ] , ' = t t t 1 ' ) [ 5 0 ] $ * T h e p r o c e s s i s r e p e a t e d f o r a l l c o m b i n a t i o n s o f i i i i a n d [ 5 1 ] $ * j j j j f o r w h i c h j j j j J L E i i i i . [ 5 2 ] i i i i = i i i i + 1 [ 5 3 ] $ > ( i i i i $ G T n i n d ) % 0 [ 5 4 ] $ > r e p 2 Co " r e s u 1 t s < # > " " r e s u I t s ; i ; j ; t a b l e [ 1 ] $ * T h i s p r o g r a m p r i n t s t h e r e s u l t s o f a l l o f t h e c a l c u l a t i o n s . [ 2 ] ' ' [ 3 ] ' ' [ 4 ] ' R e s u l t s f o r e x p r e s s i o n : ' , d e p e n [ n d e p ; ] , ' = ' , e x p r [ n d e p ; ] [ 5 ] 7 0 $ . ' * ' [ 6 ] ' ' [ 7 ] ' E s t i m a t e s o f p a r a m e t e r s : ' [ 8 ] 2 4 $ , ' _ ' [ 9 ] ( 1 0 $ , ' ' ) , ' L o w P r o b a b l e H i g h M e a n V a r i a n c e [ 1 0 ] ( 7 $ , ' ' ) , 6 G $ . ' ' [ 1 1 ] i = 1 [ 1 2 ] r e p 1 : i n d e p [ n d e p ; 1 ; ] , ' : ' , ( 1 1 _ 4 $ F M ( o r d e r [ 1 ; 1 ] , o r d e r [ i ; 2 ] , o r d e r [ . v i n d [ 1 ] , t h m o m [ i ] ) ) [ 1 3 ] i = 1 + 1 [ 1 4 ] $ > ( i $ G T n i n d ) % L 1 [ 1 5 ] $ > r e p 1 [ 1 6 ] L 1 : ' ' [ 1 7 ] ' C o r r e l a t i o n c o e f f i c i e n t s : ' [ 1 8 ] 2 5 $ , ' _ ' [ 1 9 ] h e a d i n g [ 2 0 ] t a b 1 e = ( n i n d , n i n d ) $ T A c o e f [ n d e p ; ; ] [ 2 1] i = 1 [ 2 2 ] r e p 2 : i n d e p [ n d e p ; i ; ] , ' : ' , ( 5 2 $ F M t a b 1 e [ i ; ] ) [ 2 3 ] i = i + 1 [ 2 4 ] $ > ( i $ G T n i n d ) % L 2 [ 2 5 ] $ > r e p 2 [ 2 6 ] L 2 : ' ' [ 2 7 ] ' C o v a r i a n c e s : ' [ 2 8 ] 1 2 $ , ' _ ' [ 2 9 ] 1=2 [ 3 0 ] r e p 4 : j = 1 [ 3 1 ] ' ' [ 3 2 ] ' B e t w e e n ' , 1 n d e p [ n d e p ; i ; ] , ' a n d : ' [ 3 3 ] r e p 3 : i n d e p [ n d e p ; j ; ] , ' : ' , S F M c o v a r [ n d e p : i ; j ] [ 3 4 ] j = j + 1 [ 3 5 ] $ > ( j $ L T i ) % r e p 3 [ 3 6 ] i = i + 1 [ 3 7 ] $ > ( i $ L E n i n d ) % r e p 4 [ 3 8 ] [ 3 9 ] ' F i r s t d e r i v a t i v e o f ' , d e p e n [ n d e p ; ] , ' : ' [ 4 0 ] 2 5 $ , ' _ ' [ 4 1 ] ' w i t h r e s p e c t t o : ' [ 4 2 ] 1=1 [ 4 3 ] r e p 5 : i n d e p [ n d e p ; i ; ] , ' : ' , $ F M f d e r [ n d e p ; i ] [ 4 4 ] i = 1 + 1 [ 4 5 ] $ > ( i $ L E n i n d)7 . r e p 5 [ 4 6 ] ' ' [ 4 7 ] ' S e c o n d d e r i v a t i v e o f ' , d e p e n [ n d e p ; ] , ' : ' [ 4 8 ] 2 6 $ . ' _ ' [ 4 9 ] i = 1 [ 5 0 ] r e p 6 : j = 1 [ 5 1 ] ' w i t h r e s p e c t t o ' , i n d e p [ n d e p ; i ; ] , ' a n d : ' [ 5 2 ] r e p 7 : i n d e p [ n d e p ; j : ] . ' : ' . S F M s d e r [ n d e p ; i ; j ] S k e w n e s s ' 1 ; 3 ] , m i n d [ i ] Ln [ 5 3 ] j = j + 1 [ 5 4 ] $ > ( j $ L E i ) % r e p 7 [ 5 5 ] 1=1+1 [ 5 6 ] ' ' [ 5 7 ] $ > ( i $ L E n i n d ) % r e p 6 [ 5 8 ] 4 0 $ , ' * ' [ 5 9 ] ' * ' [ 6 0 ] ' * E x p e c t e d v a l u e o f ' , d e p e n [ n d e p ; ] , ' i s ' , $ F M e x v a 1 [ n d e p ] [ 6 1 ] ' * V a r i a n c e o f ' , d e p e n [ n d e p ; ] . ' i s ' , S F M v a r 1 [ n d e p ] [ 6 2 ] ' * S t a n d a r d d e v i a t i o n o f ' , d e p e n f n d e p ; ] , ' 1 s ' , $ F M v a r i [ n d e p ]<?0. 5 [ 6 3 ] ' * T h i r d m o m e n t o f ' . d e p e n [ n d e p ; ] , ' i s ' , $ F M s k e w [ n d e p ] [ 6 4 ] ' * S k e w n e s s c o e f f i c i e n t o f ' , d e p e n [ n d e p ; ] , ' i s ' , $ F M s k e w c o [ n d e p ] [ 6 5 ] ' * ' [ 6 6 ] 4 0 $ , ' * ' " e x v a r < # > " " e x v a r [ I ] $ * T h i s p r o g r a m i s u s e d t o c a l c u l a t e t h e e x p e c t e d v a l u e , v a r i a n c e , [ 2 ] $ * a n d s k e w n e s s o f t h e d e p e n d e n t v a r i a b l e s . [ 3 ] $"* s d e r 2 i s a v e c t o r c o n t a i n i n g t h e s e c o n d p a r t i a l d e r i v a t i v e s [ 4 ] $ * w . r . t e a c h o f t h e p a r a m e t e r s , o b t a i n e d b y t a k i n g t h e [ 5 ] $ * d i a g o n a l e l e m e n t s f r o m t h e s d e r m a t r i x . [ 6 ] s d e r 2 = + $ C 1 ( 1 0 1 0 $ , 1 0 0 0 0 0 0 0 0 0 0 ) * s d e r [ n d e p ; ; ] [ 7 ] $ * T h e e x p e c t e d v a l u e i s c a l c u l a t e d . [ 8 ] e x v a l [ n d e p ] = ( $ E X e x p r [ n d e p ; ] ) + 0 . 5 * (+%+$C 1 s d e r [ n d e p ; ; ] * c o v a r [ n d e p ; ; ] ) + + % s d e t - 2 * v i n d [ 9 ] $ * T h e v a r i a n c e i s c a l c u l a t e d a s a s u m o f t h r e e t e r m s . [ 1 0 ] t e r m l = (+%v i n d * f d e r [ n d e p ; ] * f d e r [ n d e p ; ] ) [ I I ] . t e r m 2 = + % + $ C 1 c o v a r [ n d e p ; ; ] * ( ( 1 0 , 1 ) $ . f d e r [ n d e p ; ] ) + . * ( 1 , 1 0 ) $ . f d e r [ n d e p ; ] [ 1 2 ] t e r m 3 = + % f d e r [ n d e p ; ] * s d e r 2 * t h m o m [ 1 3 ] v a r i [ n d e p ] = t e r m 1 + t e r m 2 + t e r m 3 [ 1 4 ] $ * S k e w n e s s a n d s k e w n e s s c o e f f i c i e n t a r e c a l c u l a t e d . [ 1 5 ] s k e w [ n d e p ] = + % ( f d e r [ n d e p ; ] @ > 3 ) * t h m o m [ 1 6 ] s k e w c o [ n d e p ] = s k e w [ n d e p ] / v a r i [ n d e p ] @ 1 . 5 [ 1 7 ] $ > 0 

Cite

Citation Scheme:

        

Citations by CSL (citeproc-js)

Usage Statistics

Share

Embed

Customize your widget with the following options, then copy and paste the code below into the HTML of your page to embed this item in your website.
                        
                            <div id="ubcOpenCollectionsWidgetDisplay">
                            <script id="ubcOpenCollectionsWidget"
                            src="{[{embed.src}]}"
                            data-item="{[{embed.item}]}"
                            data-collection="{[{embed.collection}]}"
                            data-metadata="{[{embed.showMetadata}]}"
                            data-width="{[{embed.width}]}"
                            async >
                            </script>
                            </div>
                        
                    
IIIF logo Our image viewer uses the IIIF 2.0 standard. To load this item in other compatible viewers, use this url:
http://iiif.library.ubc.ca/presentation/dsp.831.1-0062946/manifest

Comment

Related Items