應用數值線性代數習題參考答案【Ch1Q12-21】

2021-02-20 樂植桃數
Demmel J. W. Applied Numerical Linear Algebra課後習題參考答案Chapter 1 Question 12 - 21Foreword

第一章的12-21題難度相比於前面有了明顯的增加. 許多題目是在寫作業時抓耳撓腮一整天沒有很明確頭緒的. 部分題目的完整解答仍然欠缺(即使我們已經有了一個不那麼完整而嚴格的證明, 但考慮到寫得不嚴謹會被噴), 以期待有興趣的讀者參與補全完整的證明. 後面的一些題目偏向於在計算機上實踐以真正理解浮點數運算和當今的IEEE 754標準並非顯然. 但更深入的理解要求我們對計算機組成原理和計算機的計算原理有較為透徹的認識, 對於一般非相關學科的同學來說是較為困難的. 實踐的部分題目對編者的編程能力有較大的挑戰, C語言norm2函數我們的實現在向同級計院曹書瑜同學請教後運行速度有了明顯的提升, 此處表示感謝.

附上視頻1996年歐洲阿麗亞娜5型運載火箭首飛發射失敗, 來一起看看沒有仔細處理浮點數運算的後果.https://www.bilibili.com/video/av2319355/

Question 1.12

Question. In order to analyze the effects of rounding errors, wehave used the following model

where

Proof.

For a complex calculation, we only need to calculate its Re and Imaccurately. Let . In order toprove that there exist a

1)For addition, our algorithm is

Now let's analyse its error.

For the relative accuracy, let

Re and Im have high relative accuracy.

2)For substraction, our algorithm is

Now let's analyse its error

For the relative accuracy, let

Re and Im have high relative accuracy.

3)For multiplication, our algorithm is

Now let's analyse its error

For relative accuracy

When

4)For division

Now let's analyse its error, we only analyse thecase

For relative accarucy,

Cause we won't multiple two big number, the problemof overflow won't happend.

This is properly tested on python code as the following.

>>> def complex_divide(a1, a2, b1, b2):
...     if abs(b1) < abs(b2):
...         return [(b1/b2*a1+a2)/(b1/b2*b1+b2), (b1/b2*a2-a1)/(b1/b2*b1+b2)]
...     else:
...         return [(a1+b2/b1*a2)/(b1+b2/b1*b2), (a2-b2/b1*a1)/(b1+b2/b1*b2)]
...
    
>>> complex_divide(2**666, 2**666, 2**666, 2**666)
[1.0, 0.0]
>>> complex_divide(2**-666, 2**-666, 2**-666, 2**-666)
[1.0, 0.0]
>>> complex_divide(2**-666, 2**666, 2**-666, 2**666)
[1.0, -0.0]
>>> complex_divide(2**666, 2**-666, 2**666, 2**-666)
[1.0, 0.0]

Question 1.13

Question. Prove Lemma 1.3. Let

Proof.

We only prove the case in

The matrix form of inner product. Let

We shall show that A is s.p.d.,

which means

If A is s.p.d, we shall show that

1)

2).

3)

4)for A is h.p.d,

Question 1.14

Question. Prove lemma 1.5:

Proof.

Question 1.15

Question. Prove Lemma 1.6:

An operator norm is a matrix norm.

Proof.

1)

If

2)

3)

Question 1.16

Question. Prove all parts except 7 of Lemma 1.7. Hint for part 8:Use the fact that if

Part 1. Prove that

Proof. For operator norm, this can be soon obtained by

if for any nonzero vector

For matrix Frobenius norm, if we rewrite

The last step is to sum the square of all the inequalities above,i.e.

Part 2. Prove that

Proof. For operator norm,

For Frobenius norm, this can be soon obtained byrewrite

Part 3. Prove that the max norm and Frobenius norm are not operatornorm.

Proof. For max norm, we may show that it violates part 2 ofLemma 1.7 by the counter example,

It canbe easily shown that

Frobenius norm is not operator norm, as

Part 4.

Proof. Only to Prove when orthogonal, since unitary is the same.For operator norm induced by

For Frobenius norm, it is the Pythagorean theorem. if

Part 5. Prove that,the maximum absolute row sum.

Proof. this can be obtained by take

Part 6. Prove that,the maximum absolute column sum.

Proof. This is trivial from the view of functional analysis, as

Part 8. Prove that

Proof. This is the same as the proof of part 6.

Part 9. Prove that

