Lecture6 - Lecture 6: More on Functions in MATLAB...

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

View Full Document Right Arrow Icon
Lecture 6: More on Functions in MATLAB Department of Mathematics University of California, Berkeley Math 98 Introduction to MATLAB programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements HW1 Solutions are up http://math.berkeley.edu/ cinnawu/HW2sol.m. HW3 is posted http://math.berkeley.edu/ cinnawu/HW3.pdf.
Background image of page 2
A few Important concepts from computer science. .. Today We will focus on calling functions indirectly (in MATLAB) using function handles.
Background image of page 3

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

View Full DocumentRight Arrow Icon
functions and function handle Recall cube.m function Y= cube(X) Y = X 3; evaluate this function (as if we actually typed in cube(4)) >>feval(’cube’,4 ) >>ans = 64 Make an inline function >>f=inline(’x 3’ ) >>f = Inline function: f(x)=x 3 Use the @ command >>f=@(x)(’x 3’ ) >>f =@(x)x 3
Background image of page 4
functions and function handle (continued) Use the @ command >>f=@cube >>f =@cube Use a function handle >>funStr=’cube’; >>cubeFun=str2Func(cube) >> cubeFun(9) >> ans=729 What a function handles is An internal MATLAB data type, which can be used to call a function. For example, cubeFun is able to call the function cube .
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/21/2012 for the course MATH 98 taught by Professor Instuctor during the Spring '08 term at University of California, Berkeley.

Page1 / 9

Lecture6 - Lecture 6: More on Functions in MATLAB...

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

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