131 lines
4.0 KiB
Plaintext
131 lines
4.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Zadanie 4.6"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "NameError",
|
|
"evalue": "name 'QQ' is not defined",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
|
"Cell \u001b[1;32mIn[1], line 5\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msympy\u001b[39;00m \u001b[39mimport\u001b[39;00m symbols, Matrix\n\u001b[0;32m 3\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mnumpy\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlinalg\u001b[39;00m \u001b[39mimport\u001b[39;00m eig\n\u001b[1;32m----> 5\u001b[0m A\u001b[39m=\u001b[39mnp\u001b[39m.\u001b[39mmatrix(QQ,\u001b[39m5\u001b[39m,\u001b[39m3\u001b[39m,[\u001b[39m2\u001b[39m, \u001b[39m4\u001b[39m, \u001b[39m6\u001b[39m, \u001b[39m8\u001b[39m, \u001b[39m10\u001b[39m, \u001b[39m12\u001b[39m, \u001b[39m14\u001b[39m, \u001b[39m16\u001b[39m, \u001b[39m18\u001b[39m, \u001b[39m20\u001b[39m, \u001b[39m22\u001b[39m, \u001b[39m24\u001b[39m, \u001b[39m26\u001b[39m, \u001b[39m28\u001b[39m, \u001b[39m31\u001b[39m])\n\u001b[0;32m 6\u001b[0m \u001b[39mprint\u001b[39m(A\u001b[39m.\u001b[39mtranspose()\u001b[39m*\u001b[39mA)\n\u001b[0;32m 7\u001b[0m \u001b[39mprint\u001b[39m((A\u001b[39m.\u001b[39mtranspose()\u001b[39m*\u001b[39mA)\u001b[39m^\u001b[39m(\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m))\n",
|
|
"\u001b[1;31mNameError\u001b[0m: name 'QQ' is not defined"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"A=matrix(QQ,5,3,[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31])\n",
|
|
"print('A =')\n",
|
|
"print(A, '\\n')\n",
|
|
"\n",
|
|
"print('b =')\n",
|
|
"b=vector(QQ,[-1,0,1,0,1])\n",
|
|
"print(b, '\\n')\n",
|
|
"\n",
|
|
"print('A^T * A =')\n",
|
|
"print(A.transpose()*A, '\\n')\n",
|
|
"print('Macierz A^T*A jest kwadratowa, więc rozwiązanie istnieje\\n')\n",
|
|
"\n",
|
|
"u=(A.transpose()*A)^(-1)*A.transpose()*b\n",
|
|
"print('u = (A^T * A)^-1 * A^T * b =')\n",
|
|
"print(u, '\\n')\n",
|
|
"\n",
|
|
"\n",
|
|
"print('b - A * u = ')\n",
|
|
"print(b - A * u, '\\n')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Zadanie 4.7\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"zbior=[(1,1),(2,3),(4,5)]\n",
|
|
"print('zbior punktów = ', zbior)\n",
|
|
"m=matrix(3,2,[1,exp(1.0),1,exp(2.0),1,exp(4.0)])\n",
|
|
"\n",
|
|
"a,b,t=var('a,b,t')\n",
|
|
"\n",
|
|
"m*vector([a,b])-vector([1,3,5])\n",
|
|
"\n",
|
|
"print('\\n (m^T * m)^-1 * m^T * vector =')\n",
|
|
"z = (m.transpose()*m)^(-1)*m.transpose()*vector([1,3,5])\n",
|
|
"print(z)\n",
|
|
"\n",
|
|
"plot(z[0] +z[1]*exp(t),(t,0,4))+sum([point(x) for x in zbior])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Zadanie 4.9"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"m=matrix(3,3,[1,1,0,1,2,2,0,2,3])\n",
|
|
"\n",
|
|
"eigenvalues = np.m.eigvals(matrix)\n",
|
|
"\n",
|
|
"eigen=m.right_eigenvectors()\n",
|
|
"e1=eigen[0][1][0]\n",
|
|
"e2=eigen[1][1][0]\n",
|
|
"print(e1.dot_product(e2))\n",
|
|
"e3=eigen[2][1][0]\n",
|
|
"print(e3.dot_product(e1))\n",
|
|
"print(e2.dot_product(e3))"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.11"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|