EGR 106 – Project Intro / While Loop Project description Project schedule Background information / terminology A simple example Examples of similar programs.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

JAVA Coursework (the same for 2A and 2B). Fundamental Information The coursework is 30 marks in your O’Level = 15% of the exam Must be word processed.
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
Computer Science 1620 Loops.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
1 Objectives You should be able to describe: Relational Expressions The if-else Statement Nested if Statements The switch Statement Common Programming.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Loops – While, Do, For Repetition Statements Introduction to Arrays
Week 7 - Programming I Relational Operators A > B Logical Operators A | B For Loops for n = 1:10 –commands end.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Loops For loop for n = [ ] code end While loop while a ~= 3 code end.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
EGR 106 – Project Description (cont.) Analysis of truss structures A simple example Factor of Safety calculations This week’s assignment.
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
Chapter 4: Looping CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Fundamentals of Python: From First Programs Through Data Structures
Python quick start guide
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Fundamentals of Python: First Programs
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB FUNDAMENTALS: CONTROL STRUCTURES – LOOPS HP 100 – MATLAB Wednesday, 10/1/2014
2 Objectives You should be able to describe: Relational Expressions Relational Expressions The if-else Statement The if-else Statement Nested if Statements.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
ENGR-25_Programming-3.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Coding Design Tools Rachel Gauci. What are Coding Design Tools? IPO charts (Input Process Output) Input- Make a list of what data is required (this generally.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
Matlab Programming for Engineers
CPS120 Introduction to Computer Science Iteration (Looping)
Week 9 - Programming III Today: – Another loop option – A programming example: tic-tac-toe Textbook chapter 7, pages , (sections 7.4.2,
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
A First Book of C++ Chapter 4 Selection.
ECE Application Programming
CNG 140 C Programming (Lecture set 3)
Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. Repetition in Pascal:
Control Structures II Chapter 3
CS1371 Introduction to Computing for Engineers
Introduction To Flowcharting
Scripts & Functions Scripts and functions are contained in .m-files
Week 8 - Programming II Today – more features: Loop control
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Coding Concepts (Basics)
Alternate Version of STARTING OUT WITH C++ 4th Edition
Chapter8: Statement-Level Control Structures April 9, 2019
How to allow the program to know when to stop a loop.
Presentation transcript:

EGR 106 – Project Intro / While Loop Project description Project schedule Background information / terminology A simple example Examples of similar programs While loop

Working in teams of approx. four students, each team is to develop a Matlab program that can be used to design a lightweight truss structure The code shall allow the designer to evaluate alternative designs quickly and easily The actual truss analysis will be performed by the Matlab function “truss_analysis.m” to be provided by the instructor. Project Description

The program developed by each team shall provide a user-friendly interface for both data input and interpretation of results Each team’s code will be used in a design competition in which each team will be given 1 hour to develop a truss design for a particular load scenario The team will then construct their design from balsa wood (required construction materials will be provided) Project Description (cont.)

3/27 – (T)Project Introduction 3/29 – (R)Quiz 2 make up / Team assignment #1 4/3 – (T)Lecture: Analysis of Trusses / Graphical Interface 4/5 – (R)Project work / Team assignment #2 4/10 – (T)Lecture: Analysis of Trusses / Graphical Interface 4/12 – (R)Quiz 3 / Project work 4/17 – (T)Project work 4/19 – (R)In-class design competition 4/24 – (T)Quiz 4 / Model testing 4/26 – (R)Project Presentations / Demonstrations 5/1 – (T)Written reports due Project Schedule (tentative)

Definition: A planar truss is a structure composed of slender members joined together at their end points (called joints). Background – Truss Structures Photo: Engineering Mechanics: Statics, by R. C. Hibbeler

Terminology – Truss Structures Forces Joint Member Supports

Trusses are supported at certain joints at which motion is constrained either in the x- direction, y-direction or both the x- and y-directions. These supports are also called boundary conditions. Terminology (cont.) X & Y –displacement=0 X - displacement=0 Y -displacement=0 (bctype=1) (bctype=2) (bctype=3)

Truss Analysis – A simple example C x = 100 C y = mm 150 mm

A simple example – input data (details to be discussed next class) C x = 100 C y = mm 150 mm joint_def=[0, 0, 1, 0, 0; 50, 50, 0, 0, 0; 150, 150, 0, 100, -50; 250, 50, 0, 0, 0; 300, 0, 3, 0, 0; 200, 0, 0, 0, 0; 100, 0, 0, 0, 0]; member_def=[1, 2, 10, 10; 2, 3, 10, 10; 3, 4, 10, 10; 4, 5, 10, 10; 5, 6, 10, 10; 6, 7, 10, 10; 7, 1, 10, 10; 2, 7, 10, 10; 7, 3, 10, 10; 3, 6, 10, 10; 6, 4, 10, 10];

Joint Displacments disp = C x = 100 C y = mm 150 mm Member Stresses stress = A simple example - results Matlab command (call to function ‘analyze_truss’): [disp,stress]=analyze_truss(joint_def,member_def)

Examples of truss design programs Johns Hopkins University: West Point Bridge Design Contest

Notes on academic integrity Truss design and analysis programs are common. Students are welcome to look at other programs for features to incorporate. Direct copying of code, however, is not permitted. Do not share code with other teams. Be sure not to leave your codes on public computers.

Longer Running Loops for loops repeat a fixed number of times: for variable = {array of length n} {commands} end and break can be used to stop earlier. Question: How about repeating “until done”? Run as long as is needed.

Answer: M ATLAB ’s “while” loop: while expression {commands to be repeated as long as expression is true} end

Prior example – compounded interest until the amount doubles: value = 1000; for year = 1:1000 value = value * 1.08; disp([num2str(year),' years: $ ',num2str(value) ]) if value > 2000 break end for loop terminated with break

Expected output:

while version format bank value = 1000; while value < 2000 value = value * 1.08; disp(value) end

Example – Collecting and storing data until a zero is entered: x = [ ]; new = 1; while new ~= 0 new = input('enter value '); x = [ x, new ]; end x = x(1:end–1) empty array to drop the zero initialize

Example – Getting valid keyboard input: E.g. forcing the user’s input to be between 0 and 10: x = –3; while ( x 10 ) x = input( 'type a value ' ); end

or: x = input('enter value '); while (x 10) disp('invalid choice'); x = input('enter value '); end disp('finally!');

Example – computing pi:

Example – “infinite” Hi-Lo: numb = round (10*rand(1)); done = 0; while ~done guess = input('guess'); if guess = = numb disp( 'You got it !!!' ); done = 1; elseif guess > numb disp('too high') else disp('too low') end initialization single guess loop control

Nesting of while loops while expression1 {outer loop commands} while expression2 {inner loop commands} end {more outer loop commands} end these can also be more than 2 levels deep