Lecture 5 - Programmig

Embed Size (px)

Citation preview

  • 8/12/2019 Lecture 5 - Programmig

    1/17

    EngineeringEducation

    EngE 1114, Spring 2014

    Exploration of Engineering DesignEngE 1114

    Graphics Communication Hand Sketching Computer Aided

    Design/DraftingINVENTOR)

    Design Teamwork Project Management Design Process Algorithm Development

    Flowcharting Programming in MATLAB

    Start

    MATLAB

  • 8/12/2019 Lecture 5 - Programmig

    2/17

    EngineeringEducation

    INVENTORTEST: Thursday Feb 27th 7PMLocations TBARequires your tablet fully chargedClosed book notes internet: just you and InventorYou will be given a properly dimensioned

    engineering drawing (multi-view) with a pictorial.

    You will then create the object in Inventor andSUBMIT that ipt file via a Scholar link. The test

    should take 60 minutes, but you will be given 45

    90.

  • 8/12/2019 Lecture 5 - Programmig

    3/17

    EngineeringEducation

    Programming module topicsAlgorithm Development

    Flowcharting

    Sequential programming with MATLAB 2013bTimeline

    Feb 21-27 Intro Algorithm development

    Flowcharting basics

    MATLAB basics and script files

    Feb 28- Mar 6 Decision structures

    Logical and relational operators

    March 720 Spring break

    Repetition structures

    Summing and averaging Ensuring valid input

    March 21-27 User defined functions

    March 28April 3 Vectors

    LECTURE

    INVENTOR Test Feb 27th

    MidTerm Test March 27th

    MATLAB Test April 3rd

  • 8/12/2019 Lecture 5 - Programmig

    4/17

    EngineeringEducation

    Why should engineers know how to write acomputer program?

  • 8/12/2019 Lecture 5 - Programmig

    5/17

    EngineeringEducation

    Rationale for Learning AlgorithmDevelopment Programming

    Computers are routinely used in all

    fields of engineering to help solve

    problems.

    Upper level courses in most departmentswill require the use of a computer to generate

    results (answers) for some problems.

    Programming can be a important tool in design,

    especially in the preliminary and detail design phases.

    Developing an algorithm is a good problem solving

    technique. Algorithms are independent of specific

    input values.

    Graphics Communication Hand Sketching Inventor

    Design Teamwork Project Management Design Process

    Algorithm Development Flowcharting Programming in

    MATLAB

  • 8/12/2019 Lecture 5 - Programmig

    6/17

    EngineeringEducation

    Algorithm? What is it?

  • 8/12/2019 Lecture 5 - Programmig

    7/17

    EngineeringEducation

    Algorithm: an effective procedure,

    a way of getting somethingdone in a finite number ofdiscrete steps.*

    * The Advent of the Algorithm, David Berlinski,

    Harcourt, Inc., New York, 2000, pg xvi.

    We will write algorithms as a way to provide

    step by step instructions for solving a problem.

    A precursor to writing programming code for acomputer

  • 8/12/2019 Lecture 5 - Programmig

    8/17

    EngineeringEducation

    Example MATLAB program via target1:Examines the trajectory of a pingpong ball into a trash canWhat must be considered? List parameters

    LECTURE

  • 8/12/2019 Lecture 5 - Programmig

    9/17

    EngineeringEducation

    Required elements:1. Problem ID

    2. Brief statement of what algorithm will do in your own words

    3. A diagram for the problem, when appropriate a sketch is fine

    4. Flowchart (copy and paste from VISIO)5. Program listing (copy and paste from MATLAB)

    6. Sample Output (copy and paste from MATLAB)

    7. Discussion You are expected to check the output from your program

    to see that it makes sense. Acknowledge anyunexpected results.

    Acknowledge any error messages

    Homework format:

    LECTURE

  • 8/12/2019 Lecture 5 - Programmig

    10/17

    EngineeringEducation

    In-class problem: Produce an algorithm that will determine the volume

    and surface area of a sphere given the diameter.

    Sketchthe flowchart on your PPT panel.

  • 8/12/2019 Lecture 5 - Programmig

    11/17

    EngineeringEducation

    Sphere Vol and SA flowchart.try Visio

  • 8/12/2019 Lecture 5 - Programmig

    12/17

    Engineering

    Education

    Sphere Vol and SA flowchart.try MATLAB

    But first.

  • 8/12/2019 Lecture 5 - Programmig

    13/17

    Engineering

    Education

    Some MATLAB basics:

    Command Line commands: Assignments Variable names Case sensitivity Semicolon up-and-down arrows Pi + - / * ^ Algebraic hierarchy Sequential programming

    i.e. one line at a time Screen areas Path clc Clear Script files

  • 8/12/2019 Lecture 5 - Programmig

    14/17

    Engineering

    Education

    Script Files File Names Input statements

    Vname=input literal string); Inputs are assignment Output statements

    fprintf Literal strings Format specifiers

    f M.Nf

    M is number of columns N is digits to right of decimal

    These signs are NOT comments General form of fprintf is:fprintfliteral string info, vname1, v2, x3) The literal string includes text and formatspecifiers.

  • 8/12/2019 Lecture 5 - Programmig

    15/17

    Engineering

    Education

    Review student code:

    Add the following two lines to the end of your program:load handel

    sound(y,Fs)

    Then.. Turn on your speakers

    type file name at command prompt OR

    select debug and run from editor

    Enter a diameterGo.

    halleluiah

    ndl n n n n n p.

    l l.

    http://www.google.com/imgres?imgurl=http://www.hallelujah-chorus.com/images/handel.jpg&imgrefurl=http://www.hallelujah-chorus.com/georg-handel.html&h=434&w=346&sz=7&tbnid=xpW5pW70gZyRWM::&tbnh=126&tbnw=100&prev=/images?q%3Dhandel%2Bpix&usg=__xtuWKKTMtHf6v3mnCsl2Fdy49JI=&ei=ctjDSfiODZeMtgeZ-tnICg&sa=X&oi=image_result&resnum=1&ct=image&cd=1http://www.google.com/imgres?imgurl=http://www.hallelujah-chorus.com/images/handel.jpg&imgrefurl=http://www.hallelujah-chorus.com/georg-handel.html&h=434&w=346&sz=7&tbnid=xpW5pW70gZyRWM::&tbnh=126&tbnw=100&prev=/images?q%3Dhandel%2Bpix&usg=__xtuWKKTMtHf6v3mnCsl2Fdy49JI=&ei=ctjDSfiODZeMtgeZ-tnICg&sa=X&oi=image_result&resnum=1&ct=image&cd=1http://www.google.com/imgres?imgurl=http://www.hallelujah-chorus.com/images/handel.jpg&imgrefurl=http://www.hallelujah-chorus.com/georg-handel.html&h=434&w=346&sz=7&tbnid=xpW5pW70gZyRWM::&tbnh=126&tbnw=100&prev=/images?q%3Dhandel%2Bpix&usg=__xtuWKKTMtHf6v3mnCsl2Fdy49JI=&ei=ctjDSfiODZeMtgeZ-tnICg&sa=X&oi=image_result&resnum=1&ct=image&cd=1
  • 8/12/2019 Lecture 5 - Programmig

    16/17

    Engineering

    Education

    Listen to the voiceover files associated with your homework. They represent

    your free textbook for MATLAB and flowcharting.

    Other resources are available via the bookstore or Newman Library.

    Other notes:

    Questions about homework, workshops and grades should be first

    addressed to your workshop leader (or any of the workshop leaders)

    When emailing me or your WSL you must include your name, the course

    and section, and a subject. Be patient, ENGE1114 has 740+ students in

    addition to other classes and responsibilities.

  • 8/12/2019 Lecture 5 - Programmig

    17/17

    Programming: Quiz#7456:

    1. The flowchart symbol for a

    process is:

    A. RectangleB. Parallelogram

    C. Ellipse

    D. Triangle

    2. The flowchart symbol for a

    repetition structure is:

    A. RectangleB. Parallelogram

    C. Irregular hexagon

    D. Diamond

    3. The flowchart symbol for input or

    output is:

    A. DiamondB. Parallelogram

    C. Rectangle

    D. Ellipse

    4. The fprintf command is used to:

    A. Save values

    B. Print the current page

    C. Print highlighted entities

    D. Send output to a printer/device

    5. The % symbol at the end of a linemeans:

    A. What follows is a comment

    B. the line should be ignored

    C. Store values from line

    D. Output values to the printer

    6. Which of the following is/are invalidvariable name(s):

    A. Diamond

    B. Flow-chart

    C. nOnAme

    D. maroONANdorange

    E. 12Times

    F. Items B and E are invalid names

    7. Which of the following format specifiers

    will display the value of pi as 3.1416

    A. %f B. %0.f

    C. %1.5f D. %7.4f

    E. %%1.4f F. f5.5%