21
Introduction to Introduction to MATLAB 7 MATLAB 7 Engineering 161 Engineering 161 Engineering Practices II Engineering Practices II Joe Mixsell Spring 2010 Joe Mixsell Spring 2010

Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Embed Size (px)

Citation preview

Page 1: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Introduction to Introduction to MATLAB 7MATLAB 7

Introduction to Introduction to MATLAB 7MATLAB 7

Engineering 161Engineering 161Engineering Practices IIEngineering Practices II

Joe Mixsell Spring 2010Joe Mixsell Spring 2010

Page 2: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

MATLAB Properties I• MATLAB is a very powerful

mathematical computational tool.• MATLAB comes from MATrix LABoratory• MATLAB provides extensive capabilities

for generating graphs• MATLAB is applicable to a broad range

of engineering problems

Page 3: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

MATLAB Properties II• MATLAB supports an interactive and a

programming environment• Think of the interactive environment as

a “super calculator” with graphics• Think of the programming environment

as tool for writing programs to perform complex calculations

Page 4: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

MATLAB Properties III• Where does MATLAB fit?

– It is usually easier to write programs in MATLAB as compared to C or Fortran

– C or Fortran programs will usually run faster than MATLAB programs

– But, MATLAB is optimized for matrix manipulations and programs formalized in this way will run faster than similar programs in C or Fortran

Page 5: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Resources• Text: MATLAB for Engineers• Notes: MATLAB Notes and

Assignments• Website:

www.engr.uaa.alaska.edu/soe/courses/engr161/• Website: www.mathworks.com

• Student Edition of MATLAB 7 ($99)• Computer Lab

Page 6: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Course of Study• MATLAB Environment Chp. 2• Built-In MATLAB Functions Chp. 3• Manipulating MATLAB Matrices Chp. 4• Plotting Chp. 5• User Defined Functions Chp. 6• User Controlled Input and Output Chp. 7• Logical Functions and Control Structures Chp. 8• Matrix Algebra Chp. 9• Symbolic Mathematics Chp. 11• Polynomials/Curve Fitting Chp. 12

Page 7: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

MATLAB Assignments• Chp. 2: 2.10, 2.12, 2.13, 2.14• Chp. 3: 3.3, 3.11, 3.12, 3.16• Chp. 4: 4.1, 4.7, 4.11• Chp. 5: 5.3, 5.4, 5.6, 5.17, 5.26 • Chp. 6: 6.4, 6.7, 6.8• Chp. 7: 7.5, 7.6, 7.9, 7.13, 7.15• Chp. 8 8.1, 8.2, 8.4, 8.9, 8.16, 8.23, 8.27• Chp. 9: 9.18, 9.19• Chp. 11: 11.9, 11.10, 11.17, 11.22, 11.29, 11.30, 11.32

Page 8: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Programming Assignment- Project #1

• In this project you use MATLAB’s built in function rand to determine how many times on average you have to flip a coin to get a string of say 6 or 7 heads in a row.

This assignment is listed as Project #10 on the website.

Page 9: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Programming Assignment- Project #2

• This project explores 3-D plotting. You will be determining the electric field strength (E-field) developed by several electric charges lying on a flat surface, then plot the field strengths as a function of position. This assignment will give you some familiarity with 3-D plotting and the power of MATLAB to visualize solutions. This is listed as project #11 on the website.

Page 10: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Assignments• The percent symbol % is used to define

a comment, use this following the MATLAB prompt to add your name and assignment number to your work

>>% Joe Mixsell>>% Assignment 3.4

Page 11: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Assignments

• Many assignment require you to print the Edit window, the Command Window and the Figure window(s). Just print them all and staple them together when you turn them in. Remember to clear the command window before your final run to start with a clean slate.

Page 12: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

More on Assignments• The first few assignments can

easily be done with paper and pencil and a calculator but you need to do them using MATLAB. Only outputs from MATLAB will be accepted.

Page 13: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

An Engineering Problem-Solving Methodology

• Step 1: State the problem clearly.• Step 2: Describe the inputs and

outputs.• Step 3: Work the problem by hand with

a set of simple data.• Step 4: Develop the MATLAB solution• Step 5: Test the solution with real data

Page 14: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Getting StartedExample 1

d = ½ * g * t^2

where d is the distance a body falls freely in a gravitation field during t seconds.

Example 2

x(t) = exp (-alpha * t ) * cos ( omega * t )

i.e, our suspension system we studied previously briefly using Excel

Page 15: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Example I• Using MATLAB we want to create a

table of values of time and distance for time increments between 0 and 10 seconds.

Page 16: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Example II• Using MATLAB we’ll do an analysis

of a suspension system and plot position versus time as the system responds to an initial displacement.

Page 17: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Continuing with today’s Discussion

• MATLAB Help and Demos• Introduce various MATLAB windows• Use the Command Window• Use the Edit Window• View results in the Command

Window and the Graphics Window

Page 18: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Discussion Next Class- Chapter 2- MATLAB Environment

• MATLAB variables• Working with Matrices• Scalar Operations• Precedence of Arithmetic Operators• Array Operations• Saving your Work

– Saving Variables– M-files (Writing and saving programs)

Page 19: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

MATLAB Discussion Sequence

• To prepare for the projects we will complete Chapters 2, 3, and 4 then jump to Chapter 6, 7 and 8 for several programming topics (functions, input statements, for loops and if statements ). At this point the first project will be assigned. Then back to Chapter 5 on plotting, continuing from that point.

Page 20: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

Scheduling our Midterm

• Assume we’ll set the midterm date to be in early part of March. It will include Excel, Powerpoint and MATLAB up to that point.

• We’ll finalize the date in a couple weeks.

Page 21: Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010

And now . . .

OFF TO MATLAB…

Learn by doing . . .