MATLAB Basics: Learning Goals, Environment, Scripts and Functions, Arithmetic Operations, , Slides of Calculus for Engineers

An overview of various topics in matlab, including learning goals, matlab environment, scripts and functions, arithmetic operations, work session commands, special variables and constants, complex numbers, formatting, discrete math functions, arrays, polynomial roots, common math functions, printing, and diary function. It covers the basics of using matlab as a calculator, creating basic cartesian plots, writing and saving simple scripts, executing conditional statements and loop statements.

Typology: Slides

2012/2013

Uploaded on 03/26/2013

abduu
abduu 🇮🇳

4.4

(49)

195 documents

1 / 49

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Engr/Math/Physics 25
Chp1 MATLAB
OverView: Part-1
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
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download MATLAB Basics: Learning Goals, Environment, Scripts and Functions, Arithmetic Operations, and more Slides Calculus for Engineers in PDF only on Docsity!

Engr/Math/Physics 25

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

>> %Use MATLAB As Example Cmd Window Session Calculator

>> 17 ans = 323*

>> 77/19 -4. ans = -0.

>> 64^(1/3) + 32^0. ans = 6

*>> (7+11)2. ans = 45

L = 14. L =

W = 13. W =

Area = LW Area = 191.*

Script & Function Files (m-files)

  • SCRIPTS and FUNCTIONS in MATLAB are

stored in text files that end with the extension

“.m”

  • These files are called m-files
  • SCRIPTS (a.k.a. “programs”)
  • Scripts files are useful for automating tasks that

may need to be repeated.

  • They have no input/output parameters
  • They can (but probably shouldn’t) share variables

with the command workspace

Script & Function Files (m-files)

  • SCRIPTS (cont.)
    • Scripts are sequences of interactive statements stored in a file - i.e., They look liked Stored versions of Command Window Sessions
  • FUNCTIONS (a.k.a. “subroutines”)
    • Function m-files are MATLAB subprograms analogous to FORTRAN Subroutines, or C functions
    • They communicate with the command window and other functions via a list of INPUT and OUTPUT PARAMETERS

Entering Commands & Expressions

  • MATLAB retains your previous keystrokes.
  • Use the up-arrow (↑) key to scroll back through

the commands.

  • Press the key (↑) once to see the previous entry,

and so on.

  • Use the down-arrow (↓) key to scroll forward.
  • Edit a line using the left (←) & right (→) arrow

keys the Backspace key, and the Delete key.

  • Press the Enter key to execute the command

Arithmetic Scalar Operations

Symbol Operation MATLAB

^ exponentiation:^ ab^ a^b

* multiplication:^ ab^ a*b

/ right division:^ a/b^ a/b

\ left division:^ b/a^ a\b

+ addition:^ a^ +^ b^ a + b

  • subtraction:^ a^ -^ b^ a - b

 LEFT-Division A\ b read from

Right-to-Left as: “b divided by A ”C

Precedence Examples

**ans = 23

8 + (3*5) ans =

23

(8 + 3)* ans = 55**

>>4^2128/4*

**ans = 0

4^2128/(42) ans = 3*

Precedence Examples cont.

>> 3*4^2 + 5

**ans = 53

(34)^2 + 5 ans = 149*

>>27^(1/3) + 32^0.

**ans = 5

27^1/3 + 32^0. ans = 11**

Work Session Commands

Command Description

clc (^) Clears the Command window clear (^) Removes all variables from memory clear v1 v2 Removes the variables v1 and v from memory exist(‘var’) (^) Determines if a file or variable exists having the name „var‟ quit (^) Stops MATLAB

Work Session Commands cont.

Command Description

who Lists the variables currently inmemory

whos

Lists the current variables and sizes, and indicates if they have imaginary parts. : (Colon) Generates an array having regularlyspaced elements , (Comma) (^) Separates elements of an array

; (Semicolon) Suppresses screen printing; alsodenotes a new row in an array

(Ellipsis) (^) Continues a line

Special VARS & const’s

Command Description

ans Temporary variable containing the mostrecent answer

eps Specifies the accuracy of floating pointprecision i,j (^) The imaginary unit (-1) Inf (^) Infinity (unbounded magnitude) NaN Indicates an undefined numerical result;a.k.a., N ot a N umber pi (^) The number pi (3.14159...)  NaN returns the IEEE arithmetic representation for Not-a-Number (NaN). These result from operations which have undefined numerical results;. e.g., try Q = 0/

The Complex Plane

Im (i or j)

Re

FABi or FABj