add september notes & hw2 code / pdf

This commit is contained in:
Elizabeth Hunt 2023-09-25 10:36:23 -06:00
parent 2e284b7150
commit 58c73fd511
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
23 changed files with 730 additions and 10 deletions

View File

@ -11,7 +11,13 @@
(:file "package")))
(:module "approx"
:components
((:file "derivative" :depends-on ("package"))
((:file "maceps" :depends-on ("package"))
(:file "derivative" :depends-on ("package"))
(:file "package")))
(:module "vector"
:components
((:file "distance" :depends-on ("norm" "package"))
(:file "norm" :depends-on ("package"))
(:file "package")))))))
@ -23,7 +29,9 @@
:components ((:module "tests"
:components
((:file "table" :depends-on ("suite"))
(:file "maceps" :depends-on ("suite"))
(:file "approx" :depends-on ("suite"))
(:file "vector" :depends-on ("suite"))
(:file "suite"))))
:perform (asdf:test-op (o c) (uiop:symbol-call
:fiveam :run!

13
cl/src/approx/maceps.lisp Normal file
View File

@ -0,0 +1,13 @@
(in-package :lizfcm.approx)
(defun compute-maceps (val f)
(let* ((h val)
(a val)
(err val))
(loop while (> err 0)
do
(progn
(setf h (/ h 2)
err (abs (- (funcall f (+ a h))
(funcall f a)))))
collect (list a h err))))

View File

@ -1,4 +1,5 @@
(in-package :cl-user)
(defpackage lizfcm.approx
(:use :cl)
(:export :derivative-at))
(:export :derivative-at
:compute-maceps))

7
cl/src/package.lisp Normal file
View File

@ -0,0 +1,7 @@
(in-package :cl-user)
(defpackage lizfcm.vector
(:use :cl)
(:export
:n-norm
:max-norm
:distance))

View File

@ -0,0 +1,6 @@
(in-package :lizfcm.vector)
(defun distance (v1 v2 norm)
(let* ((d (mapcar #'- v1 v2))
(length (funcall norm d)))
length))

17
cl/src/vector/norm.lisp Normal file
View File

@ -0,0 +1,17 @@
(in-package :lizfcm.vector)
(defun p-norm (p)
(lambda (v)
(expt
(reduce (lambda (acc x)
(+ acc x))
(mapcar (lambda (x)
(abs
(expt x p)))
v))
(/ 1 p))))
(defun max-norm (v)
(reduce (lambda (acc x)
(max acc x))
v))

View File

@ -0,0 +1,7 @@
(in-package :cl-user)
(defpackage lizfcm.vector
(:use :cl)
(:export
:p-norm
:max-norm
:distance))

25
cl/tests/maceps.lisp Normal file
View File

@ -0,0 +1,25 @@
(defpackage lizfcm/tests.maceps
(:use :cl
:fiveam
:lizfcm.approx
:lizfcm.utils
:lizfcm/tests)
(:export :approx-suite))
(in-package :lizfcm/tests.maceps)
(def-suite maceps-suite
:in lizfcm-test-suite)
(in-suite maceps-suite)
(test maceps
:description "double precision provides precision about (mac eps of single precision) squared"
(let* ((maceps-computation-double (compute-maceps 1.0d0
(lambda (x) x)))
(maceps-computation-single (compute-maceps 1.0
(lambda (x) x)))
(last-double-h (cadar (last maceps-computation-double)))
(last-single-h (cadar (last maceps-computation-single))))
(is (within-range-p
(- last-double-h (* last-single-h last-single-h))
0
last-single-h))))

31
cl/tests/vector.lisp Normal file
View File

@ -0,0 +1,31 @@
(defpackage lizfcm/tests.vector
(:use :cl
:fiveam
:lizfcm.vector
:lizfcm.utils
:lizfcm/tests)
(:export :vector-suite))
(in-package :lizfcm/tests.vector)
(def-suite vector-suite
:in lizfcm-test-suite)
(in-suite vector-suite)
(test p-norm
:description "computes p-norm"
(let ((v '(1 1))
(length (sqrt 2))
(2-norm (p-norm 2)))
(is (within-range-p (funcall 2-norm v)
length
0.00001))))
(test vector-distance
:description "computes distance via norm"
(let ((v1 '(0 0))
(v2 '(1 1))
(dist (sqrt 2)))
(is (within-range-p (distance v1 v2 (p-norm 2))
dist
0.00001))))

179
homeworks/hw-2.org Normal file
View File

@ -0,0 +1,179 @@
#+TITLE: HW 02
#+AUTHOR: Elizabeth Hunt
#+STARTUP: entitiespretty fold inlineimages
#+LATEX_HEADER: \notindent \notag \usepackage{amsmath} \usepackage[a4paper,margin=1in,portrait]{geometry}
#+LATEX: \setlength\parindent{0pt}
#+OPTIONS: toc:nil
* Question One
Computing $\epsilon_{\text{mac}}$ for single precision numbers
#+BEGIN_SRC lisp :session t :results table
(load "../cl/lizfcm.asd")
(ql:quickload :lizfcm)
(let ((domain-values (lizfcm.approx:compute-maceps 1.0
(lambda (x) x))))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
#+END_SRC
(with many rows truncated)
| a | h | err |
| 1.0 | 0.5 | 0.5 |
| 1.0 | 0.25 | 0.25 |
| 1.0 | 0.125 | 0.125 |
| 1.0 | 0.0625 | 0.0625 |
| 1.0 | 1.9073486e-06 | 1.9073486e-06 |
| 1.0 | 9.536743e-07 | 9.536743e-07 |
| 1.0 | 4.7683716e-07 | 4.7683716e-07 |
| 1.0 | 2.3841858e-07 | 2.3841858e-07 |
| 1.0 | 1.1920929e-07 | 1.1920929e-07 |
| 1.0 | 5.9604645e-08 | 0.0 |
$\epsilon_{\text{mac}}$ \approx 5.9604 \cdot 10^{-8}
* Question Two
Computing $\epsilon_{\text{mac}}$ for double precision numbers:
#+BEGIN_SRC lisp :session t :results table
(let ((domain-values (lizfcm.approx:compute-maceps 1.0d0
(lambda (x) x))))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
#+END_SRC
(with many rows truncated)
| a | h | err |
| 1.0d0 | 0.5d0 | 0.5d0 |
| 1.0d0 | 0.25d0 | 0.25d0 |
| 1.0d0 | 0.125d0 | 0.125d0 |
| 1.0d0 | 0.0625d0 | 0.0625d0 |
| 1.0d0 | 0.03125d0 | 0.03125d0 |
| 1.0d0 | 0.015625d0 | 0.015625d0 |
| 1.0d0 | 0.0078125d0 | 0.0078125d0 |
| 1.0d0 | 0.00390625d0 | 0.00390625d0 |
| 1.0d0 | 0.001953125d0 | 0.001953125d0 |
| 1.0d0 | 7.105427357601002d-15 | 7.105427357601002d-15 |
| 1.0d0 | 3.552713678800501d-15 | 3.552713678800501d-15 |
| 1.0d0 | 1.7763568394002505d-15 | 1.7763568394002505d-15 |
| 1.0d0 | 8.881784197001252d-16 | 8.881784197001252d-16 |
| 1.0d0 | 4.440892098500626d-16 | 4.440892098500626d-16 |
| 1.0d0 | 2.220446049250313d-16 | 2.220446049250313d-16 |
| 1.0d0 | 1.1102230246251565d-16 | 0.0d0 |
Thus, $\epsilon_{\text{mac}}$ \approx 1.1102 \cdot 10^{-16}
* Question Three - |v|_2
#+BEGIN_SRC lisp :session t
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(2-norm (lizfcm.vector:p-norm 2)))
(lizfcm.utils:table (:headers '("x" "y" "2norm")
:domain-order (x y)
:domain-values vs)
(funcall 2-norm (list x y))))
#+END_SRC
| x | y | 2norm |
| 1 | 1 | 1.4142135 |
| 2 | 3 | 3.6055512 |
| 4 | 5 | 6.4031243 |
| -1 | 2 | 2.236068 |
* Question Four - |v|_1
#+BEGIN_SRC lisp :session t
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(1-norm (lizfcm.vector:p-norm 1)))
(lizfcm.utils:table (:headers '("x" "y" "1norm")
:domain-order (x y)
:domain-values vs)
(funcall 1-norm (list x y))))
#+END_SRC
| x | y | 1norm |
| 1 | 1 | 2 |
| 2 | 3 | 5 |
| 4 | 5 | 9 |
| -1 | 2 | 3 |
* Question Five - |v|_{\infty}
#+BEGIN_SRC lisp :session t
(let ((vs '((1 1) (2 3) (4 5) (-1 2))))
(lizfcm.utils:table (:headers '("x" "y" "max-norm")
:domain-order (x y)
:domain-values vs)
(lizfcm.vector:max-norm (list x y))))
#+END_SRC
| x | y | infty-norm |
| 1 | 1 | 1 |
| 2 | 3 | 3 |
| 4 | 5 | 5 |
| -1 | 2 | 2 |
* Question Six - ||v - u|| via |v|_{2}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
(2-norm (lizfcm.vector:p-norm 2)))
(lizfcm.utils:table (:headers '("v1" "v2" "2-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 2-norm)))
#+END_SRC
| v1 | v2 | 2-norm |
| (1 1) | (7 9) | 10.0 |
| (2 3) | (2 2) | 1.0 |
| (4 5) | (8 -1) | 7.2111025 |
| (-1 2) | (4 4) | 5.3851647 |
* Question Seven - ||v - u|| via |v|_{1}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
(1-norm (lizfcm.vector:p-norm 1)))
(lizfcm.utils:table (:headers '("v1" "v2" "1-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 1-norm)))
#+END_SRC
| v1 | v2 | 1-norm-d |
| (1 1) | (7 9) | 14 |
| (2 3) | (2 2) | 1 |
| (4 5) | (8 -1) | 10 |
| (-1 2) | (4 4) | 7 |
* Question Eight - ||v - u|| via |v|_{\infty}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4))))
(lizfcm.utils:table (:headers '("v1" "v2" "max-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 'lizfcm.vector:max-norm)))
#+END_SRC
| v1 | v2 | max-norm-d |
| (1 1) | (7 9) | -6 |
| (2 3) | (2 2) | 1 |
| (4 5) | (8 -1) | 6 |
| (-1 2) | (4 4) | -2 |

BIN
homeworks/hw-2.pdf Normal file

Binary file not shown.

243
homeworks/hw-2.tex Normal file
View File

@ -0,0 +1,243 @@
% Created 2023-09-25 Mon 09:52
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\notindent \notag \usepackage{amsmath} \usepackage[a4paper,margin=1in,portrait]{geometry}
\author{Elizabeth Hunt}
\date{\today}
\title{HW 02}
\hypersetup{
pdfauthor={Elizabeth Hunt},
pdftitle={HW 02},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 28.2 (Org mode 9.7-pre)},
pdflang={English}}
\begin{document}
\maketitle
\setlength\parindent{0pt}
\section{Question One}
\label{sec:orga203815}
Computing \(\epsilon_{\text{mac}}\) for single precision numbers
\begin{verbatim}
(load "../cl/lizfcm.asd")
(ql:quickload :lizfcm)
(let ((domain-values (lizfcm.approx:compute-maceps 1.0
(lambda (x) x))))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
\end{verbatim}
(with many rows truncated)
\begin{center}
\begin{tabular}{rrr}
a & h & err\\[0pt]
1.0 & 0.5 & 0.5\\[0pt]
1.0 & 0.25 & 0.25\\[0pt]
1.0 & 0.125 & 0.125\\[0pt]
1.0 & 0.0625 & 0.0625\\[0pt]
1.0 & 1.9073486e-06 & 1.9073486e-06\\[0pt]
1.0 & 9.536743e-07 & 9.536743e-07\\[0pt]
1.0 & 4.7683716e-07 & 4.7683716e-07\\[0pt]
1.0 & 2.3841858e-07 & 2.3841858e-07\\[0pt]
1.0 & 1.1920929e-07 & 1.1920929e-07\\[0pt]
1.0 & 5.9604645e-08 & 0.0\\[0pt]
\end{tabular}
\end{center}
\(\epsilon_{\text{mac}}\) \(\approx\) 5.9604 \(\cdot\) 10\textsuperscript{-8}
\section{Question Two}
\label{sec:orgdd79be1}
Computing \(\epsilon_{\text{mac}}\) for double precision numbers:
\begin{verbatim}
(let ((domain-values (lizfcm.approx:compute-maceps 1.0d0
(lambda (x) x))))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
\end{verbatim}
(with many rows truncated)
\begin{center}
\begin{tabular}{rrr}
a & h & err\\[0pt]
1.0d0 & 0.5d0 & 0.5d0\\[0pt]
1.0d0 & 0.25d0 & 0.25d0\\[0pt]
1.0d0 & 0.125d0 & 0.125d0\\[0pt]
1.0d0 & 0.0625d0 & 0.0625d0\\[0pt]
1.0d0 & 0.03125d0 & 0.03125d0\\[0pt]
1.0d0 & 0.015625d0 & 0.015625d0\\[0pt]
1.0d0 & 0.0078125d0 & 0.0078125d0\\[0pt]
1.0d0 & 0.00390625d0 & 0.00390625d0\\[0pt]
1.0d0 & 0.001953125d0 & 0.001953125d0\\[0pt]
1.0d0 & 7.105427357601002d-15 & 7.105427357601002d-15\\[0pt]
1.0d0 & 3.552713678800501d-15 & 3.552713678800501d-15\\[0pt]
1.0d0 & 1.7763568394002505d-15 & 1.7763568394002505d-15\\[0pt]
1.0d0 & 8.881784197001252d-16 & 8.881784197001252d-16\\[0pt]
1.0d0 & 4.440892098500626d-16 & 4.440892098500626d-16\\[0pt]
1.0d0 & 2.220446049250313d-16 & 2.220446049250313d-16\\[0pt]
1.0d0 & 1.1102230246251565d-16 & 0.0d0\\[0pt]
\end{tabular}
\end{center}
Thus, \(\epsilon_{\text{mac}}\) \(\approx\) 1.1102 \(\cdot\) 10\textsuperscript{-16}
\section{Question Three - |v|\textsubscript{2}}
\label{sec:org04608d9}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(2-norm (lizfcm.vector:p-norm 2)))
(lizfcm.utils:table (:headers '("x" "y" "2norm")
:domain-order (x y)
:domain-values vs)
(funcall 2-norm (list x y))))
\end{verbatim}
\begin{center}
\begin{tabular}{rrr}
x & y & 2norm\\[0pt]
1 & 1 & 1.4142135\\[0pt]
2 & 3 & 3.6055512\\[0pt]
4 & 5 & 6.4031243\\[0pt]
-1 & 2 & 2.236068\\[0pt]
\end{tabular}
\end{center}
\section{Question Four - |v|\textsubscript{1}}
\label{sec:orgfb57f3a}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(1-norm (lizfcm.vector:p-norm 1)))
(lizfcm.utils:table (:headers '("x" "y" "1norm")
:domain-order (x y)
:domain-values vs)
(funcall 1-norm (list x y))))
\end{verbatim}
\begin{center}
\begin{tabular}{rrr}
x & y & 1norm\\[0pt]
1 & 1 & 2\\[0pt]
2 & 3 & 5\\[0pt]
4 & 5 & 9\\[0pt]
-1 & 2 & 3\\[0pt]
\end{tabular}
\end{center}
\section{Question Five - |v|\textsubscript{\(\infty\)}}
\label{sec:org7bbdf04}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2))))
(lizfcm.utils:table (:headers '("x" "y" "max-norm")
:domain-order (x y)
:domain-values vs)
(lizfcm.vector:max-norm (list x y))))
\end{verbatim}
\begin{center}
\begin{tabular}{rrr}
x & y & infty-norm\\[0pt]
1 & 1 & 1\\[0pt]
2 & 3 & 3\\[0pt]
4 & 5 & 5\\[0pt]
-1 & 2 & 2\\[0pt]
\end{tabular}
\end{center}
\section{Question Six - ||v - u|| via |v|\textsubscript{2}}
\label{sec:orge36996c}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
(2-norm (lizfcm.vector:p-norm 2)))
(lizfcm.utils:table (:headers '("v1" "v2" "2-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 2-norm)))
\end{verbatim}
\begin{center}
\begin{tabular}{llr}
v1 & v2 & 2-norm\\[0pt]
(1 1) & (7 9) & 10.0\\[0pt]
(2 3) & (2 2) & 1.0\\[0pt]
(4 5) & (8 -1) & 7.2111025\\[0pt]
(-1 2) & (4 4) & 5.3851647\\[0pt]
\end{tabular}
\end{center}
\section{Question Seven - ||v - u|| via |v|\textsubscript{1}}
\label{sec:orgd1577f0}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
(1-norm (lizfcm.vector:p-norm 1)))
(lizfcm.utils:table (:headers '("v1" "v2" "1-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 1-norm)))
\end{verbatim}
\begin{center}
\begin{tabular}{llr}
v1 & v2 & 1-norm-d\\[0pt]
(1 1) & (7 9) & 14\\[0pt]
(2 3) & (2 2) & 1\\[0pt]
(4 5) & (8 -1) & 10\\[0pt]
(-1 2) & (4 4) & 7\\[0pt]
\end{tabular}
\end{center}
\section{Question Eight - ||v - u|| via |v|\textsubscript{\(\infty\)}}
\label{sec:org2661676}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4))))
(lizfcm.utils:table (:headers '("v1" "v2" "max-norm-d")
:domain-order (v1 v2)
:domain-values (mapcar (lambda (v1 v2)
(list v1 v2))
vs
vs2))
(lizfcm.vector:distance v1 v2 'lizfcm.vector:max-norm)))
\end{verbatim}
\begin{center}
\begin{tabular}{llr}
v1 & v2 & max-norm-d\\[0pt]
(1 1) & (7 9) & -6\\[0pt]
(2 3) & (2 2) & 1\\[0pt]
(4 5) & (8 -1) & 6\\[0pt]
(-1 2) & (4 4) & -2\\[0pt]
\end{tabular}
\end{center}
\end{document}

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -31,17 +31,18 @@ Table of Errors
(lizfcm.utils:table (:headers '("u" "v" "e_{abs}" "e_{rel}")
:domain-order (u v)
:domain-values *u-v*)
(fround (eabs u v) 4)
(fround (erel u v) 4))
(eabs u v)
(erel u v))
#+END_SRC
#+RESULTS:
| u | v | e_{abs} | e_{rel} |
| 1 | 0.99 | 0.0 | 0.0 |
| 1 | 1.01 | 0.0 | 0.0 |
| -1.5 | -1.2 | 0.0 | 0.0 |
| 100 | 99.9 | 0.0 | 0.0 |
| 100 | 99 | 0.0 | 0.0 |
| 1 | 0.99 | 0.00999999 | 0.00999999 |
| 1 | 1.01 | 0.00999999 | 0.00999999 |
| -1.5 | -1.2 | 0.29999995 | 0.19999997 |
| 100 | 99.9 | 0.099998474 | 0.0009999848 |
| 100 | 99 | 1 | 1/100 |
Look at $u \approx 0$ then $v \approx 0$, $e_{abs}$ is better error since $e_{rel}$ is high.

16
notes/Sep-13.org Normal file
View File

@ -0,0 +1,16 @@
* Homework 2
1. maceps - single precision
2. maceps - double precision
3. 2-norm of a vector
4. 1-norm of a vector
5. infinity-norm of a vector (max-norm)
6. 2-norm distance between 2 vectors
7. 1-norm distance between 2 vectors
8. infinity-norm distance

52
notes/Sep-15.org Normal file
View File

@ -0,0 +1,52 @@
* Taylor Series Approx.
Suppose f has $\infty$ many derivatives near a point a. Then the taylor series is given by
$f(x) = \Sigma_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$
For increment notation we can write
$f(a + h) = f(a) + f'(a)(a+h - a) + \dots$
$= \Sigma_{n=0}^{\infty} \frac{f^{(n)}(a)}{h!} (h^n)$
Consider the approximation
$e = |f'(a) - \frac{f(a + h) - f(a)}{h}| = |f'(a) - \frac{1}{h}(f(a + h) - f(a))|$
Substituting...
$= |f'(a) - \frac{1}{h}((f(a) + f'(a) h + \frac{f''(a)}{2} h^2 + \cdots) - f(a))|$
$f(a) - f(a) = 0$... and $distribute the h$
$= |-1/2 f''(a) h + \frac{1}{6}f'''(a)h^2 \cdots|$
** With Remainder
We can determine for some u $f(a + h) = f(a) + f'(a)h + \frac{1}{2}f''(u)h^2$
and so the error is $e = |f'(a) - \frac{f(a + h) - f(a)}{h}| = |\frac{h}{2}f''(u)|$
- [https://openstax.org/books/calculus-volume-2/pages/6-3-taylor-and-maclaurin-series]
+ > Taylor's Theorem w/ Remainder
** Of Deriviatives
Again, $f'(a) \approx \frac{f(a+h) - f(a)}{h}$,
$e = |\frac{1}{2} f''(a) + \frac{1}{3!}h^2 f'''(a) + \cdots$
$R_2 = \frac{h}{2} f''(u)$
$|\frac{h}{2} f''(u)| \leq M h^1$
$M = \frac{1}{2}|f'(u)|$
*** Another approximation
$\text{err} = |f'(a) - \frac{f(a) - f(a - h)}{h}|$
$= f'(a) - \frac{1}{h}(f(a) - (f(a) + f'(a)(a - (a - h)) + \frac{1}{2}f''(a)(a-(a-h))^2 + \cdots))$
$= |f'(a) - \frac{1}{h}(f'(a) + \frac{1}{2}f''(a)h)|$

