0% found this document useful (0 votes)
51 views38 pages

Lecture 1 Week 1

Here are the results of the arithmetic operations: 1. 3-2 = 1 2. 3*2 = 6 3. 3/2 = 1.5000 4. 3\2 = 1.5000 (division) 5. 3^2 = 9 (exponentiation) 6. 2/0 = Inf (division by zero results in infinity) 7. 0/2 = 0 (division of zero results in zero) 8. 3*Inf = Inf (infinity times a number results in infinity)

Uploaded by

kaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views38 pages

Lecture 1 Week 1

Here are the results of the arithmetic operations: 1. 3-2 = 1 2. 3*2 = 6 3. 3/2 = 1.5000 4. 3\2 = 1.5000 (division) 5. 3^2 = 9 (exponentiation) 6. 2/0 = Inf (division by zero results in infinity) 7. 0/2 = 0 (division of zero results in zero) 8. 3*Inf = Inf (infinity times a number results in infinity)

Uploaded by

kaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

300027

Engineering Computing
Engineering Computing 300027
• Unit Coordinators
– Dr. Upul Gunawardana, PS-ED.G.122, Tue 11-12
Email: [email protected]
– Dr Mark Wang, KWD-XB.2.43, Wed 11-1
Email: [email protected]

2
Lecture
• Parramatta & Kingswood Campuses
Mazin Aouf, Email: [email protected]

3
What is Engineering?
• To ‘engineer’ means to make things happen
• Engineering involves application of scientific knowledge to the
design, build and control of machines, buildings, roads, bridges,
electrical equipment, etc.
• Analyse, model and solve complex technical problems that require
integrated, interdisciplinary view of problem solving
• Conceptualize complex systems as a collection of smaller, simpler
components
• Development and use of mathematical simulation models.
• Synthesis and design by taking into account factors such as
reliability, safety, flexibility, economy and sustainability

1-4
Why Engineering Computing?
• Engineers use all forms of mathematical simulation models
and tools
• During the B Eng degree (vary from key area to key area)
– MATLAB, Simulink
– SolidWorks, Autocad
– NI LabView, Multisim, Ultiboard, Altium Designer
– Ansys models
– Abaqus, Microstrain
– Programming Languages such as C++, C#, C, Visual Basic, Python
– Spreadsheet applications such as Excel

1-5
WHS & SCEM
• Work Health and Safety (WHS) Induction
– Login to vUWS and select 2019 Work Health and Safety
vUWS site
– Go through learning material
– Take the test – you need to get at least 23 of 25 correct
– Need to complete WHS induction before attending lab
classes
• SCEM Accounts
– Need SCEM account to access Engineering computer labs
– Different to Western Sydney account (which is all numbers)
– Login to a SCEM computer using username as ‘register’ and
password as ‘register’ and follow the process
1-6
Engineering Computing: Learning
Outcomes
At the conclusion of this unit, students will be able to:

1. Utilise a typical software development environment.


2. Develop solutions to problems using an algorithmic approach.
3. Apply data structures of a common programming language, such as C++,
to translate an algorithm into a coded program. These programming
structures should include the following as a minimum:
• Selection and Repetition statements
• Functions
• 1 & 2 dimensional Arrays
• File processing
4. Implement basic features of data manipulation and graphing using a
spread sheet program, such as EXCEL.

1-7
Textbook and Software
• MATLAB
• Textbook: Essential MATLAB (6th edition) by Hahn and
Valentine, Elsevier
• Software: MATLAB (information for downloading
MATLAB available on vUWS)
• C++
• Software: Microsoft Visual Studio (or access to a similar
C++ development environment) / Xcode / Dev C++
• Excel
• Software: Microsoft Office

1-8
Additional Resources
• MATLAB
– Textbook: Gilate, A, (2014), “MATLAB: An Introduction
with Applications”, 5th Ed., Wiley
• C++
– Textbook: Gaddis, T, (2012), "Starting Out with C++ from
control structures through objects," 7th Ed., Addison-
Wesley
– Website: C++ Tutorial & Forum
http://www.cplusplus.com/doc/tutorial/
• Excel
– Textbook: Larsen, Ronald W., (2013) "Engineering with
Excel", 4rd Ed., Pearson
1-9
What is useful?
• Lectures
– Lecture notes
– Textbook (hardcopy or softcopy)
– If you have a laptop with MATLAB installed you may
bring that to lecture and lab classes
• Lab Classes
– WHS Induction must be completed with a Pass Grade
– Must be wearing covered shoes
– A USB drive to save your work
– Complete previous lab questions
1-10
Teaching and Learning Activities

