12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

33 ! 36 $ 39 ’ 42 * 45 - 48 034 " 37 % 40 ( 43 + 46 . 49 135 # 38 & 41 ) 44 , 47 / 50 2Typing char(7) rings the bell.Exercise 9 (Page 80)The strvcat function is used instead <strong>of</strong> char because it ignores emptystrings in the input; the char function doesn’t:>> char(’’,’The’,’’,’quick’)ans =Thequick>> strvcat(’’,’The’,’’,’quick’)ans =ThequickIf char were used instead <strong>of</strong> strvcat, the result would always begin witha blank line.Exercise 10 (Page 83)The problem is to deal with the two cases: (1) where the name <strong>of</strong> afunction or m-file is given, such as ‘sin’, <strong>and</strong> (2) where the function itselfis given, such as ‘sin(x)’. The difference here boils down to whetherthe string input contains brackets or not (see hint). In other cases thestring input might not contain brackets, but would contain charactersused in defining a function, such as +, -, *, /, or. (as in t.^2). Theascii values for these characters are all less than 48, so we detect thepresence <strong>of</strong> a function (rather than a function name) by checking theinput string for ascii values less than 48. If this is the case, we makethe input string into an inline function before passing it to feval:function funplot(f,lims)% Simple function plotter.% Test for characters whose presence would imply that f% is a function (not a function name):if any(f

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!