MATLAB Tutorial for Engineering Students, Slides of Computational Methods

An overview of matlab learning goals, systems of linear equations, left division, matrix inverse, and programming style. It includes examples, exercises, and tips for using matlab in engineering applications.

Typology: Slides

2012/2013

Uploaded on 04/30/2013

bipasha
bipasha šŸ‡®šŸ‡³

4.4

(30)

159 documents

1 / 37

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chp1 MATLAB
OverView: Part-2
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download MATLAB Tutorial for Engineering Students and more Slides Computational Methods in PDF only on Docsity!

Chp1 MATLAB

OverView: Part-

Learning Goals

  • Turn On MATLAB and use as a calculator
  • Create Basic Cartesian Plots
  • Write and Save simple ā€œScriptā€ Program-

files

  • Execute Conditional Statements
    • IF, THEN, ELSE, >, <, >=, etc.
  • Execute Loop Statements
    • FOR & WHILE

Systems of Linear Equations cont

  • We Will Use MATLAB’s ā€œLeftā€ Division Solver
  • Write the System of Eqns (below) in Matrix/Array Form ļ‚§ In MATLAB need to InPut the - 4x4 COEFFICIENT Matrix, A - 4x1 CONSTRAINT Vector, b

























= 















































āˆ’

āˆ’

āˆ’ āˆ’

0

0

12

0

0 0 1 1000

1 1 1 0

0 1 0 0

1 0 1 2000

2

1

x

o

I

V

V

V

0 1 0 0 12 V

1 2

1 2

1 2

1 2

o x

o x

o x

o x

V V V I
V V V I
V V V I
V V V I

A (^) b

 ā‹… x =



Systems of Linear Equations cont

  • Use MATLAB to Solve 4Eqns in 4Unkowns >> A = [1,0,-1,-2000; 0,1,0,0; 1,-1,1,0; 0,0,1,-1000]; >> b = [0;12;0;0]; >> Soln = A\b Soln = **9.

0.**

Row Separator Left Division ļ‚§ Thus the Solution by MATLAB

  1. 003 Amps

3 Volts

12 Volts

9 Volts

2

1

x

o

I
V
V
V

Left Div & Matrix Inverse

  • Use MATLAB to Solve 4Eqns in 4Unkowns >> A = [1,0,-1,-2000; 0,1,0,0; 1,-1,1,0; 0,0,1,-1000]; >> b = [0;12;0;0]; >> Soln = A\b

The Matrix ā€œInverseā€ (More on This Later)

ļ‚§ By MTH

  • x is the Solution Vector

x b

A =

x b

A A = A

( ) x x b

A A = = A

x b

= A \

Performing MATLAB Ops

  • You can perform operations in MATLAB in two ways:
  1. In the interactive mode, in which all commands are entered directly in the Command window
  2. By running a MATLAB program stored in script ā€œmā€ file.
  • A Script file contains MATLAB commands, so running it is equivalent to typing all the commands - one at a time - at the Command window prompt.
  • Run the file by typing its name at the Command window prompt

MATLAB Editor/Debugger

Script File Usage

  • The name of a script file must begin with a letter , and may include digits and the underscore character, up to 63 characters.
  • Do not give a script file the same name as a variable
  • Do not give a script file the same name as a MATLAB command or function. - You can check to see if a command, function or file name already exists by using the exist command

Locating Program Errors

  • To locate program errors, try:
    1. Use a simple version of the problem which can be checked by hand to Test your program
    2. Display any intermediate calculations by removing semicolons at the end of statements.
    3. Use the debugging features of the Editor/Debugger.

Programming Style

1. Comments section

a. The nam e of the program and any key words in the first line. b. The date created, and the creators' names in the second line. c. The definitions of the variable names for every input and output variable.

  • Include definitions of variables used in the calculations and units of measurement for all input and all output variables! d. The (file)name of every user-defined function called by the program.

InPut/OutPut Commands

Command Description

disp(A) Displays the contents, but notthe name, of the array A.

disp(’text’) Displays the text string enclosed within quotes.

x = input(’text’)

Displays the text in quotes, waits for user input from the keyboard, and stores the value in x.

x = input(’text’,’s’)

Displays the text in quotes, waits for user input from the keyboard, and stores the input as a TEXT STRING in x.

Script File Example

  • Problem: The speed v of a falling object

dropped with no initial velocity is given as a

function of time t by v = gt.

  • Where g is the Acceleration of Gravity; a CONSTANT = 32.2 ft/s^2
  • Use MATLAB to Plot v as a

function of t for 0 ≤ t ≤ tf

  • Where tf is the final time entered by the user.

Exploit the TextBook

  • Throughout each chapter margin notes identify where key terms are introduced.
  • Each chapter contains tables summarizing the MATLAB commands introduced in that chapter.
  • At the end of each chapter is a summary guide to the commands covered in that chapter.
  • Appendix A contains tables of MATLAB commands , grouped by category, with the appropriate page references.
  • There are three indexes.
    1. lists MATLAB commands and symbols,
    2. lists SimuLink blocks
    3. lists topics.

MATLAB Help → Hidden Tab