Skip to content

Commit 1ca385c

Browse files
committed
2 parents 12d58ab + e128f60 commit 1ca385c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
A collection of MATLAB scripts.
44

5+
The input values for each function are generally not validated other than their lengths. If an error such as division by 0 occurs, it will propagate. Please refer to each function's help documentation for additional information.
6+
57
### Table of Contents
68

79
1. [Tridiagonal LU Decomposition Matrix Solver](#Tridiagonal-LU-Decomposition-Matrix-Solver)
8-
a. [Example](#Example)
10+
a. [Example 1](#Example)
11+
2. [Least-Square Plot Using QR Decomposition](#Least-Square-Plot-Using-QR-Decomposition)
12+
b. [Example 2](#Example-1)
913

1014
### Tridiagonal LU Decomposition Matrix Solver
1115

@@ -36,3 +40,27 @@ z =
3640
x =
3741
1 1 1 1 1
3842
```
43+
### Least-Square Plot Using QR Decomposition
44+
45+
This script solves `Ax = y` for the n x 1 vector `x` in the least-square sense using QR decomposition. It also plots the least-square fit function along with the input coordinates for comparison.
46+
47+
The input n x 1 `basis` functions (with m x 1 input `t`) are used to form the m x n matrix `A`. For example, for n = 2 basis functions `b_1(t) = e^-t` and `b_2(t) = e^-2t` with m = 3 input coordinates given by `t = [0; 1; 2]` and `y = [0; 2; 1.06]`, we get the following 3 x 2 matrix:
48+
49+
```
50+
[ e^0 e^0 ]
51+
A = [ e^-1 e^-2 ]
52+
[ e^-2 e^-4 ]
53+
```
54+
55+
Two assumptions made for the script are: `A` has rank n and m >= n.
56+
57+
##### Example
58+
59+
```
60+
>> [x] = lsquare_plot_with_qr([0;.5;1;1.3;2;3], [0;1.6;2;1.93;1.06;0.38], {@(t)exp(-t), @(t)exp(-2*t)})
61+
62+
x =
63+
8.3282
64+
-8.4245
65+
```
66+
<img src="https://raw.githubusercontent.com/onezerosix/misc-matlab-scripts/master/pictures/lsquare_plot_with_qr_example_graph.png" width="45%" alt="example plot">

0 commit comments

Comments
 (0)