{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 3

# Lecture 3 - E7 Spring 2010 Lecture 3 Raja Sengupta College...

This preview shows pages 1–7. Sign up to view the full content.

E7 Spring 2010: Lecture 3 Raja Sengupta College of Engineering University of California, Berkeley

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Textbook Sections • 3.2
Topics Programming functions in matlab The scope of a variable

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example: Programming functions help function Write a program to compute the length of a vector in Reals 2 2 2 2 x1 is 2 1 vector a of length The x x x + ! " # \$ % &
Steps Create and open an M-file with the same name as the function These are the contents of vectorLength.m function len = vectorLength(x1,x2) len = sqrt(x1^2+x2^2); end To execute the function you type – vectorLength(1,1) for example, or – blah = vectorLength(1,1) for example In the second case the number output by vectorLength will be assigned to the variable blah . This means it is stored for future use – Try blah^2 or sin(blah) Matlab will only find your function if you are in the directory containing the function or you have added the directory to the matlab search path for functions.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Type
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}