11
Academic Misconduct
• Read definitions of collusion and plagiarism as
explained in Western Sydney University Academic
Misconduct Policy
• All quizzes and exams will be individual work

1-12
Assessment Details
MATLAB MATLAB program to be submitted in
Programming 20% the practical session, open book, 4
Quiz 1 questions (Week 5)

MATLAB MATLAB program to be submitted in


Programming 30% the practical session, open book, 4
Quiz 2 questions (Week 10)

C++ C++ program to be submitted in the


Programming 10% practical session, open book, 2
Quiz 3 questions (Week 14)

Multiple choice, closed book, 50


Final Exam 40% questions: 35 MATLAB, 13 C++, 2
Excel (TBA)
Introduction to MATLAB

Content based on the text:

Essential MATLAB
for Engineers and Scientists, 6th Edition
By
Brian H. Hahn & Daniel T. Valentine
Outline
• What is MATLAB?
• How is MATLAB used in industry?
• Problem Solving in Engineering and Science
• Introduction to MATLAB
– How to get started with MATLAB
– Learn how to do technical computing with
MATLAB

15
What is MATLAB?
• MATLAB is one of a number of commercially
available, sophisticated mathematical
computation tools
• Others include
– Maple
– Mathematica
– MathCad
– Octave

16
MATLAB excels at:
• Numerical calculations
– Especially involving matrices
• Graphics
• MATLAB stands for
Matrix Laboratory

17
Why MATLAB

• Easy to use
• Versatile
• Built in programming language
• Not a general purpose language like C++ or Java
MATLAB was originally written in Fortran,
then later rewritten in C

18
MATLAB
• The Mathworks packages their software in groups,
called releases
• New releases are issued twice a year in the spring
and in the fall (2016a, 2016b, etc.)
• MATLAB Releases include the base MATLAB,
Simulink and a set of specialized “toolboxes”
• MATLAB is updated regularly

19
How is MATLAB used in Industry?
• Widespread, especially in the signal processing field
• Tool of choice in Academia for most engineering fields
• MATLAB is used in Industry in a number of fields such
as Biomedical Engineering, Electrical Engineering, Fluid
Dynamics, Financial industry, Biological Sciences, etc.

20
Problem Solving in Engineering and Science
1. State the Problem
– If you don’t have a clear understanding of the problem, it’s
unlikely that you’ll be able to solve it
– Drawing a picture often helps you understand the system better
2. Describe the input and output
– Be careful to include units and identify constants
3. Develop an algorithm
– Identify any equations relating the knowns and unknowns
– Work through a simplified version of the problem by hand or with
a calculator
4. Solve the problem
– Create a MATLAB solution
– Be generous with comments, so that others can follow your work
5. Test the solution
21
Test the Solution
• Compare to the hand solution
• Do your answers make sense physically?
• Is your answer really what was asked for?
• Graphs are often useful ways to check your
calculations for reasonableness

22
MATLAB desktop

Command Window
Workspace Window
Command History
Window

Current Directory
Window

23
Command Window
• The Command Window in the center is the main
panel where you interact with MATLAB.
• You key (or type) and <Enter> commands after the
prompt >>; MATLAB executes the commands and
displays results (if requested).
• Some commonly used tools and commands:
–  (up arrow) returns last command input, can be repeated
– clc – clears the screen
– whos – shows list of variables
– clear – clears variables

24
Evaluation of MATLAB
• HANDS-ON with MATLAB
– Type
>> 2+3 <Enter>
into the Command Window
>> clc <Enter>
>> whos <Enter>
Throughout the lecture, yellow text indicates what you
should type into MATLAB.

25
Command History Window
• The Command History Window logs all of the
commands you enter in MATLAB.
• It should have logged 2+3.
Use the Command History Window to reenter 2+3 in
the command window (use copy-and- paste or
double click on 2+3).
• This is useful to retrieve past commands.
• Use “Shift” key to select multiple lines.