Proof. Remember that

This is true for

Part 10. If

Proof. There exists

wherethe last inequality is a corollary from the inequality of means.There exists

Part 11. If

Proof. This can be soon obtained from parts 6, 8, and 10.

Part 12. If

Proof. This can be soon obtained from parts 10 and 11.

Part 13. If

Proof. For the first part, find one, then define

The second part is true, since

Question 1.17

Question. We mentioned that on a Cray machine the expression

Proof.

Now consider the case that we want to calculate

For any

As

Define Andobviously,

We want to prove that

...(Wait for completion. If you can do it, please contact us)

When

Question 1.18

Question. Suppose that

if

Prove the following facts:

Barring overflow or underflow, the only round-off error committed inrunning the algorithm is computing

Thus, this program in effect simulates quadruple precision arithmetic,representing the true sum

Using this and similar tricks in a systematic way, it is possible toefficiently simulate all four basic floating-point operations inarbitrary precision arithmetic, using only the underlying floating pointinstructions and no "bit-fiddling". 128-bit arithmetic is implementedthis way on the IBM RS6000 and Cray (but much less efficiently on theCray, which does not have IEEE arithmetic).

Proof. We shall prove the following lemma: If floating point numbers

Proof of lemma. Remember we are in the binary system, and

Assume

When

When

When

For the case

Question 1.19

Question. This question illustrates the challenges in engineeringhighly reliable numerical software. Your job is to write a program tocompute the two-norm


for

end for

This algorithm is inadequate because it does not have the followingdesirable properties:

It must compute the answer accurately (i.e., nearly all the computeddigits must be correct) unless

It must be nearly as fast as the obvious program above in mostcases.

It must work on any "reasonable" machine, possibly including ones not running IEEE arithmetic. This means it may not cause an errorcondition unless

To illustrate the difficulties, note that the obvious algorithm failswhen

This routine is important enough that it has been standardized as aBasic Linear Algebra Subroutine, or BLAS, which should be availableon all machines.

Answer.

To avoid overflow, one can separate out the exponent part of a floating-point number, and compute the scaled squares. One result can be like

import numpy as np
def frexp(x):
    """fake one to separate double precision floating point number's
    exponent and tail"""
    b = '{:0>64s}'.format(bin(np.float64(x).view(np.uint64))[2:])
    exp = int(b[1:12], base=2) - 1023
    if exp > -1023:
        return exp, int(b[12:], base=2) * (2**-52) + 1
    else:
        extra = b[1:].find('1')
        return exp - extra + 11, int(b[extra:], base=2) * (2**(extra-62))

def norm2(x):
    if len(x) == 0:
        return 0
    if len(x) == 1:
        return abs(x[0])

    s = 0
    size = -1076
    for i in range(len(x)):
        x_exp, x_frac = frexp(x[i])  # 獲取指數部分和尾數部分
        if size < x_exp:
            s *= 2 ** (size - x_exp)
            size = x_exp
        else:
            x_frac *= 2 ** (x_exp - size)
        s += x_frac ** 2

    return s**0.5 * 2**size
        

This code is tested for

>>> norm2([2**-1024]) == 2**-1024
True
>>> norm2([2**-1054, 2**-1055]) == 2**-1055 * 5**0.5
True
>>> norm2([0.+2**1020]) == 2**1020
True
>>> norm2([0.+2**1020, 0.+2**1020]) == 2**1020 * 2**0.5
True
>>> norm2([2**-1054, 2**1020]) == 2**1020
True
>>> norm2([2**1020, 2**-1054]) == 2**1020
True

Though for the convenience of coding, we cannot apply the built-infunction <frexp> in C code and implement it in a slow way, theperformance can be still evaluated. Assume the 'frexp' operation can beperformed in a proper way (in machine level, separate the exponent partand the tail part), and calculated as three operations, totally thisalgorithm cost

Further, the code is implemented in C code. (Please go see attachment ingitee)

https://gitee.com/j7168908jx/shuzhidaishu/blob/master/code/c1-19/code.c

Test results are given in table 11. norm2simple is the baseline algorithm given inthe question, norm2lapack is the one from LAPACK in Fortran code.norm2 and norm22 are the algorithms designed in the answer, wherenorm22 uses more efficient but probably harder to read operations, andmight not work with denormalized floating-point numbers. The vector

