Download Understanding Algorithmic Operations & Developing Computer Solutions and more Slides Calculus for Engineers in PDF only on Docsity!
Learning Goals
- Write MATLAB Programs That can MAKE
“Logical” Decisions that Affect Program
Output
- Write Programs that Employ
LOOPing Processes
- For → No. Loops know a priori
- while → Loop Terminates based on Logic Criteria
- Use the MATLAB DeBugger to
Correct Errors (time permitting)
What’s an “Algorithm”
A postage stamp issued by the USSR in 1983 to commemorate the 1200th anniversary of Muhammad al-Khowarizmi , after whom algorithms are named.
Algorithmic Operations
1. SEQUENTIAL OPERATIONS →
Instructions executed in order
- CONDITIONAL OPERATIONS → Control structures that first ask a question to be answered with a true/false response and then select the next instruction based on the answer
- ITERATIVE OPERATIONS (LOOPS): Control structures that repeat the execution of a block of instructions
Structured Programming
• STRUCTURED PROGRAMMING ≡
A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure withOUT UNconditional branches to higher levels of the structure. Three types of control flow are used: (1) sequential , (2) test , and (3) iteration.
Structured Program Advantages
- Structured programming is effective in a teamwork environment because several people can work on a common program, each person developing one or more modules.
- Structured programs are easier to understand and modify , especially if meaningful names are chosen for the modules and if the documentation clearly identifies the module’s task.
Developing Computer Solns
- State the problem concisely
- Use Math Eqns/Relns Whenever possible
- Specify the data to be used by the program. This is the “ input .”
- In physical Problems These are typically
- Boundary Conditions
- Initial Conditions
- Constraints
- Parameters
- Specify the information to be generated by the program. This is the “ output .”
Developing Computer Solns cont
6. Check the output of the program with your hand solution(s)
- Run the program with your input data and perform a reality check on the output.
- Output MUST NOT Violate the Laws of Physics; e.g., in Statics (ENGR36)
- a CABLE canNOT support NEGATIVE Tension (you can’t PUSH something with a ROPE)
- Objects canNOT have NEGATIVE Weight or Mass (at least not until we figure out AntiGravity methods)
- In ENGR43 Physical Resistors, Capacitors, and Inductors can NOT have NEGATIVE Values
Developing Computer Solns cont
- If you will use the program as a general tool in the future, test it by running it for a range of reasonable data values;
- Perform a Reality Check on the results
Anatomy of a Structure Chart Module
the called module
Example: Pizza Pricing Problem
- Write a program to find the UNIT price for a given pizza. The size of the pizza will be provided in inches. The result must be cost/inch^2
FlowCharting
Example
Basic House Painting
- Note the Cascade of Decision-Diamonds
Effective Documentation cont
- A verbal description of the program, often in pseudocode.
- Generic way of describing an algorithm, without use of any specific programming language
- Helps programmers to PLAN an algorithm
- Not an actual programming Language, but may borrow syntax from popular programming languages
- Styles vary
PsuedoCode: Common Terms
- To Describe input , output , computations , etc., the following terms are often used: - Input: INPUT, READ, GET - Output: PRINT, DISPLAY, SHOW - Compute: COMPUTE, CALCULATE, DETERMINE - Initialize: SET, INIT - Add one: INCREMENT, BUMP, STEP - Decisions: TEST, IF/THEN/ELSE, WHILE/DO
PsuedoCode Algorithms
- Ensure that the the task is completely specified
- Issues to Consider
- What data is known before the program runs?
- What data must be input by the user?
- What computations will be performed on the data?
- What data will be output (displayed) to the user?