26
Arithmetic with MATLAB
• Let us explore by doing exercises:

>> 3–2 <Enter>


>> 3*2 <Enter>
>> 3/2 <Enter>
>> 3\2 <Enter>
>> 3^2 <Enter>
>> 2/0 <Enter>
>> 0/2 <Enter>
>> 3*Inf <Enter>
27
Algebraic-numeric computations
• Let us explore by doing exercises:
>> a = 3 <Enter>
>> b = 2 <Enter>
>> a – b <Enter>
>> a / b <Enter>
>> a^2 <Enter>
>> c = a * b <Enter>
>> d = c^(b+1) <Enter>
>> who

28
Hiding Output with ;
• Let us explore by doing exercises:
>> clear; clc <Enter>
>> whos <Enter>
>> a = 3; <Enter>
>> b = 2; <Enter>
>> c = a * b; <Enter>
>> d = c^(b+1); <Enter>
>> who <Enter>
>> % a, b, c, d are in workspace<Enter>
>> a, b, c, d <Enter>

29
Plot y versus x
• Introduction to plotting & displaying data:
>> clear; clc <Enter>
>> x = 0:0.1:1; <Enter>
>> y = x.^2; <Enter>
>> whos <Enter>
>> plot(x,y,’-o’) <Enter>
>> disp(' '),disp('...... x ........ y .....'),disp([x‘ y']) <Enter>
>> x <Enter>
>> y <Enter>
>> % x and y are 1-by-11 arrays of numbers!

30
Write a Simple Program
• Consider computing the volume of a cone:
Volume = (pi.*r.^2.*h)./3
radius = 6 cm
height = 12 cm

• In the command window key in:


>> clear; clc <Enter>
>> r = 6 <Enter>
>> h = 12 <Enter>
>> v = (pi.*r.^2.*h)./3 <Enter>
>> whos <Enter>

31
Editor & M-Files
• An M-file in MATLAB is analogous to a txt-file
in Microsoft Notepad.
• An M-file is created in MATLAB text editor.
• M-files:
– You can save your programs (i.e., list of
executable commands) as M-files.
– You can reopen and modify your program.
– They are useful for “debugging” (correcting errors)
as you develop your programs (your technical
computing tools).
32
Comments in programs
• Every time you write a program to be saved, it is
helpful for you to comment (i.e., describe) it well.
• To insert a comment on a line in the editor or in the
Command Window, use the comment operator %,
then type your comment.
• MATLAB:
– will not run lines that begin with the comment operator (in
the editor comments appear in green).
• Comments
– Comments allow you (and others) to more easily read and
understand your program.
– When your lines of code are easy to understand, your code
will be easier to use later.
33
Art of well-written code
• A well-written program contains comments
explaining:
– what your program requires as input.
– what the variables in the program represent.
– what your program computes and displays.
• It is useful for you to add a set of header
comments that include the name of the
program, your name (as the programmer), and
the date the program was created or modified.

34
Saving code in an M-File
• Open the editor by:
– Entering the command edit in the command window.
– Or click the New Script icon located at the left most side of
the toolbar.
• Now enter the lines of code to find the volume of a cone:
rr = 4
h = 12
v = (pi.*r.^2.*h)./3
REMARK: If you save it, add header comments and comments
explaining what the program does.
• After you have typed in the code, save it as cone.m.

35
This is cone.m in the editor

36
Execute an M-file as a Command
• Now execute (or run) the program by pushing F5, or
by typing on the command line
>> cone <Enter>
– or by clicking the run button. (Note that the run button looks like a
green arrowhead pointing to the right in the Editor toolbar.)
• If you entered the code as written on the previous
slide you will get an error!
• What went wrong?
• Repair your program (Change rr = 4 to r = 4.), save it, and
run it again.
• Now change the height to 24, save and run your
program again (clicking the run button saves and
executes your code).
37
Summary
• MATLAB can be used like a hand calculator to do
arithmetic.
• You can define (or assign) variables with numbers
and expressions to do calculations as illustrated by
the volume-of-cone example.
• The advantage of saving programs as M-files is that
you open it, make changes and/or execute it again
without having to type it all over again.
• This concludes our overview of MATLAB and a taste
of things to come!

38

You might also like