21
notes/Sep-20.org Normal file
View File

@ -0,0 +1,21 @@
* Review & Summary
Approx f'(a) with
+ forward difference $f'(a) \approx \frac{f(a+h) - f(a)}{h}$
+ backward difference $f'(a) \approx \frac{f(a) - f(a-h)}{h}$
+ central difference $f'(a) \approx \frac{f(a+h) - f(a-h)}{2h}$
** Taylor Series
given $C = \frac{1}{2}(|f''(\xi)|) \cdot h^1$
with f.d. $e_{\text{abs}} \leq Ch^1$
b.d. $e_{\text{abs}} \leq Ch^1$
c.d. $e_{\text{abs}} \leq Ch^2$
$e_{\text{abs}} \leq Ch^r$
$log(e(h)) \leq log(ch^r) = log(C) + log(h^r) = log(C) + rlog(h)$

45
notes/Sep-22.org Normal file
View File

@ -0,0 +1,45 @@
* regression
consider the generic problem of fitting a dataset to a linear polynomial
given discrete f: x \rightarrow y
interpolation: y = a + bx
[[1 x_0] [[y_0]
[1 x_1] \cdot [[a] = [y_1]
[1 x_n]] [b]] [y_n]]
consider p \in col(A)
then y = p + q for some q \cdot p = 0
then we can generate n \in col(A) by $Az$ and n must be orthogonal to q as well
(Az)^T \cdot q = 0 = (Az)^T (y - p)
0 = (z^T A^T)(y - Ax)
= z^T (A^T y - A^T A x)
= A^T Ax
= A^T y
A^T A = [[n+1 \Sigma_{n=0}^n x_n]
[\Sigma_{n=0}^n x_n \Sigma_{n=0}^n x_n^2]]
A^T y = [[\Sigma_{n=0}^n y_n]
[\Sigma_{n=0}^n x_n y_n]]
a_11 = n+1
a_12 = \Sigma_{n=0}^n x_n
a_21 = a_12
a_22 = \Sigma_{n=0}^n x_n^2
b_1 = \Sigma_{n=0}^n y_n
b_2 = \Sigma_{n=0}^n x_n y_n
then apply this with:
log(e(h)) \leq log(C) + rlog(h)
* homework 3:
two columns \Rightarrow coefficients for linear regression

