====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
gibson:teaching:fall-2013:math445:lecture5functions [2013/09/10 13:02] gibson |
gibson:teaching:fall-2013:math445:lecture5functions [2013/09/10 13:05] (current) gibson |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | The functions we wrote in class are provided below. Each has a description of what we're illustrating, the filename, and then the file contents. You can cut & paste as needed. | + | The functions we wrote in class are provided below. Each lists the filename, a description of what we're illustrating, and then the file contents. You can cut & paste as needed. |
- | A super-simple example of a function that takes one argument and returns one value | ||
- | square.m | + | square.m : a super-simple example of a function that takes one argument and returns one value |
<code> | <code> | ||
function s = square(x); % declare a function named square | function s = square(x); % declare a function named square | ||
Line 13: | Line 12: | ||
</code> | </code> | ||
- | An example of a function that takes two arguments | ||
- | pow.m | + | pow.m : an example of a function that takes two arguments |
<code> | <code> | ||
function y = pow(x,n) % this function takes two arguments | function y = pow(x,n) % this function takes two arguments | ||
Line 25: | Line 23: | ||
</code> | </code> | ||
- | An example of a function with two return values | ||
- | square_cube.m | + | square_cube.m : an example of a function with two return values |
<code> | <code> | ||
Line 40: | Line 37: | ||
- | + | isOdd.m : an example of an if-else statement | |
- | + | ||
- | + | ||
- | An example of an if-else statement. | + | |
- | + | ||
- | isOdd.m | + | |
<code> | <code> | ||
function r = isOdd(n) | function r = isOdd(n) | ||
Line 58: | Line 50: | ||
- | A simpler example of an if-else statement | + | isTwo.m : a simpler example of an if-else statement |
- | + | ||
- | isTwo.m | + | |
<code> | <code> | ||
function r = isTwo(n); | function r = isTwo(n); | ||
Line 76: | Line 66: | ||
</code> | </code> | ||
- | An simple example of a for-loop, with no arguments and no return value | + | printtoten.m : a simple example of a for-loop, with no arguments and no return value |
- | + | ||
- | printtoten.m | + | |
<code> | <code> | ||
function printtoten(); | function printtoten(); | ||
Line 91: | Line 79: | ||
</code> | </code> | ||
- | A more meaningful example of a for-loop | ||
- | sumtoten.m | + | sumtoten.m : a more meaningful example of a for-loop |
<code> | <code> | ||
function s = sumtoten(); | function s = sumtoten(); | ||
Line 107: | Line 94: | ||
</code> | </code> | ||
- | A home-grown matrix-vector multiply function | ||
- | matvecmult.m | + | matvecmult.m : a home-grown matrix-vector multiply function |
<code> | <code> | ||
function y = matvecmult(A,x); | function y = matvecmult(A,x); |