Skip to main content
Contents
Calc
Dark Mode Prev Next Profile
\(\newcommand\DLGray{\color{Gray}}
\newcommand\DLO{\color{BurntOrange}}
\newcommand\DLRa{\color{WildStrawberry}}
\newcommand\DLGa{\color{Green}}
\newcommand\DLGb{\color{PineGreen}}
\newcommand\DLBa{\color{RoyalBlue}}
\newcommand\DLBb{\color{Cerulean}}
\newcommand\ds{\displaystyle}
\newcommand\ddx{\frac{d}{dx}}
\newcommand\os{\overset}
\newcommand\us{\underset}
\newcommand\ob{\overbrace}
\newcommand\obt{\overbracket}
\newcommand\ub{\underbrace}
\newcommand\ubt{\underbracket}
\newcommand\ul{\underline}
\newcommand\tikznode[3][]
{\tikz[remember picture,baseline=(#2.base)]
\node[minimum size=0pt,inner sep=0pt,#1](#2){#3};
}
\newcommand\del{\nabla}
\newcommand\R{\mathbb{R}}
\newcommand\C{\mathcal{C}}
\newcommand\N{\mathcal{N}}
\newcommand\eps{\varepsilon}
\renewcommand\epsilon{\varepsilon}
\renewcommand\subset{\subseteq}
\newcommand\norm[1]{\|{#1}\|}
\newcommand\matrixbrackets[4][1]{
\draw (#3,#2) -- (\fpeval{#3+0.2},#2);
\draw (#3,#1) -- (#3 ,#2);
\draw (#3,#1) -- (\fpeval{#3+0.2},#1);
\draw (#4,#2) -- (\fpeval{#4-0.2},#2);
\draw (#4,#1) -- (#4 ,#2);
\draw (#4,#1) -- (\fpeval{#4-0.2},#1);
}
\tikzstyle{circle node 0}=[fill=white, draw=black, shape=circle, inner sep=0pt]
\tikzstyle{circle node 2}=[fill=white, draw=black, shape=circle, inner sep=2pt]
\tikzstyle{hrect node}=[fill=white, draw=black, inner sep=2pt, outer sep=3pt]
\tikzstyle{vrect node}=[fill=white, draw=black, inner sep=0pt, outer sep=0pt]
\tikzstyle{hidden node 0}=[inner sep=0pt, outer sep=0pt]
\tikzstyle{hidden node 2}=[fill=white, inner sep=2pt, outer sep=2pt]
\tikzstyle{rect node 1}=[fill=white, inner sep=2pt, outer sep=0pt]
\tikzstyle{rect node 2}=[fill=white, draw=black, inner sep=2pt, outer sep=0pt]
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Exercises π€π Conceptual Questions
1.
(a) Purpose of a Function.
A MATLAB function is most useful when you want to:
clear the Command Window automatically
store a long list of comments
create a reusable tool that takes inputs and returns outputs
avoid using variables
(b) File Name Match.
If a function is named
coin_total, then its file should be saved as
coin_total.m.
True.
Matching the file name to the function name prevents βfunction not foundβ and naming errors.
False.
Matching the file name to the function name prevents βfunction not foundβ and naming errors.
(c) Function Workspace.
Variables created inside a function automatically appear in the Workspace after the function finishes.
True.
A function uses its own workspace, so its internal variables do not automatically become Workspace variables.
False.
A function uses its own workspace, so its internal variables do not automatically become Workspace variables.
(d) Calling a Function.
Which of the following is a function call with three inputs?
f = 2, 3, 4
f(2; 3; 4)
f(2, 3, 4)
f = (2, 3, 4)
(e) Multiple Outputs.
To store two outputs from a function, you should write:
a, b = f(x)
(a, b) = f(x)
[a, b] = f(x)
a = f(x), b
(f) Function Header Meaning.
In the header
function y = f(x), which symbol represents the output?
(g) Calling Functions from Scripts.
A script can call a function that you wrote (for example,
coin_total), as long as the function file is available in the Current Folder (or on the path).
True.
This is one of the main benefits of functions: they simplify scripts by packaging common computations.
False.
This is one of the main benefits of functions: they simplify scripts by packaging common computations.
(h) Matching the Description.