improvements

This commit is contained in:
piotrwrzodak 2023-06-14 21:20:54 +02:00
parent 0d6328617e
commit 51a10d0cff

View File

@ -1,7 +1,6 @@
{ {
"cells": [ "cells": [
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -9,7 +8,6 @@
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [] "source": []
@ -32,31 +30,28 @@
} }
], ],
"source": [ "source": [
"import numpy as np\n", "A=matrix(QQ,5,3,[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31])\n",
"from sympy import symbols, Matrix\n", "print('A =')\n",
"from numpy.linalg import eig\n", "print(A, '\\n')\n",
"\n", "\n",
"A=np.matrix(QQ,5,3,[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31])\n", "print('b =')\n",
"print(A.transpose()*A)\n", "b=vector(QQ,[-1,0,1,0,1])\n",
"print((A.transpose()*A)^(-1))\n", "print(b, '\\n')\n",
"mm=(A.transpose()*A)^(-1)\n",
"mm=(A.transpose()*A)^(-1)*A.transpose()\n",
"print(mm)\n",
"\n", "\n",
"b1=np.vector([-1,0,1,0,1])\n", "print('A^T * A =')\n",
"mm1=mm*b1\n", "print(A.transpose()*A, '\\n')\n",
"print(mm1)\n", "print('Macierz A^T*A jest kwadratowa, więc rozwiązanie istnieje\\n')\n",
"print((b1-A*mm1))\n",
"b2=np.vector([1,1,1,1,1])\n",
"mm2=mm*b2\n",
"print(mm2)\n",
"print((b2-A*mm2))\n",
"\n", "\n",
"b2 in (m.transpose()).image()" "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')"
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -69,41 +64,22 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"zb1=[(1,1),(2,3),(4,5)]\n", "zbior=[(1,1),(2,3),(4,5)]\n",
"zb2=[(1,1),(2,3),(3,4),(4,5),(5,7),(6,9)]\n", "print('zbior punktów = ', zbior)\n",
"\n", "m=matrix(3,2,[1,exp(1.0),1,exp(2.0),1,exp(4.0)])\n",
"m1=matrix(3,2,[1,exp(1.0),1,exp(2.0),1,exp(4.0)])\n",
"m2=matrix(6,2,[1,exp(1.0),1,exp(2.0),1,exp(3.0),1,exp(4.0),1,exp(5.0),1,exp(6.0)])\n",
"\n", "\n",
"a,b,t=var('a,b,t')\n", "a,b,t=var('a,b,t')\n",
"\n", "\n",
"m1*vector([a,b])-vector([1,3,5])\n", "m*vector([a,b])-vector([1,3,5])\n",
"m2*vector([a,b])-vector([1,3,4,5,7,9])\n",
"\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", "\n",
"\n", "plot(z[0] +z[1]*exp(t),(t,0,4))+sum([point(x) for x in zbior])"
"M1=m1.transpose()*m1\n",
"M1.det()\n",
"\n",
"\n",
"\n",
"M2=m2.transpose()*m2\n",
"M2.det()\n",
"\n",
"\n",
"\n",
"M1^(-1)*m1.transpose()*vector([1,3,5])\n",
"\n",
"M2^(-1)*m2.transpose()*vector([1,3,4,5,7,9])\n",
"\n",
"\n",
"plot(1.64148598265947+ 0.0629860338045423*exp(t),(t,0,4))+sum([point(x) for x in zb1])\n",
"\n",
"plot(3.10041190358990+ 0.0163320609303546*exp(t),(t,0,6))+sum([point(x) for x in zb2])"
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -132,7 +108,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "base", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -146,9 +122,8 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.9" "version": "3.10.11"
}, }
"orig_nbformat": 4
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 2