Lecture 2 Numerical Methods for Engineering MECN 3500 Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus Dr.

Slides:



Advertisements
Similar presentations
Lecture 7: Software Design (Part II)
Advertisements

CS101: Introduction to Computer programming
Algorithms An algorithm is a finite sequence of instructions, logic, an explicit step-by-step procedure for solving a problem. Specific algorithms sometimes.
Understanding the Three Basic Structures
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Mathematics for Computing Lecture 4: Algorithms and flowcharts Dr Andrew Purkiss-Trew Cancer Research UK
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
ITEC113 Algorithms and Programming Techniques
Mechanisms Design MECN 4110
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 4 Programming and Software EXCEL and MathCAD.
Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Program Design and Development
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
BPC.1 Basic Programming Concepts
Fundamentals of C programming
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
CIS Computer Programming Logic
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Mechanical Measurement and Instrumentation MECN 4600
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
CPS120 Introduction to Computer Science Iteration (Looping)
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 2.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
ITEC113 Algorithms and Programming Techniques
Control Structures CPS120: Introduction to Computer Science Lecture 5.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
Numerical Methods for Engineering MECN 3500
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
MECN 3500 Inter - Bayamon Lecture 8 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
MECN 3500 Inter - Bayamon Lecture 6 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
Introduction to Flowcharts
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Program design Program Design Process has 2 phases:
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Algorithms and Flowcharts
Introduction to Computer Programming
Programming Fundamentals
Unit# 9: Computer Program Development
Visual Basic 6 Programming.
Understanding Problems and how to Solve them by using Computers
Basic Concepts of Algorithm
Presentation transcript:

Lecture 2 Numerical Methods for Engineering MECN 3500 Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus Dr. Omar E. Meza Castillo

Lecture 2 MECN 3500 Inter - Bayamon 2 Tentative Lectures Schedule TopicLecture Mathematical Modeling and Engineering Problem Solving 1 Introduction to Matlab 2 Numerical Error Root Finding System of Linear Equations Least Square Curve Fitting Polynomial Interpolation Numerical Integration Ordinary Differential Equations

Lecture 2 MECN 3500 Inter - Bayamon MATLAB Programming and Software 3

Lecture 2 MECN 3500 Inter - Bayamon  To introduce you to how the computer is used as a tool to obtain numerical solutions. Thermal Systems Design Universidad del Turabo 4 Course Objectives

Lecture 2 MECN 3500 Inter - Bayamon 4 Packages and Programming  Computer programs are merely a set of instructions that direct the computer to perform a certain task.  The programs consist of: Simple information representation (constants, variables, and type declarations). Simple information representation (constants, variables, and type declarations). Advanced information representation (data structure, arrays, and records). Advanced information representation (data structure, arrays, and records). Mathematical formulas (assignment, priority rules, and intrinsic functions). Mathematical formulas (assignment, priority rules, and intrinsic functions). Input/output. Input/output. Logical representation (sequence, selection, and repetition). Logical representation (sequence, selection, and repetition). Modular programming (functions and subroutines). Modular programming (functions and subroutines).

Lecture 2 MECN 3500 Inter - Bayamon 5 Structured Programming  Structured programming is a set of rules that prescribe good style habits for the programmer. Although structured programming is flexible enough to allow considerable creativity and personal expression, its rules impose enough constraints to render the resulting codes far superior to unstructured versions.  In particular, the finished product is more elegant and easier to understand.  A key idea behind structured programming is that any numerical algorithm can be composed using the three fundamental control structures: sequence, selection, and repetition.  To keep this description generic, we will employ flowcharts and pseudocode.

Lecture 2 MECN 3500 Inter - Bayamon 6 Flowchart  A flowchart is a visual or graphical representation of an algorithm

Lecture 2 MECN 3500 Inter - Bayamon 7 Pseudocode An alternative approach to express an algorithm that bridges the gap between flowcharts and computer code is called pseudocode. This technique uses code-like statements in place of the graphical symbols of the flowchart. We have adopted some style conventions for the pseudocode in this class. Keywords such as IF, DO, INPUT, etc., are capitalized, whereas the conditions, processing steps, and tasks are in lowercase. Additionally, the processing steps are indented. Thus the keywords form a “sandwich” around the steps to visually define the extent of each control structure. An alternative approach to express an algorithm that bridges the gap between flowcharts and computer code is called pseudocode. This technique uses code-like statements in place of the graphical symbols of the flowchart. We have adopted some style conventions for the pseudocode in this class. Keywords such as IF, DO, INPUT, etc., are capitalized, whereas the conditions, processing steps, and tasks are in lowercase. Additionally, the processing steps are indented. Thus the keywords form a “sandwich” around the steps to visually define the extent of each control structure.

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  Sequence: The sequence structure expresses the trivial idea that unless you direct it otherwise, the computer code is to be implemented one instruction at a time. As in Figure, the structure can be expressed generically as a flowchart or as pseudocode. 8 Figure 1

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  Selection: In contrast to the step-by-step sequence structure, selection provides a means to split the program’s flow into branches based on the outcome of a logical condition. Figure 2 and 3 show the two most fundamental ways for doing this.  The single-alternative decision, or IF/THEN structure (Figure 2), allows for a detour in the program flow if a logical condition is true. If it is false, nothing happens and the program moves directly to the next statement following the ENDIF. 9

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation 10 Figure 2

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  The double-alternative decision, or IF/THEN/ELSE structure (Figure 3), behaves in the same manner for a true condition. However, if the condition is false, the program implements the code between the ELSE and the ENDIF. 11 Figure 3

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation 12 Figure 4

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  The CASE structure is a variant on this type of decision making (Figure 5). Rather than testing individual conditions, the branching is based on the value of a single test expression. Depending on its value, different blocks of code will be implemented. In addition, an optional block can be implemented if the expression takes on none of the prescribed values (CASE ELSE). 13 Figure 5

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  Repetition: Repetition provides a means to implement instructions repeatedly. The resulting constructs, called loops, come in two “flavors” distinguished by how they are terminated.  The first and most fundamental type is called a decision loop because it terminates based on the result of a logical condition. Figure 6 shows the most generic type of decision loop, the DOEXIT construct, also called a break loop. This structure repeats until a logical condition is true. 14

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation 15 Figure 6

Lecture 2 MECN 3500 Inter - Bayamon Logical Representation  The break loop in Figure 6 is called a logical loop because it terminates on a logical condition. In contrast, a count-controlled or DOFOR loop (Figure 7) performs a specified number of repetitions, or iterations 16 Figure 7

Lecture 2 MECN 3500 Inter - Bayamon 18

Lecture 2 MECN 3500 Inter - Bayamon Algorithm for Roots of a Quadratic 19 Example 2.1 Problem Statement: The roots of a quadratic equation. Problem Statement: The roots of a quadratic equation. Can be determined with the quadratic formula Develop an algorithm that does the following: Develop an algorithm that does the following:

Lecture 2 MECN 3500 Inter - Bayamon Algorithm for Roots of a Quadratic 20

Lecture 2 MECN 3500 Inter - Bayamon Algorithm for Roots of a Quadratic 21

Lecture 2 MECN 3500 Inter - Bayamon Homework2  Omar E. Meza Castillo Ph.D. 22