Skip to content

Commit

Permalink
Fixed bug in numerical linear algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
jlperla committed Jan 4, 2024
1 parent 8517cdc commit 7c798e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ julia format_myst.jl lectures/getting_started_julia/getting_started.md
```
As a helper, you can call a shell script to do it for an entire folder
```bash
bash format_all_directory.sh lectures/dynamic_programming
```
or to also do the unicode substitutions
```bash
bash format_all_directory.sh lectures/dynamic_programming true
```
Expand Down
11 changes: 4 additions & 7 deletions lectures/tools_and_techniques/numerical_linear_algebra.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The theme of this lecture, and numerical linear algebra in general, comes down t
---
tags: [hide-output]
---
using LinearAlgebra, Statistics, BenchmarkTools, SparseArrays, Random, Parameters
using LinearAlgebra, Statistics, BenchmarkTools, SparseArrays, Random
Random.seed!(42); # seed random numbers for reproducibility
```

Expand Down Expand Up @@ -491,14 +491,11 @@ To manually use the QR decomposition in solving linear least squares:

```{code-cell} julia
Af = qr(A)
Q = Af.Q
R = [Af.R; zeros(N - M, M)] # Stack with zeros
@show Q * R ≈ A
x = R \ Matrix(Q)' * b # simplified QR solution for least squares
@show Af.Q * Af.R ≈ A
x = Af.R \ (Matrix(Af.Q)' * b) # simplified QR solution for least squares
```

This stacks the `R` with zeros, but the more specialized algorithm would not multiply directly
in that way.
See [here](https://discourse.julialang.org/t/qr-decomposition-with-julia-how-to/92508/8) for more, thought keep in mind that more specialized algorithm would be more efficient.

In some cases, if an LU is not available for a particular matrix structure, the QR factorization
can also be used to solve systems of equations (i.e., not just LLS). This tends to be about 2 times slower than the LU
Expand Down

0 comments on commit 7c798e8

Please sign in to comment.