4.0 KiB
4.0 KiB
Zadanie 4.6
A=matrix(QQ,5,3,[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31])
print('A =')
print(A, '\n')
print('b =')
b=vector(QQ,[-1,0,1,0,1])
print(b, '\n')
print('A^T * A =')
print(A.transpose()*A, '\n')
print('Macierz A^T*A jest kwadratowa, więc rozwiązanie istnieje\n')
u=(A.transpose()*A)^(-1)*A.transpose()*b
print('u = (A^T * A)^-1 * A^T * b =')
print(u, '\n')
print('b - A * u = ')
print(b - A * u, '\n')
[1;31m---------------------------------------------------------------------------[0m [1;31mNameError[0m Traceback (most recent call last) Cell [1;32mIn[1], line 5[0m [0;32m 2[0m [39mfrom[39;00m [39msympy[39;00m [39mimport[39;00m symbols, Matrix [0;32m 3[0m [39mfrom[39;00m [39mnumpy[39;00m[39m.[39;00m[39mlinalg[39;00m [39mimport[39;00m eig [1;32m----> 5[0m A[39m=[39mnp[39m.[39mmatrix(QQ,[39m5[39m,[39m3[39m,[[39m2[39m, [39m4[39m, [39m6[39m, [39m8[39m, [39m10[39m, [39m12[39m, [39m14[39m, [39m16[39m, [39m18[39m, [39m20[39m, [39m22[39m, [39m24[39m, [39m26[39m, [39m28[39m, [39m31[39m]) [0;32m 6[0m [39mprint[39m(A[39m.[39mtranspose()[39m*[39mA) [0;32m 7[0m [39mprint[39m((A[39m.[39mtranspose()[39m*[39mA)[39m^[39m([39m-[39m[39m1[39m)) [1;31mNameError[0m: name 'QQ' is not defined
Zadanie 4.7
zbior=[(1,1),(2,3),(4,5)]
print('zbior punktów = ', zbior)
m=matrix(3,2,[1,exp(1.0),1,exp(2.0),1,exp(4.0)])
a,b,t=var('a,b,t')
m*vector([a,b])-vector([1,3,5])
print('\n (m^T * m)^-1 * m^T * vector =')
z = (m.transpose()*m)^(-1)*m.transpose()*vector([1,3,5])
print(z)
plot(z[0] +z[1]*exp(t),(t,0,4))+sum([point(x) for x in zbior])
Zadanie 4.9
m=matrix(3,3,[1,1,0,1,2,2,0,2,3])
eigenvalues = np.m.eigvals(matrix)
eigen=m.right_eigenvectors()
e1=eigen[0][1][0]
e2=eigen[1][1][0]
print(e1.dot_product(e2))
e3=eigen[2][1][0]
print(e3.dot_product(e1))
print(e2.dot_product(e3))