48
notes/Sep-25.org Normal file
View File

@ -0,0 +1,48 @@
ex: erfc(x) = \int_{0}^x (\frac{2}{\sqrt{pi}})e^{-t^2 }dt
ex: IVP \frac{dP}{dt} = \alpha P - \beta P^2
P(0) = P_0
Explicit Euler Method
$\frac{P(t + \Delta t) - P(t)}{\Delta t} \approx \alpha P(t) - \beta P^2(t)$
From 0 \rightarrow T
P(T) \approx n steps
* Steps
** Calculus: defference quotient
$f'(a) \approx \frac{f(a+h) - f(a)}{h}$
** Test.
Roundoff for h \approx 0
** Calculus: Taylor Serioes w/ Remainder
$e_{abs}(h) \leq Ch^r$
(see Sep-20 . Taylor Series)
* Pseudo Code
#+BEGIN_SRC python
for i in range(n):
a12 = a12 + x[i+1]
a22 = a22 + x[i+1]**2
a21 = a12
b1 = y[0]
b2 = y[0] * x[0]
for i in range(n):
b1 = b1 + y[i+1]
b2 = b2 + y[i+1]*x[i+1]
detA = a22*a11 - a12*a21
c = (a22*b1 - a12*b2) / detA
d = (-a21 * b1 + a11 * b2) / detA
return (c, d)
#+END_SRC
* Error
We want
$e_k = |df(h_kk) - f'(a)|$
$= |df(h_k) - df(h_m) + df(h_m) - f'(a)|$
$\leq |df(h_k) - df(h_m)| + |df(h_m) - f'(a)|$ and $|df(h_m) - f'(a)|$ is negligible