Week 8, Chapter 6, ENCMP Flashcards
What do functions do?
they accept input arguments and return output arguments after performing some type fo calculation
How should primary functions’ names be saves?
they should have the same name as the function name.
Input and output arguments are merely _______ for values to be passed/returned
Input and output arguments are merely placeholders for values to be passed/returned
Where are two places that functions can be made
Inside the file and outside in a script.m file
when making a separate file for a function command, what must be at the beginning of the file
the function file must begin with the keyword function and should be named with the same filename as the function name
Can functions take and return vector inputs and outputs ?
yes
What is the benifit of functions being able to take and return vector inputs and outputs.
Then you can give a function a vector of values and it will compute them inside of the function and then return the values as another set of vectors.
What is an ‘overloadable’ property
It is a property that is sometimes used to define a vector calculated inside of an function
How do you make a function that will accept multiple input and output arguments
The function header should look something like this: %function [vol,SA] = cone_vol_SA(R,H)
What is a call-by-value or pass-by-value
•When a function is called, MATLAB makes a copy of the actual input arguments and then passes them to the function
This means that if the function modifies these arguments, it will not affect the data available to the caller
What are some advantages of using functions.
- Independent testing of sub-tasks
- Reusable code
- Isolation from unintended side-effects
- Easier maintenance of programs
What are some potential disadvantages of using functions
Input arguments passed by value to the function must be copied to a new memory location for use in the function’s workspace
When passing large arrays this can be time-consuming and occupy memory
What is a base workspace
it is the command winder workspace
What is a local variable
When a function is defined inside of their own file they have their own workspace. It is important to note that the main file cannot access these local files
What is a breakpoint?
Setting breakpoints pauses the execution of your MATLAB® program so that you can examine values where you think an issue might have occurred