作业内容:
代码:(简化问题n=10,m=20)
import numpy as np
from scipy.linalg import toeplitz,svd
n,m=10,20
array = np.linspace(1, m,m)
A=np.random.normal(size=(n,m))
B=toeplitz(array,array)
print(B)
def fun1(x):
I=np.eye(m)
return np.dot(A,B-x*I)
if __name__=="__main__":
print("matrix A")
print(A)
print("matrix B")
print(B)
print("#exercise 9.1")
print("A+A")
print(A+A)
print("AA'")
print(np.dot(A,A.T))
print("A'A")
print(np.dot(A.T,A))
print("AB")
print(np.dot(A,B))
print("A(B-xI)")
x=float(input("please input x: "))
print(fun1(x))
print("#exercise 9.2")
b=np.random.normal(size=(m,1))
print("vector b:")
print(b)
x=np.linalg.solve(B,b)
print(x)
print("#exercise 9.3")
print("the Frobenius norm of A:")
print(np.linalg.norm(A,'fro'))
print("the infinity norm of B:")
print(np.linalg.norm(B,np.inf))
U, sigma, VT = np.linalg.svd(B)
print("the largest singular values of B")
print(sigma.max())
print("the smallest singular values of B")
print(sigma.min())
print("#exercise 9.4")
Z=np.random.normal(size=(n,n))
max_val=-np.inf
max_vec=None
count=1
for i in range(1,100):
T=np.power(Z,i)
eigval, eigvec = np.linalg.eig(T)
eigval_max=eigval.max()
index=eigval.argmax()
if eigval_max>max_val:
max_val=eigval_max
max_vec=eigvec[:,index]
count=i
print("the largest eigenvalue")
print(max_val)
print("the corresponding eigenvector")
print(max_vec)
print("iterations needed")
print(count)
print("#exercise 9.5")
probility=float(input("please input probility: "))
C = np.random.choice(2,size=(n,n),p=[1-probility,probility])
U,s,vh=svd(C)
max_val=s.max()
print(max_val)
print("#exercise 9.6")
z=float(input("please input z: "))
A1=np.abs(np.subtract(A,z))
min_index=np.argmin(A1)
print("the element in A that is closest to z")
print(A.reshape(n*m,1)[min_index])
运行结果:
matrix A
[[-0.83879741 -0.85304511 -0.56418422 -0.0496559 -1.36998588 -1.3332013
0.5564232 -1.30930225 -1.65792455 -0.8642228 1.39090228 -0.78343139
0.34415094 0.61766543 -0.06660307 -1.02418396 0.3601281 1.73085965
-1.49263248 -0.13923497]
[-1.05586037 -0.4958746 0.67608371 -1.75816027 0.89000394 0.00617552
-0.06581061 1.29830915 -0.68240219 0.31290186 -0.02487612 1.23968057
0.0968259 1.61416456 -1.79023238 -0.259946 -0.30635247 1.48029469
0.21888145 -0.89312315]
[ 0.53229698 -0.37492817 -0.92615849 0.41893526 0.44048827 -1.00670368
-0.42846315 2.27533837 0.21803224 0.46647612 2.21625363 1.55280377
-0.92346732 1.23784391 -1.28329713 0.23711638 0.94274339 -0.56677757
-0.77715125 -0.29940184]
[-0.85544192 2.31477933 -1.31201574 -1.82726275 0.17892515 1.36258725
-1.78370156 0.59270487 -0.39906891 -0.01647322 1.03718013 0.85344182
0.04732554 0.16222088 -0.47905225 0.36897321 -0.95496198 -1.08949467
-0.22778226 -0.81745905]
[-1.37748717 1.13164106 0.07190672 -1.90565728 -0.1532229 0.99355408
-3.20585071 -0.36460408 2.63391877 -1.74331358 1.29264097 -0.50963835
1.62763866 -0.27055652 1.96943963 -0.81227892 0.96437187 -1.5308579
-0.28475566 0.36422325]
[ 0.11320989 0.9929267 0.75745717 0.26025499 -1.22818356 0.25194111
0.21004889 -0.30007482 0.36556121 1.23009562 -1.02193175 -0.18258642
-1.37336872 -1.11649694 0.89230301 0.17974019 0.44348259 -0.53011786
-0.540528 1.3070806 ]
[ 1.75516811 0.25810973 1.0351582 0.37903135 1.77940803 1.63931502
2.16647758 0.24941799 0.71152634 -1.09979528 0.24492749 -0.19589205
0.86984129 -1.71180397 -1.05895603 1.3135398 1.21141574 0.21945216
-0.75729256 1.45592732]
[-0.981149 -0.5676369 0.93405695 -1.20423783 -0.41368581 -0.63007691
0.19892078 1.84595019 0.13798537 -0.13920084 0.42971135 -0.91400678
-0.61915155 -1.26540214 -1.28157329 0.84049556 0.42393157 -0.04221135
-0.76236196 -1.93217411]
[ 0.18852702 -0.53024648 0.15253338 -1.16197532 0.49953469 -1.16722703
0.45010816 2.65912931 0.74678156 -0.75428783 -0.18888037 0.06001568
-0.46935055 -0.66308667 1.77963501 0.21186296 -0.22836321 -0.63643303
-0.65992694 -0.16054044]
[-0.21103138 -0.42482452 1.04849198 -0.14493554 0.52789674 -0.77741211
0.15875382 -0.47402506 -0.93766965 0.87319288 1.88976022 -1.8991802
-0.93891109 0.95844741 1.76981145 0.76011445 0.60433063 0.13699152
-1.18884941 -0.30466725]]
matrix B
[[ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.
15. 16. 17. 18. 19. 20.]
[ 2. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13.
14. 15. 16. 17. 18. 19.]
[ 3. 2. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
13. 14. 15. 16. 17. 18.]
[ 4. 3. 2. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
12. 13. 14. 15. 16. 17.]
[ 5. 4. 3. 2. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
11. 12. 13. 14. 15. 16.]
[ 6. 5. 4. 3. 2. 1. 2. 3. 4. 5. 6. 7. 8. 9.
10. 11. 12. 13. 14. 15.]
[ 7. 6. 5. 4. 3. 2. 1. 2. 3. 4. 5. 6. 7. 8.
9. 10. 11. 12. 13. 14.]
[ 8. 7. 6. 5. 4. 3. 2. 1. 2. 3. 4. 5. 6. 7.
8. 9. 10. 11. 12. 13.]
[ 9. 8. 7. 6. 5. 4. 3. 2. 1. 2. 3. 4. 5. 6.
7. 8. 9. 10. 11. 12.]
[ 10. 9. 8. 7. 6. 5. 4. 3. 2. 1. 2. 3. 4. 5.
6. 7. 8. 9. 10. 11.]
[ 11. 10. 9. 8. 7. 6. 5. 4. 3. 2. 1. 2. 3. 4.
5. 6. 7. 8. 9. 10.]
[ 12. 11. 10. 9. 8. 7. 6. 5. 4. 3. 2. 1. 2. 3.
4. 5. 6. 7. 8. 9.]
[ 13. 12. 11. 10. 9. 8. 7. 6. 5. 4. 3. 2. 1. 2.
3. 4. 5. 6. 7. 8.]
[ 14. 13. 12. 11. 10. 9. 8. 7. 6. 5. 4. 3. 2. 1.
2. 3. 4. 5. 6. 7.]
[ 15. 14. 13. 12. 11. 10. 9. 8. 7. 6. 5. 4. 3. 2.
1. 2. 3. 4. 5. 6.]
[ 16. 15. 14. 13. 12. 11. 10. 9. 8. 7. 6. 5. 4. 3.
2. 1. 2. 3. 4. 5.]
[ 17. 16. 15. 14. 13. 12. 11. 10. 9. 8. 7. 6. 5. 4.
3. 2. 1. 2. 3. 4.]
[ 18. 17. 16. 15. 14. 13. 12. 11. 10. 9. 8. 7. 6. 5.
4. 3. 2. 1. 2. 3.]
[ 19. 18. 17. 16. 15. 14. 13. 12. 11. 10. 9. 8. 7. 6.
5. 4. 3. 2. 1. 2.]
[ 20. 19. 18. 17. 16. 15. 14. 13. 12. 11. 10. 9. 8. 7.
6. 5. 4. 3. 2. 1.]]
#exercise 9.1
A+A
[[-1.67759482 -1.70609023 -1.12836845 -0.09931179 -2.73997176 -2.6664026
1.11284639 -2.61860449 -3.3158491 -1.7284456 2.78180455 -1.56686278
0.68830188 1.23533087 -0.13320614 -2.04836792 0.7202562 3.46171929
-2.98526497 -0.27846994]
[-2.11172075 -0.9917492 1.35216742 -3.51632054 1.78000789 0.01235104
-0.13162121 2.5966183 -1.36480438 0.62580373 -0.04975224 2.47936114
0.1936518 3.22832912 -3.58046477 -0.519892 -0.61270494 2.96058938
0.43776291 -1.78624629]
[ 1.06459396 -0.74985635 -1.85231697 0.83787052 0.88097654 -2.01340735
-0.85692629 4.55067674 0.43606449 0.93295224 4.43250725 3.10560754
-1.84693464 2.47568781 -2.56659425 0.47423275 1.88548679 -1.13355513
-1.5543025 -0.59880368]
[-1.71088385 4.62955866 -2.62403148 -3.65452549 0.35785029 2.72517451
-3.56740313 1.18540973 -0.79813782 -0.03294644 2.07436025 1.70688364
0.09465107 0.32444175 -0.9581045 0.73794642 -1.90992396 -2.17898934
-0.45556452 -1.63491811]
[-2.75497433 2.26328213 0.14381344 -3.81131457 -0.3064458 1.98710815
-6.41170142 -0.72920817 5.26783755 -3.48662717 2.58528194 -1.01927669
3.25527733 -0.54111303 3.93887925 -1.62455784 1.92874374 -3.06171581
-0.56951132 0.7284465 ]
[ 0.22641977 1.98585341 1.51491433 0.52050998 -2.45636711 0.50388222
0.42009779 -0.60014964 0.73112241 2.46019124 -2.04386351 -0.36517284
-2.74673744 -2.23299389 1.78460602 0.35948038 0.88696518 -1.06023573
-1.08105601 2.6141612 ]
[ 3.51033623 0.51621946 2.07031639 0.7580627 3.55881605 3.27863004
4.33295517 0.49883598 1.42305267 -2.19959056 0.48985497 -0.3917841
1.73968259 -3.42360793 -2.11791206 2.6270796 2.42283147 0.43890433
-1.51458512 2.91185464]
[-1.962298 -1.13527379 1.86811391 -2.40847566 -0.82737162 -1.26015381
0.39784155 3.69190039 0.27597075 -0.27840168 0.8594227 -1.82801355
-1.23830309 -2.53080428 -2.56314659 1.68099111 0.84786314 -0.0844227
-1.52472391 -3.86434823]
[ 0.37705404 -1.06049296 0.30506677 -2.32395064 0.99906939 -2.33445406
0.90021632 5.31825863 1.49356313 -1.50857565 -0.37776074 0.12003137
-0.9387011 -1.32617334 3.55927001 0.42372592 -0.45672642 -1.27286606
-1.31985387 -0.32108088]
[-0.42206276 -0.84964904 2.09698397 -0.28987107 1.05579348 -1.55482423
0.31750764 -0.94805013 -1.87533931 1.74638575 3.77952043 -3.7983604
-1.87782218 1.91689483 3.53962291 1.5202289 1.20866126 0.27398303
-2.37769882 -0.6093345 ]]
AA'
[[ 20.4004162 1.57095392 -0.15275076 -4.81186243 -3.6742877
-4.01209782 -6.06368026 0.86226028 -4.0725411 7.5377609 ]
[ 1.57095392 18.510148 6.6102239 4.82305122 -5.65001141
-7.90342795 -3.88823825 6.13590119 0.17352519 -2.13222073]
[ -0.15275076 6.6102239 21.60526533 4.47388311 -3.38055813
-4.83575671 -1.39042943 4.83009424 4.49472527 1.79546486]
[ -4.81186243 4.82305122 4.47388311 21.74870284 13.20159124
-2.47723729 -5.95629751 2.00368287 -0.33481512 -3.40646148]
[ -3.6742877 -5.65001141 -3.38055813 13.20159124 40.89132812
-0.46152467 -3.94126794 -1.06010259 4.35574981 0.07205994]
[ -4.01209782 -7.90342795 -4.83575671 -2.47723729 -0.46152467
12.51027132 1.37928945 -1.46882325 0.61816076 1.16399257]
[ -6.06368026 -3.88823825 -1.39042943 -5.95629751 -3.94126794
1.37928945 27.52869176 0.65701733 0.79847374 -2.4658194 ]
[ 0.86226028 6.13590119 4.83009424 2.00368287 -1.06010259
-1.46882325 0.65701733 17.5106741 7.02711324 2.81171984]
[ -4.0725411 0.17352519 4.49472527 -0.33481512 4.35574981
0.61816076 0.79847374 7.02711324 16.53202137 2.39018299]
[ 7.5377609 -2.13222073 1.79546486 -3.40646148 0.07205994
1.16399257 -2.4658194 2.81171984 2.39018299 18.69841753]]
A'A
[[ 8.8671757 -1.38739011 1.0833688 7.9969427 3.87467193
1.50967726 8.99905872 0.12777352 0.43394861 1.07735038
-3.1703806 1.09109771 -1.07662889 -3.54623681 -1.57826015
3.44374856 1.6016345 -0.0581004 0.67842678 5.73115896]
[ -1.38739011 9.58933648 -2.49961629 -3.91159384 -0.21157353
7.77021441 -7.68939864 -1.91063411 4.19848663 -0.55822402
-0.03952267 1.93215075 1.81615228 -2.60980611 2.19011736
0.45371261 -1.2512186 -6.41885814 1.16216595 2.17879132]
[ 1.0833688 -2.49961629 7.00007655 -0.15282204 1.87586675
0.27852656 4.97079046 0.36898418 1.25815808 0.62709786
-2.28856072 -4.4913263 -0.99267853 -3.53176015 1.29562473
2.75019665 2.6235467 1.70131601 -1.26434869 1.19921402]
[ 7.9969427 -3.91159384 -0.15282204 13.27229795 -1.15112991
-1.8349316 9.36737938 -6.88027996 -3.44988059 3.86128427
-4.20041619 -0.89396207 -2.36306315 -0.91486532 -1.21475108
0.65708152 1.06471897 2.6978082 1.75205573 5.70087991]
[ 3.87467193 -0.21157353 1.87586675 -1.15112991 8.29256331
3.35485846 2.98589263 5.24021221 1.92314046 -1.39391734
1.45251899 2.37259112 1.72757387 0.22962731 -3.08161463
3.74265298 0.97111073 -0.45038332 0.57470723 0.60555101]
[ 1.50967726 7.77021441 0.27852656 -1.8349316 3.35485846
10.74932337 -3.09620191 -3.65676398 5.08868007 -2.27370806
-2.76342062 1.76060838 4.90087407 -4.3687312 -1.48314203
1.65164559 -0.14689002 -3.84423523 2.9776338 4.08722619]
[ 8.99905872 -7.68939864 4.97079046 9.36737938 2.98589263
-3.09620191 18.96170378 0.28895884 -6.87013411 2.56397276
-5.55160655 -1.99033508 -3.60904734 -4.05602828 -6.1083571
4.55827183 1.22348751 8.05052495 -1.58439686 3.32385121]
[ 0.12777352 -1.91063411 0.36898418 -6.88027996 5.24021221
-3.65676398 0.28895884 19.91673372 3.33673838 -0.09503274
3.0956781 6.23861452 -4.3083338 -0.34706999 -5.16326523
4.08610411 0.41609125 -3.34294562 -2.18623616 -6.1540616 ]
[ 0.43394861 4.19848663 1.25815808 -3.44988059 1.92314046
5.08868007 -6.87013411 3.33673838 12.45456048 -4.99829476
-0.86805133 0.6019164 3.99150264 -5.82765994 5.49617809
0.20216342 3.0840823 -8.24793706 1.27704263 3.47351338]
[ 1.07735038 -0.55822402 0.62709786 3.86128427 -1.39391734
-2.27370806 2.56397276 -0.09503274 -4.99829476 8.17527989
-2.24023284 1.07815721 -6.56182658 3.04014034 -1.88301526
1.4877693 -1.77863933 1.1017647 1.22987075 -0.78965001]
[ -3.1703806 -0.03952267 -2.28856072 -4.20041619 1.45251899
-2.76342062 -5.55160655 3.0956781 -0.86805133 -2.24023284
14.48952669 -1.30719302 0.24748638 5.495292 0.44313299
0.33577091 4.06484291 -1.0378958 -6.49094087 -3.56689041]
[ 1.09109771 1.93215075 -4.4913263 -0.89396207 2.37259112
1.76060838 -1.99033508 6.23861452 0.6019164 1.07815721
-1.30719302 10.0674736 0.02859867 3.55132284 -7.61089069
-0.91203925 -2.37169983 -0.75663067 3.34675629 -0.53515101]
[ -1.07662889 1.81615228 -0.99267853 -2.36306315 1.72757387
4.90087407 -3.60904734 -4.3083338 3.99150264 -6.56182658
0.24748638 0.02859867 7.76001248 -0.9677733 0.32162034
-2.33903774 0.47010381 -0.16567762 1.73251552 1.72526556]
[ -3.54623681 -2.60980611 -3.53176015 -0.91486532 0.22962731
-4.3687312 -4.05602828 -0.34706999 -5.82765994 3.04014034
5.495292 3.55132284 -0.9677733 11.75519799 -2.17555052
-3.40378374 -1.89558073 3.81733369 0.67213056 -3.82160471]
[ -1.57826015 2.19011736 1.29562473 -1.21475108 -3.08161463
-1.48314203 -6.1083571 -5.16326523 5.49617809 -1.88301526
0.44313299 -7.61089069 0.32162034 -2.17555052 18.82375895
-2.1326618 0.90411903 -6.07250375 -1.72862917 4.37717899]
[ 3.44374856 0.45371261 2.75019665 0.65708152 3.74265298
1.65164559 4.55827183 4.08610411 0.20216342 1.4877693
0.33577091 -0.91203925 -2.33903774 -3.40378374 -2.1326618
5.05547318 1.23688901 -1.32362849 -1.34131298 -0.03592334]
[ 1.6016345 -1.2512186 2.6235467 1.06471897 0.97111073
-0.14689002 1.22348751 0.41609125 3.0840823 -1.77863933
4.06484291 -2.37169983 0.47010381 -1.89558073 0.90411903
1.23688901 5.21556282 -0.55939576 -3.44239019 2.44993085]
[ -0.0581004 -6.41885814 1.70131601 2.6978082 -0.45038332
-3.84423523 8.05052495 -3.34294562 -8.24793706 1.1017647
-1.0378958 -0.75663067 -0.16567762 3.81733369 -6.07250375
-1.32362849 -0.55939576 9.79368853 -0.72529697 -1.29174844]
[ 0.67842678 1.16216595 -1.26434869 1.75205573 0.57470723
2.9776338 -1.58439686 -2.18623616 1.27704263 1.22987075
-6.49094087 3.34675629 1.73251552 0.67213056 -1.72862917
-1.34131298 -3.44239019 -0.72529697 6.3085202 0.45959498]
[ 5.73115896 2.17879132 1.19921402 5.70087991 0.60555101
4.08722619 3.32385121 -6.1540616 3.47351338 -0.78965001
-3.56689041 -0.53515101 1.72526556 -3.82160471 4.37717899
-0.03592334 2.44993085 -1.29174844 0.45959498 9.3876709 ]]
AB
[[ -41.66123374 -35.99255285 -32.02996219 -29.19573998 -26.46082956
-26.4658909 -29.13735484 -30.69597239 -34.87319444 -42.36626558
-51.58778232 -58.0274945 -66.03406947 -73.35234256 -79.43528478
-85.65143315 -93.91594944 -101.46020954 -105.54275033 -112.6105561 ]
[ 19.5288167 16.91641275 13.3122596 11.06027386 5.29196759
1.3036692 -2.67227814 -6.77984669 -8.29079694 -11.16655158
-13.41650248 -15.71620562 -15.53654762 -15.16323783 -11.56159891
-11.54042477 -12.03914262 -13.1505654 -11.30139881 -9.01446931]
[ 34.6247525 31.73736673 28.10012462 22.61056554 17.95887697
14.18816494 8.40404556 1.76299988 -0.32736905 -1.98167351
-2.70302572 1.00812932 7.8248919 12.79471984 20.24023559
25.11915708 30.47231133 37.71095237 43.81603827 48.36682168]
[ -43.16936325 -42.03567095 -36.27241998 -33.1332005 -33.64850651
-33.80596223 -31.23824343 -32.23792777 -32.05220237 -32.6646148
-33.30997366 -31.88097227 -28.74508724 -25.51455114 -21.95957329
-19.36269993 -16.02788015 -14.60298433 -15.35707785 -16.56673589]
[ 12.32146195 10.67537568 11.29257154 12.05358084 9.00327556
5.64652449 4.27688157 -3.50446277 -12.01501528 -15.25773024
-21.98707237 -26.13113255 -31.29446943 -33.20252897 -35.65170156
-34.16199489 -34.29684606 -32.50295349 -33.77077673 -35.6081113 ]
[ -1.34405195 -1.82844606 -0.32698677 2.68938686 6.22627046
7.30678696 8.89118567 10.89568217 12.30002903 14.43549831
19.03115883 21.58295583 23.76958 23.20946673 20.41635957
19.40785843 18.75883768 18.9967821 18.1744908 16.27114348]
[ 70.28505869 63.33041865 56.89199808 52.5238939 48.91385242
48.86262699 52.0900316 59.65039138 67.70958714 77.19183558
84.47449345 92.2470063 99.62773505 108.74814638 114.44494978
118.02384112 124.22981206 132.85861447 141.92632121 149.47944283]
[ -78.43304083 -74.45352214 -71.60927725 -66.89691845 -64.59303531
-63.11652379 -62.90016609 -62.28596683 -57.97986718 -53.39779679
-49.09412808 -43.93103667 -40.5959588 -38.49918403 -38.93321354
-41.93038963 -43.24657462 -43.71489645 -44.26764099 -46.34510944]
[ -3.71133192 -3.4620878 -4.27333665 -4.77951873 -7.60965145
-9.44071479 -13.60623219 -16.87153326 -14.81857571 -11.27205502
-9.23411 -7.57392571 -5.79371005 -4.9521955 -5.43685429
-2.36224306 1.13609409 4.17770482 5.94644949 6.39534029]
[ 19.06864936 17.22030172 14.52230504 13.92129233 13.03040854
13.19531823 11.8054037 10.7329968 8.71253977 4.81674344
2.66733286 4.29744271 2.12919215 -1.91688059 -4.0460585
-2.6356135 0.2950604 4.43439557 8.84771376 10.88333313]]
A(B-xI)
please input x: 2
[[ -39.98363892 -34.28646263 -30.90159375 -29.09642819 -23.7208578
-23.7994883 -30.25020124 -28.0773679 -31.55734534 -40.63781998
-54.36958687 -56.46063172 -66.72237135 -74.58767343 -79.30207864
-83.60306523 -94.63620564 -104.92192883 -102.55748537 -112.33208616]
[ 21.64053745 17.90816194 11.96009218 14.5765944 3.5119597
1.29131816 -2.54065693 -9.37646499 -6.92599257 -11.7923553
-13.36675024 -18.19556676 -15.73019942 -18.39156694 -7.98113414
-11.02053277 -11.42643768 -16.11115479 -11.73916171 -7.22822302]
[ 33.56015854 32.48722308 29.95244159 21.77269502 17.07790043
16.20157229 9.26097185 -2.78767685 -0.76343354 -2.91462574
-7.13553297 -2.09747822 9.67182654 10.31903202 22.80682984
24.64492433 28.58682455 38.8445075 45.37034077 48.96562536]
[ -41.4584794 -46.66522961 -33.64838851 -29.47867501 -34.0063568
-36.53113673 -27.67084031 -33.4233375 -31.25406456 -32.63166835
-35.38433391 -33.58785591 -28.83973831 -25.83899289 -21.00146879
-20.10064635 -14.11795618 -12.42399498 -14.90151333 -14.93181779]
[ 15.07643628 8.41209355 11.1487581 15.8648954 9.30972136
3.65941634 10.68858299 -2.7752546 -17.28285283 -11.77110308
-24.57235431 -25.11185586 -34.54974675 -32.66141594 -39.59058081
-32.53743704 -36.2255898 -29.44123769 -33.20126541 -36.3365578 ]
[ -1.57047172 -3.81429947 -1.8419011 2.16887687 8.68263758
6.80290474 8.47108788 11.49583181 11.56890662 11.97530707
21.07502233 21.94812867 26.51631744 25.44246062 18.63175355
19.04837806 17.8718725 20.05701783 19.25554681 13.65698229]
[ 66.77472246 62.81419919 54.82168168 51.7658312 45.35503636
45.58399694 47.75707643 59.1515554 66.28653447 79.39142613
83.98463848 92.63879041 97.88805246 112.17175431 116.56286183
115.39676152 121.80698058 132.41971014 143.44090634 146.56758819]
[ -76.47074283 -73.31824835 -73.47739116 -64.48844279 -63.7656637
-61.85636998 -63.29800764 -65.97786722 -58.25583793 -53.11939512
-49.95355079 -42.10302311 -39.35765571 -35.96837975 -36.37006695
-43.61138075 -44.09443776 -43.63047376 -42.74291708 -42.48076122]
[ -4.08838596 -2.40159484 -4.57840342 -2.45556809 -8.60872084
-7.10626073 -14.50644851 -22.18979189 -16.31213883 -9.76347937
-8.85634926 -7.69395708 -4.85500894 -3.62602215 -8.9961243
-2.78596898 1.59282051 5.45057087 7.26630336 6.71642117]
[ 19.49071212 18.06995077 12.42532107 14.2111634 11.97461507
14.75014246 11.48789606 11.68104692 10.58787908 3.07035769
-1.11218757 8.09580311 4.00701434 -3.83377541 -7.58568141
-4.1558424 -0.91360085 4.16041253 11.22541258 11.49266763]]
#exercise 9.2
vector b:
[[ 0.19400148]
[ 1.74475416]
[ 1.05649293]
[-1.63046725]
[ 0.42759598]
[-0.19584916]
[-0.58532903]
[ 1.14874146]
[ 0.14935076]
[-0.75203852]
[-1.29661338]
[-1.09165483]
[-0.08941965]
[-0.96077948]
[-1.67055136]
[-0.22884009]
[ 1.436191 ]
[ 0.6368024 ]
[-0.76163487]
[-0.30313947]]
[[ 0.77277782]
[-1.11950696]
[-0.99934947]
[ 2.3725117 ]
[-1.34075418]
[ 0.11698263]
[ 1.06177518]
[-1.36673059]
[ 0.04900071]
[ 0.17840721]
[ 0.37476671]
[ 0.39863831]
[-0.9367975 ]
[ 0.08079398]
[ 1.07574157]
[ 0.11165991]
[-1.23220985]
[-0.29952433]
[ 0.92846634]
[-0.23184623]]
#exercise 9.3
the Frobenius norm of A:
14.6947588133
the infinity norm of B:
210.0
the largest singular values of B
157.955486199
the smallest singular values of B
0.503096979329
#exercise 9.4
the largest eigenvalue
(1.14989582352e+32+0j)
the corresponding eigenvector
[ 2.62298249e-18+0.j 1.07980266e-16+0.j -5.31577465e-08+0.j
1.68166249e-23+0.j -1.13074868e-22+0.j 3.16756873e-16+0.j
1.09918026e-20+0.j 8.98008414e-16+0.j -1.00000000e+00+0.j
-2.14806759e-26+0.j]
iterations needed
99
#exercise 9.5
please input probility: 0.3
3.69337534581
#exercise 9.6
please input z: 2
the element in A that is closest to z
[ 1.96943963]
Process finished with exit code 0