During the completion of the C code, conclusions are obtained. One ofthe most important for the problem is that sometimes it is not soexpensive to do the division, rather than using other techniques thatmight add more complexity to the code and the running time. Limited CPUstructure(register cache, variable storage) is to blame.

Table 1. Test result for question 1.19Iterations, length(
11.25s13.45s20.49s22.38sQuestion 1.20

Question. We will use a Matlab program to illustrate how sensitivethe roots of a polynomial can be to small perturbations in thecoefficients. Polyplot takes an input polynomial specified by its rootsr and then adds random perturbations to the polynomial coefficients,computes the perturbed roots, and plots them. The inputs are



The first part of your assignment is to run this program for the following inputs. In all cases choose m high enough that you get afairly dense plot but don't have to wait too long. m = a few hundred or perhaps 1000 is enough. You may want to change the axes of the plot if the graph is too small or too large.

Also try your own example with complex conjugate roots. Which rootsare most sensitive?

r=(1:10);e=1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,

r=(1:20);e=1e-9,1e-11,1e-13,1e-15,

r=[2,4,8,16,...,1024];e=1e-1,1e-2,1e-3,1e-4.

The second part of your assignment is to modify the program tocompute the condition number c(i) for each root. In other words, arelative perturbation of e in each coefficient should change rootr(i) by at most about e*c(i). Modify the program to plot circlescentered at r(i) with radii e*c(i), and confirm that these circlesenclose the perturbed roots (at least when e is small enough thatthe linearization used to derive the condition number is accurate).You should turn in a few plots with circles and perturbed roots, andsome explanation of what you observe.

In the last part, notice that your formula for c(i) "blows up" if

Answer.

1.Here we let m =1000.

1)The case r=1:10, let e=1e-3,1e-4,1e-5,1e-6,1e-7,1e-8. See figures below.

Figure. When r=1:10

2)The case r=1:20,let e=1e-9,1e-11,1e-13,1e-15, See figures below.

Figure. When r=2:10

3)The case r=[2,4,8,...,1024],let e=1e-1,1e-2,1e-3,1e-4, See figures below.

Figure. When r=[2,4,8,...,1024]

2.Let's start from the theoretical analysis. Let,

where

So

For our numerical experiment, we assume that

r=1:10,e=1e-7

We can see that the circle in the middle is muchlarger than the circle on the edeg, but the circle of the roots 5 or 6is not the largest . It is easy to see that

derivative

3.The same trick as 2, notice that k-th derivative of p(x) will be 0 if

See the code appendix c1-20

https://gitee.com/j7168908jx/shuzhidaishu/tree/master/code/c1-20

Question 1.21

Question. Apply Algorithm 1.1, Bisection, to find the roots of

Answer.

The bisection is implemented as

import numpy as np
from matplotlib import pyplot as plt

def bisect(coeff, a, b, tol):
    low = a
    high = b
    poly = np.poly1d(coeff, r=True)
    p_low = poly(low)
    p_high = poly(high)

    if abs(p_low) < tol:
        return low, low
    elif abs(p_high) < tol:
        return high, high

    while high - low > 2 * tol:
        mid = (low + high) / 2
        p_mid = poly(mid)
        if p_mid * p_low < 0:
            high = mid
            p_high = p_mid
        elif p_mid * p_high < 0:
            low = mid
            p_low = p_mid
        else:
            low = high = mid
            p_low = p_high = p_mid
    return low, high

result = [bisect([2] * 9, 1, h, 1e-5) for h in np.linspace(3, 3.5, 100)]
plt.plot(np.linspace(3, 3.5, 100), result)
plt.xlabel("search interval: [1, x]")
plt.ylabel('result')
plt.title("different bisection result when initial value varies")
plt.show()    

and the great difference in result can be inherited from figure listed below.

result for question 1.21

Modified bisection search code is listed below.

def bisect(roots, a, b, tol):
    low = a
    high = b
    poly = np.poly1d(roots, r=True)
    coeff = poly.coef
    poly2 = np.poly1d(np.abs(coeff))
    p_low = poly(low)
    p_high = poly(high)
        
    if abs(p_low) < tol:
        return low, low
    elif abs(p_high) < tol:
        return high, high
        
    def stop(mi, pmi):
        err = 2 * len(roots) * poly2(np.abs(mi)) * 2**-52
        if pmi > 0:
            return pmi - err <= 0
        else:
            return pmi - err > 0
        
    while True:
        mid = (low + high) / 2
        p_mid = poly(mid)
        if p_mid * p_low < 0:
            high = mid
            p_high = p_mid
        elif p_mid * p_high < 0:
            low = mid
            p_low = p_mid
        else:
            low = high = mid
            p_low = p_high = p_mid
        if high - low < 2 * tol:
            break
        if stop(mid, p_mid):
            low = high = mid
            p_low = p_high = p_mid
            break
        
    return low, high

