Engineering Programming and Five-Step Problem Solving
Methodological Approach to Engineering Programming
The problem-solving process consists of five distinct steps that must be completed before writing a single line of actual code. These steps are as vital as the code itself, serving as the foundation for complex engineering solutions.
The bridge between understanding a problem and writing software is the combination of English descriptions and mathematical notation, which forms the logic and algorithm design.
Skipping the initial thinking phase leads to structural errors; therefore, the pre-coding steps are categorized as "things to do before we code."
The final preparatory stage involves the creation of pseudocode, which act as a direct precursor to the development of the Python script.
The overarching workflow for engineering programming includes defined phases of preparation, implementation (Python), and verification of results.
The Engineering Scenario: Steel Bar Stress Analysis
A specific engineering problem is used to illustrate the five-step process: analyzing a steel bar subjected to mechanical stress.
The known parameters of the bar are:
Tensile Force ():
Cross-Section Area ():
The two primary goals for the analysis are:
Goal 1: Determine the actual normal stress () produced in the bar.
Goal 2: Determine if the bar is safe to use based on a specific safety limit.
Safety Limit (Allowable Stress, ):
Phase 1 and 2: Problem Comprehension and Decomposition
Understanding the goal requires identifying what needs to be determined—specifically, the magnitude of the stress and a binary safety assessment.
Information gathering involves identifying the physical relationship between force and area. The fundamental engineering formula for stress is:
Consistency in units is paramount for safety calculations. In this context, the relationship for Megapascals () is defined as:
The problem decomposition process highlights that we have sufficient information to solve for stress but must account for the specific units ( vs ) provided in the initial data.
Phase 3: Identification of Inputs and Outputs
Inputs: To reach the goals, the system requires specific variables:
Input 1: Tensile Force ()
Input 2: Cross-Section Area ()
Input 3: Maximum Allowable Stress ()
Note: While area and force are calculation-specific, the allowable stress is included as an input to facilitate "what-if" scenarios or variable safety thresholds.
Outputs: The process must yield two distinct results:
Output 1: The calculated normal stress ().
Output 2: A safety status (Safe or Not Safe).
Phase 4: Logic and Algorithm Development
The algorithm must manage unit conversion to ensure the calculated stress is directly comparable to the allowable stress of .
Algorithm Sequence:
Obtain Force () and Area ().
Obtain Allowable Stress ().
Convert Force from kilonewtons () to Newtons () to align with the unit definition ().
Calculate Stress: .
Compare the calculated stress () to the allowable stress ().
If , then the condition is deemed "Safe."
If \sigma > \sigma_{allowable}, then the condition is deemed "Unsafe" or "Not Safe."
Report both the stress value and the safety status.
This logic accounts for the two goals of the problem and involves the engineering knowledge of the field combined with programming logic.
Phase 5: Pseudocode, Implementation, and Verification
Pseudocode acts as the last step before working on actual code. It structured logically as follows:
START
Input the required values: Force, Area, Allowable Stress.
Perform specific conversions: .
Calculate: .
IF :
The system should report "Safe."
ELSE (or IF NOT):
The system should report "Not Safe."
Report the calculated .
END
Applying the bar data to the algorithm:
Since , the condition is "Safe."
Once the logic is verified, the system is translated into Python, allowing for any numerical input for force, area, and allowable stress to yield a report.
Questions & Discussion
Question regarding Pseudocode Examples: A request was made for a specific example of pseudocode. Response: Handled immediately through the step-by-step steel bar analysis.
Question regarding Logical Operators/If Statements: Is there a requirement for a formal "else" statement or can an "if not" structure be used? Response: In logic-building, both "else" and "if not" represent the opposite condition; the goal is to prepare the logic before actual coding. Python will eventually handle these as formal conditional statements.
Question regarding Input Convention: Is there a specific convention for which value comes first when comparing a stress number and a safety limit? Response: There is no strict convention; either can be prioritized as long as the logical comparison ( or >) remains accurate.
Discussion on Implementation: Engineering programming requires a unique combination of domain knowledge (physics/mechanics) and computational logic. The lecture concluded by offering ten minutes of time back to the participants.