#+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 "../lizfcm.asd") (ql:quickload :lizfcm) (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))) #+END_SRC #+RESULTS: | 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 | 0.03125 | 0.03125 | | 1.0 | 0.015625 | 0.015625 | | 1.0 | 0.0078125 | 0.0078125 | | 1.0 | 0.00390625 | 0.00390625 | | 1.0 | 0.001953125 | 0.001953125 | | 1.0 | 0.0009765625 | 0.0009765625 | | 1.0 | 0.00048828125 | 0.00048828125 | | 1.0 | 0.00024414063 | 0.00024414063 | | 1.0 | 0.00012207031 | 0.00012207031 | | 1.0 | 6.1035156e-05 | 6.1035156e-05 | | 1.0 | 3.0517578e-05 | 3.0517578e-05 | | 1.0 | 1.5258789e-05 | 1.5258789e-05 | | 1.0 | 7.6293945e-06 | 7.6293945e-06 | | 1.0 | 3.8146973e-06 | 3.8146973e-06 | | 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 | (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 (lambda (x) x) 1.0d0 1.0d0))) (lizfcm.utils:table (:headers '("a" "h" "err") :domain-order (a h err) :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 | | 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 |