1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# Functions
This directory contains the functions written throught the course.
* days.m
* falsePositive.m
* heun.m
* luFactor.m
* simpson.m
* spacialMatrix.m
---
## [days.m](days.m)
Function to count the total days elapsed in a year according to a given date.
The syntax of the function is `days(<months>, <days>, <leap>)` where `<months>` is a integer (1-12). `<days>` is an integer from 1-31 and `<leap>` accounts for leap years.
### Input
* `months` - month number (1-12). Example: `8` represents August.
* `days` - day number of the month.
* `leap` - indicates if the year is a leapyear or a regular year. `0` for regular and `1` for leap year.
### Output
`nd` - number of days elapsed in the year.
### Example:
`days(8,4,0)` represents August 8th in a regular year (non-leap year).
---
## [falsePositive.m](falsePositive.m)
Function finds the root of an anonymous function using the false position method.
Synopsis: `[root, fx, ea, iter] = falsePosition(func, xl, xu, es, maxit, varargin)`.
### Input
`func` - the function being evaluated.
`xl` - lower bound guess.
`xu` - upper bound guess.
`es` - desired relative error (default 0.0001%)
`maxit` - maximum number of iterations (default 200)
`varargin` - any additional parameters used by the function
### Output
`root` - estimated root location.
`fx` - function evaluated at root location.
`ea` - approximated relative error (%).
`iter` - number of iterations performed.
### Notes:
Known issue: the output of `iter` needs fixing. The output is incorrect.
---
## [heun.m](heun.m)
Uses the heun method to integrate an ODE.
Synopsis: `[t,y] = Heun(dydt,tspan,y0,h)`.
### Input
`dydt` -the differential equation of interest (must be anonymous function).
`tspan` - the initial and final values of the independent variable as a vector with length=2 [ti,tf].
`y0` - the initial value of the dependent variable.
`h` - step size.
`es` - stopping criterion (%), optional (default = 0.001).
`maxit` - maximum iterations of corrector, optional (default = 50).
### Output
`t` - vector of independent variable values
`y` - vector of solution for dependent variable
### Notes:
This function needs some working on to compute a correct solution when using multiple steps with an irregular step size at the end.
---
## [luFactor.m](luFactor.m)
Performs LU decomposition with pivoting.
Synopsis: `[L, U, P] = luFactor(A)`.
### Input
`A` - a coefficient matrix.
### Output
`L` - lower triangular matrix, with 1's along the diagonals.
`U` - upper triangular matrix.
`P` - the permutation matrix.
### Notes:
Be cautious when using this function on bigger matrices. The `L` variable is known to be incorrect.
---
## [simpson.m](simpson.m)
Evaluates the integral of two vectors by Simpsons 1/3 rule.
Synopsis: `[I] = Simpson(x, y)`
### Input
`x` - the vector of equally spaced independent variable.
`y` - the vector of function values with respect to x.
### Output
`I` - numerical calculated integral.
### Notes:
The current state of this function is **deprecated**. The algorithm fails compute the correct trapeziodal rule given 2 data points as well as 3 data points. Thus, failing to solve real problem. Pull requests are welcomed.
---
## [specialMatrix.m](specialMatrix.m)
|