ENGG 1801 Engineering Computing - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

ENGG 1801 Engineering Computing

Description:

MATLAB Lecture 3: Revision of Tutorial 3 & 4 Concepts, ... to check your answers: don't get bogged down or be misled by wrong answers to early questions. ... – PowerPoint PPT presentation

Number of Views:183
Avg rating:3.0/5.0
Slides: 13
Provided by: amic52
Category:

less

Transcript and Presenter's Notes

Title: ENGG 1801 Engineering Computing


1
ENGG 1801Engineering Computing
  • MATLAB Lecture 3 Revision of Tutorial 3 4
    Concepts, Background for Weeks 5 6 Tutorial,
    Directions for Weeks 7 8 Tutorial
  • More Programming in MATLAB

2
Outline of Lecture
  • Problem solving revision tutorial 3 4.
  • fprintf, printing formats, for tutorial 5 6.
  • Getting the most from tutorials.
  • New material loops (tutorial 7 8), good
    programming practice.

3
Revision Assigning Variables
  • Variables are required to be assigned to carry
    out actions, e.g nTrucks has to be assigned as a
    variable in tut 3, question 1, by gtgt nTrucks
    (something)
  • That (something) depends on what you need to do
  • if the variable never (or rarely changes, it can
    be typed in directly, gtgt nTrucks 4
  • if the variable changes frequently, needs to be
    changed by users, the input function will help to
    prompt the user assign the variable, gtgt nTrucks
    input(How many trucks ? )

4
Revision Functions Punctuation
  • Learn about functions by reading the notes,
    coming to lectures.
  • Punctuation (like ) is required around text, not
    numbers, e.g. How many trucks?, so the
    following variable is
  • a string, gtgt x How many trucks
  • a number, gtgt x 433

5
Revision fprintf
  • fprintf
  • gtgt x 433
  • gtgt fprintf(My room is g,x)
  • Q Whats with the g?
  • A It is a format for output. Here it means
    general output format. Try using gtgt help fprintf
    for some more guidance.

6
Examples of Using fprintf
New line
  • Printing a line of information
  • gtgt fprintf(\nI am talking too much\n)
  • To give a number with a decimal point floating
    point format
  • gtgt x 42.2
  • gtgt fprintf(Load 12.2f N,x)
  • Gives
  • Load 42.20 N

The printing field is 12 spaces wide, there are
two figures behind the decimalpoint
7
Examples of Using fprintf
  • Put them together
  • gtgt fprintf(\nLoad 12.2f N\n,x)
  • prints a line then goes to the next line.
  • Several numbers
  • gtgt y 3.3
  • gtgt fprintf(\nLoad 12.2f N \nDeflection
    6.2f mm\n,x,y)
  • Load 42.20 N
  • Deflection 3.30 mm

8
Examples of Using fprintf
  • Scientific notation exponential format
  • gtgt fprintf(\n Load 12.2e N \n Deflection
    6.2f mm \n,x,y)
  • Load 4.22E001 N
  • Deflection 3.30 mm
  • Useful formats for tutorials in weeks 5 6, 7
    8 and onwards, are e, f, \n

The E001 takes up 5 spaces, there are two
numbers behind the decimal point
9
Getting the Most from Tutorials
  • Ask the tutors to check your answers dont get
    bogged down or be misled by wrong answers to
    early questions.
  • Dont copy the work of others or just leave this
    is not ethical, good practice, does not help you
    to learn.
  • Read the lecture notes prior to the tutorial.

10
Loops
  • When you want to do something several times, in
    succession.
  • gtgt for numb 1 3
  • gtgt fprintf(Case 5.0f \n, numb)
  • gtgt end
  • Case 1
  • Case 2
  • Case 3

11
Loops
  • Notice that good programming practice involves
    indenting material within FOR END loops and IF
    ELSEIF ELSE ... END decisions for better
    readability.
  • FOR END, is capped off by an end statement
  • Read notes (or Help) on loops using WHILE END

12
Conclusions
  • We are now learning more about programming
    practice useful tools for this.
  • Have reviewed
  • Assigning variables.
  • Functions punctuation.
  • fprintf formatting.
  • Getting the most from tutorials.
  • Extending decisions (IF ELSE IF ELSE END)
    to loops (FOR END).
Write a Comment
User Comments (0)
About PowerShow.com