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

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

View Full Document Right Arrow Icon
E7 Spring 2010: Lecture 3 Raja Sengupta College of Engineering University of California, Berkeley
Background image of page 1

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

View Full DocumentRight Arrow Icon
Textbook Sections • 3.2
Background image of page 2
Topics • Programming functions in matlab • The scope of a variable
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 + ! " # $ % &
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Type A domain and range for my function might be
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2010 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 13

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

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online