fix bug in which err = 0

This commit is contained in:
Elizabeth Hunt 2023-09-27 10:10:33 -06:00
parent 4584437d43
commit b35e399833
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
4 changed files with 31 additions and 87 deletions

View File

@ -45,7 +45,6 @@ Computing $\epsilon_{\text{mac}}$ for single precision numbers
| 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 |
(with many rows truncated)
@ -54,14 +53,14 @@ Computing $\epsilon_{\text{mac}}$ for single precision numbers
| 1.0 | 0.25 | 0.25 |
| 1.0 | 0.125 | 0.125 |
| 1.0 | 0.0625 | 0.0625 |
| 1.0 | 0.03125 | 0.03125 |
| 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}
$\epsilon_{\text{mac single precision}}$ \approx 1.192(10^-7)
* Question Two
Computing $\epsilon_{\text{mac}}$ for double precision numbers:
@ -75,62 +74,6 @@ Computing $\epsilon_{\text{mac}}$ for double precision numbers:
:domain-values domain-values)))
#+END_SRC
#+RESULTS:
| 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 | 9.765625d-4 | 9.765625d-4 |
| 1.0d0 | 4.8828125d-4 | 4.8828125d-4 |
| 1.0d0 | 2.44140625d-4 | 2.44140625d-4 |
| 1.0d0 | 1.220703125d-4 | 1.220703125d-4 |
| 1.0d0 | 6.103515625d-5 | 6.103515625d-5 |
| 1.0d0 | 3.0517578125d-5 | 3.0517578125d-5 |
| 1.0d0 | 1.52587890625d-5 | 1.52587890625d-5 |
| 1.0d0 | 7.62939453125d-6 | 7.62939453125d-6 |
| 1.0d0 | 3.814697265625d-6 | 3.814697265625d-6 |
| 1.0d0 | 1.9073486328125d-6 | 1.9073486328125d-6 |
| 1.0d0 | 9.5367431640625d-7 | 9.5367431640625d-7 |
| 1.0d0 | 4.76837158203125d-7 | 4.76837158203125d-7 |
| 1.0d0 | 2.384185791015625d-7 | 2.384185791015625d-7 |
| 1.0d0 | 1.1920928955078125d-7 | 1.1920928955078125d-7 |
| 1.0d0 | 5.960464477539063d-8 | 5.960464477539063d-8 |
| 1.0d0 | 2.9802322387695313d-8 | 2.9802322387695313d-8 |
| 1.0d0 | 1.4901161193847656d-8 | 1.4901161193847656d-8 |
| 1.0d0 | 7.450580596923828d-9 | 7.450580596923828d-9 |
| 1.0d0 | 3.725290298461914d-9 | 3.725290298461914d-9 |
| 1.0d0 | 1.862645149230957d-9 | 1.862645149230957d-9 |
| 1.0d0 | 9.313225746154785d-10 | 9.313225746154785d-10 |
| 1.0d0 | 4.656612873077393d-10 | 4.656612873077393d-10 |
| 1.0d0 | 2.3283064365386963d-10 | 2.3283064365386963d-10 |
| 1.0d0 | 1.1641532182693481d-10 | 1.1641532182693481d-10 |
| 1.0d0 | 5.820766091346741d-11 | 5.820766091346741d-11 |
| 1.0d0 | 2.9103830456733704d-11 | 2.9103830456733704d-11 |
| 1.0d0 | 1.4551915228366852d-11 | 1.4551915228366852d-11 |
| 1.0d0 | 7.275957614183426d-12 | 7.275957614183426d-12 |
| 1.0d0 | 3.637978807091713d-12 | 3.637978807091713d-12 |
| 1.0d0 | 1.8189894035458565d-12 | 1.8189894035458565d-12 |
| 1.0d0 | 9.094947017729282d-13 | 9.094947017729282d-13 |
| 1.0d0 | 4.547473508864641d-13 | 4.547473508864641d-13 |
| 1.0d0 | 2.2737367544323206d-13 | 2.2737367544323206d-13 |
| 1.0d0 | 1.1368683772161603d-13 | 1.1368683772161603d-13 |
| 1.0d0 | 5.684341886080802d-14 | 5.684341886080802d-14 |
| 1.0d0 | 2.842170943040401d-14 | 2.842170943040401d-14 |
| 1.0d0 | 1.4210854715202004d-14 | 1.4210854715202004d-14 |
| 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 |
(with many rows truncated)
| a | h | err |
| 1.0d0 | 0.5d0 | 0.5d0 |
@ -148,9 +91,8 @@ Computing $\epsilon_{\text{mac}}$ for double precision numbers:
| 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}
Thus, $\epsilon_{\text{mac double precision}}$ \approx 2.220 \cdot 10^{-16}
* Question Three - |v|_2
#+BEGIN_SRC lisp :session t
@ -204,7 +146,7 @@ Thus, $\epsilon_{\text{mac}}$ \approx 1.1102 \cdot 10^{-16}
* Question Six - ||v - u|| via |v|_{2}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(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")
@ -225,7 +167,7 @@ Thus, $\epsilon_{\text{mac}}$ \approx 1.1102 \cdot 10^{-16}
* Question Seven - ||v - u|| via |v|_{1}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(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")
@ -246,7 +188,7 @@ Thus, $\epsilon_{\text{mac}}$ \approx 1.1102 \cdot 10^{-16}
* Question Eight - ||v - u|| via |v|_{\infty}
#+BEGIN_SRC lisp :session t
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(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)

Binary file not shown.

View File

@ -1,4 +1,4 @@
% Created 2023-09-25 Mon 09:52
% Created 2023-09-27 Wed 10:09
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
@ -29,15 +29,16 @@
\setlength\parindent{0pt}
\section{Question One}
\label{sec:orga203815}
\label{sec:orga21c813}
Computing \(\epsilon_{\text{mac}}\) for single precision numbers
\begin{verbatim}
(load "../cl/lizfcm.asd")
(load "../lizfcm.asd")
(ql:quickload :lizfcm)
(let ((domain-values (lizfcm.approx:compute-maceps 1.0
(lambda (x) x))))
(let ((domain-values (lizfcm.approx:compute-maceps (lambda (x) x)
1.0
1.0)))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
@ -52,24 +53,25 @@ a & h & err\\[0pt]
1.0 & 0.25 & 0.25\\[0pt]
1.0 & 0.125 & 0.125\\[0pt]
1.0 & 0.0625 & 0.0625\\[0pt]
1.0 & 0.03125 & 0.03125\\[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}
\(\epsilon_{\text{mac single precision}}\) \(\approx\) 1.192(10\textsuperscript{-7})
\section{Question Two}
\label{sec:orgdd79be1}
\label{sec:org06c4a23}
Computing \(\epsilon_{\text{mac}}\) for double precision numbers:
\begin{verbatim}
(let ((domain-values (lizfcm.approx:compute-maceps 1.0d0
(lambda (x) x))))
(let ((domain-values (lizfcm.approx:compute-maceps (lambda (x) x)
1.0d0
1.0d0)))
(lizfcm.utils:table (:headers '("a" "h" "err")
:domain-order (a h err)
:domain-values domain-values)))
@ -94,14 +96,13 @@ a & h & err\\[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}
Thus, \(\epsilon_{\text{mac double precision}}\) \(\approx\) 2.220 \(\cdot\) 10\textsuperscript{-16}
\section{Question Three - |v|\textsubscript{2}}
\label{sec:org04608d9}
\label{sec:orgf181ba7}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(2-norm (lizfcm.vector:p-norm 2)))
@ -123,7 +124,7 @@ x & y & 2norm\\[0pt]
\end{center}
\section{Question Four - |v|\textsubscript{1}}
\label{sec:orgfb57f3a}
\label{sec:org2196087}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2)))
(1-norm (lizfcm.vector:p-norm 1)))
@ -145,7 +146,7 @@ x & y & 1norm\\[0pt]
\end{center}
\section{Question Five - |v|\textsubscript{\(\infty\)}}
\label{sec:org7bbdf04}
\label{sec:org11b8894}
\begin{verbatim}
(let ((vs '((1 1) (2 3) (4 5) (-1 2))))
(lizfcm.utils:table (:headers '("x" "y" "max-norm")
@ -166,7 +167,7 @@ x & y & infty-norm\\[0pt]
\end{center}
\section{Question Six - ||v - u|| via |v|\textsubscript{2}}
\label{sec:orge36996c}
\label{sec:orga2324b2}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
@ -192,7 +193,7 @@ v1 & v2 & 2-norm\\[0pt]
\end{center}
\section{Question Seven - ||v - u|| via |v|\textsubscript{1}}
\label{sec:orgd1577f0}
\label{sec:org388fbc7}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4)))
@ -218,7 +219,7 @@ v1 & v2 & 1-norm-d\\[0pt]
\end{center}
\section{Question Eight - ||v - u|| via |v|\textsubscript{\(\infty\)}}
\label{sec:org2661676}
\label{sec:org6e77f76}
\begin{verbatim}
(let* ((vs '((1 1) (2 3) (4 5) (-1 2)))
(vs2 '((7 9) (2 2) (8 -1) (4 4))))

View File

@ -8,4 +8,5 @@
(setf h (/ h 2)
err (abs (- (funcall f (+ a h))
(funcall f a))))
when (> err 0)
collect (list a h err))))