summaryrefslogtreecommitdiff
path: root/Functions/README.md
blob: 8e881b33d95f98d9c10958c8a9c03124f751cf9a (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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)

# specialMatrix.m
Function returns a special matrix A with the following criteria:
- The value of each element in the first row is the number of the column.
- The value of each element in the first column is the number of the row.
- The rest of the elements each has a value equal to the sum of the element above it and element to the left.
- The function returns a sensible error if the user does not input exactly two arguments.

 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
* `A` - special matrix with the appropriate rules

## Notes:
This function has not much of a practical application, rather a very good exercise for beginners to get started with the basics of matrix manipulation and user-defined functions.