This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| gibson:teaching:fall-2014:math445:lecture9-diary [2014/10/14 12:50] gibson [for loops] | gibson:teaching:fall-2014:math445:lecture9-diary [2014/10/15 12:45] (current) gibson [example: solving a nonlinear equation] | ||
|---|---|---|---|
| Line 40: | Line 40: | ||
|  |  | ||
| end | end | ||
| + | </code> | ||
| **example 4:** Write a function that computes the factorial of //n//. | **example 4:** Write a function that computes the factorial of //n//. | ||
| + | |||
| + | <code matlab> | ||
| function p = factorial(n) | function p = factorial(n) | ||
| % return the factorial of n (assume n is a positive integer) | % return the factorial of n (assume n is a positive integer) | ||
| Line 51: | Line 54: | ||
|  |  | ||
| end | end | ||
| + | </code> | ||
| **The for loop is probably the single most important programming construct in numerical mathematics.** | **The for loop is probably the single most important programming construct in numerical mathematics.** | ||
| Line 67: | Line 71: | ||
| - | ===== example: solving a nonlinear equation ===== | + | |