Respectively, the outcome of code, when given different initial value,is shown in the figure below.

result for question 1.21

有什麼問題歡迎在下方留言哦~ <

相關焦點

  • 工程數學-線性代數(第六版)課後答案及習題解析.主編:同濟大學數學系.
    書名:工程數學-線性代數版本:第六版
  • 人工智慧中的線性代數:如何理解並更好地應用它
    如果不掌握應用數學這個領域,你永遠就只能是「門外漢」。當然,學習線性代數道阻且長。數學,尤其是線性代數常與枯燥、複雜和毫無意義的事物聯繫起來。不過你還可以另闢蹊徑。閱讀完本文後,你將了解到:線性代數的本質;線性代數的真實應用場景;線性代數可用於 AI、ML 和數據科學的原因;學習線性代數最有效的方法。
  • 《量子力學概論》課本習題答案(格裡菲斯、英文版)
    課後答案解析 Weixin ID gh_484d90502929
  • 注重基礎培養能力 2011考研線性代數複習建議
    考研數學科目尤其是數學中的線性代數部分,複習起來有一定的難度,為了幫助考生有效地進行考研複習,萬學海文數學考研輔導專家結合以往的教學經驗,有針對性地為考生提出現性代數的複習建議。掌握他們之間的聯繫與區別,對大家做線性代數的兩個大題在解題思路和方法上會有很大的幫助。二、參照大綱,做題鞏固考研大綱在7月份左右出來。由於數學的考試大綱變化不是很大,所以可以參考去年的考試大綱進行複習。
  • 清華把線性代數教材換成英文版引熱議:網友:早該換了
    乾明 發自 凹非寺量子位 報導 | 公眾號 QbitAI因為課本換成了英文教材,清華大學的線性代數課火了。知乎上還專門熱火朝天展開討論。截至到現在,瀏覽已經近85萬次,有300+回答。他博士畢業於UCLA,之後一直在MIT任教,主要課程有「數據分析的矩陣方法」、「線性代數」、「計算機科學與工程」等,也出版過很多課程教材。這本線性代數(Introduction to Linear Algebra)就是其中之一,現在已經是第5版了。其主要內容包括行列式、矩陣、線性方程組與向量、矩陣的特徵值與特徵向量、二次型及Mathematica 軟體的應用等。
  • 線性代數入門——矩陣乘積和乘冪在實際問題中的應用舉例
    系列簡介:這個系列文章講解線性代數的基礎內容,注重學習方法的培養。
  • 強化學習中的線性代數知識
    線性代數的基本原理如何用於深度強化學習?答案是解決了馬爾可夫決策過程時的迭代更新。強化學習(RL)是一系列用於迭代性學習任務的智能方法。由於計算機科學是一個計算領域,這種學習發生在狀態向量、動作等以及轉移矩陣上。狀態和向量可以採用不同的形式。當我們考慮通過某個線性系統傳遞一個向量變量,並得到一個類似的輸出時,應該想到特徵值。
  • 《世紀雲圖·2017張宇線性代數9講》圖書
    噹噹購買連結點擊進入【教材名稱】世紀雲圖2017張宇線性代數9講(2017張宇考研系列叢書+全新正版圖書+張宇考研數學學習包用書)【作者】張宇主編【
  • 二年級下冊語文第三單元習題之閱讀理解和看圖寫作題以及參考答案
    01二年級下冊語文第三單元測試習題第二卷2本次課程繼續上次課程的內容,將閱讀理解習題和作文題目進行展示,然後給出整個試卷的答案,希望學生認真完成後再進行答案的匹對,歡迎大家加入尖子生數理化教育獲取更多的考點,如果對題目有問題,歡迎在下方為我們留言。
  • 線性代數的非主流經典名作:《線性代數應該這樣學》
    本書是公認的闡述線性代數的經典佳作。從線性代數基礎講起,無需更多數學預備知識。拋棄晦澀難懂的行列式,從向量空間和線性映射出發描述線性算子。包含561道習題和大量示例,提高學生理解和熟練運用線性代數知識的能力並闡明線性代數的主要思想。對術語、結論、證明思路、提及的數學家做了注釋,增加行文趣味性。
  • 86歲還在錄網課:MIT教授Gilbert Strang最新「線性代數」課程上線
    從各大平臺的討論中,我們可以總結出以下關鍵詞:1、實用、難度適中。知乎上有個帖子專門討論 Gilbert Strang 的線性代數教材《Introduction to Linear Algebra》。有人表示,「Strang 的教材更加面向實際應用,難度適中,比較注重從實際問題中培養數學直覺,比較適合工程學科學生使用。」
  • 2016考研數學:線性代數解題技巧
    >>2016考研考前終極預測題及答案解析匯總(各科目)   線性代數考研數學中佔有重要的地位,多以計算題為主,證明題為輔。以下是總結的線性代數解題技巧,以供大家參考。
  • 數列與極限100道經典例題答案
    關於《數列與極限》部分諮詢的小夥伴們比較多,因為工作原因,斷更也是迫不得已,今天特意抽時間,把《數列與極限》的100道例題答案整理出來,
  • 同濟大學《高等數學》第七版教材課後習題參考解答
    更多通用教材課後習題分享在逐步完善中...微分中值定理與導數的應用  第四章 不定積分  第五章 定積分  第六章 定積分的應用  第七章 微分方程  高等數學(下冊)習題解答第八章 向量代數與空間解析幾何  第九章 多元函數微分法及其應用  第十章 重積分  第十一章 曲線積分與曲面積分  第十二章
  • 《信號與系統》第八次作業參考答案
    每一章在提綱挈領地介紹基礎知識點後,輔之以大量的考研真題和著名教材習題的解答,向學習者演示基礎知識的靈活運用和答題技巧。最後一章包含了大量的各類高校考研(博)真題,以給讀者提供豐富的自我測試材料,所有真題都包含參考解答,解答有詳有略,以便學習者對照答案參考之用。
  • 資料下載 | 線性代數應該這樣學(中文第三版)
    《線性代數應該這樣學》 中文版第三版內容簡介:描述線性算子的結構是線性代數的中心任務之一,傳統的方法多以行列式為工具
  • 2020年六年級道德與法治期中測試習題參考答案詳解
    道德與法治期中測試習題參考答案詳解繼續上次課程的內容,這次課程我們先來展示一下自主探究題,然後給出所有題目的答案詳解,滿分100分,你拿到了多少分?問:1.請列舉你身邊類似的示例,這些事例體現了怎樣的抗災精神?(8分)2.自然災害發生時,我們應該怎麼辦?
  • 剛體力學的知識點和參考習題
    學習時與質點力學的知識體系比較是一個不錯的選擇(大家可參考之前的推文)。此外,定軸轉動的是一種簡單的運動形式,其轉動的方向只有兩個可能,因此,涉及的物理量往往只用正負就可以區別,一般剛體問題都是從剛體上的任意點出發,然後求和推廣到整個剛體。剛體運動學是對剛體定軸轉動的描述,剛體上各點都在做圓周運動,因此,第一章關於圓周運動的角量描述可用於剛體上各點的運動情況。
  • 線性代數重要,選對教材更重要:同濟版《線性代數》引發激烈爭議
    如今已經畢業多年,沒想到最近在知乎上看到一篇文章《《線性代數》(同濟版)——教科書中的恥辱柱》,點讚量快突破五千。對於這篇文章,大家有時間可以讀一下,看看是不是同意作者的觀點。線性代數真的很重要,這是很多工程技術人員走上工作崗位的最大感受。好多算法都用到線性代數的知識,就比如現在非常熱門的深度學習,它的底層實現方式用到好多線性代數方面的知識。
  • 如何看待清華大學將線性代數教材改為英文教材?
    英文版線性代數教材的作者是麻省理工學院教授Gilbert Strang,其主要內容包括行列式、矩陣、線性方程組和向量等,並且每章都配有習題。我們的數學教材是指令式的,告訴你是什麼,然後你自己去做習題鞏固知識。而英文教材往往是探索式的,會告訴你這些定義的緣由。我國若想做出原創性的優秀科研成果,那必須改變高等教育中的指令式教學習慣(至於初等教育是否需要採用探索式教學,這個問題有待研究,個人認為是不需要的)。清華現在的那本線性代數寫的真的很好,比如,解釋了矩陣乘法為什麼要定義成那種看起來比較「噁心」的樣子。