{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"id": "5f734ba6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"3.0 & 1.0 & 0.0 \\\\\n",
"1.0 & 0.0 & 0.0 \\\\\n",
"0.0 & 1.0 & -1.0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 3.0 1.0 0.0]\n",
"[ 1.0 0.0 0.0]\n",
"[ 0.0 1.0 -1.0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = matrix(RDF,[[3,1,0],[1,0,0],[0,1,-1]])\n",
"show(A)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "37c10d96",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"3.300000000000001 & -0.03015113445777634 & 0.09534625892455918 \\\\\n",
"-0.33166247903554 & -1.209090909090909 & 0.6612035107624792 \\\\\n",
"0.0 & -0.2874797872880346 & -0.09090909090909098\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 3.300000000000001 -0.03015113445777634 0.09534625892455918]\n",
"[ -0.33166247903554 -1.209090909090909 0.6612035107624792]\n",
"[ 0.0 -0.2874797872880346 -0.09090909090909098]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Q1,R1=A.QR()\n",
"A2 = R1*Q1\n",
"show(A2)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "ab4ebefa",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"3.3019027159736085 & 0.3026001168112323 & 0.06527214388879723 \\\\\n",
"0.012426900402049768 & -1.0050092530424077 & -0.9503938545184746 \\\\\n",
"0.0 & 0.004351688393828896 & -0.296893462931199\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 3.3019027159736085 0.3026001168112323 0.06527214388879723]\n",
"[0.012426900402049768 -1.0050092530424077 -0.9503938545184746]\n",
"[ 0.0 0.004351688393828896 -0.296893462931199]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Q2,R2=A2.QR()\n",
"A2 = R2*Q2\n",
"show(A2)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "7a4a4f09",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[-1.0, -0.30277563773199434, 3.302775637731995]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.eigenvalues()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94956e2a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d90e723b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "8f757d76",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"\\frac{16}{25} & -\\frac{14}{25} & -2 \\\\\n",
"-\\frac{12}{25} & -\\frac{52}{25} & -1 \\\\\n",
"-\\frac{3}{5} & -\\frac{3}{5} & -3\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 16/25 -14/25 -2]\n",
"[-12/25 -52/25 -1]\n",
"[ -3/5 -3/5 -3]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = matrix([[16/25,-14/25,-2],[-12/25,-52/25,-1],[-3/5,-3/5,-3]])\n",
"show(A)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "90c6d04a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((-9/25, -12/25, -3/5), 1, 3/5*sqrt(2))"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c1 = A.column(0)\n",
"u1 = c1 - c1.norm(2)*vector([1,0,0])\n",
"u1,c1.norm(2),u1.norm()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "24d6260d",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"\\frac{16}{25} & -\\frac{12}{25} & -\\frac{3}{5} \\\\\n",
"-\\frac{12}{25} & \\frac{9}{25} & -\\frac{4}{5} \\\\\n",
"-\\frac{3}{5} & -\\frac{4}{5} & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 16/25 -12/25 -3/5]\n",
"[-12/25 9/25 -4/5]\n",
"[ -3/5 -4/5 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Q1 = matrix.identity(3) - 2*u1.column()*u1.row()/(u1*u1)\n",
"show(Q1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1d89170c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"1 & 1 & 1 \\\\\n",
"0 & 0 & 3 \\\\\n",
"0 & 2 & 2\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[1 1 1]\n",
"[0 0 3]\n",
"[0 2 2]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"R1 = Q1*A\n",
"show(R1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7bd4c6f6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((-2, 2), 2)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c2 = vector([0,2])\n",
"u2 = c2 - c2.norm(2)*vector([1,0])\n",
"u2,c2.norm(2)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "8d453ce0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rr}\n",
"0 & 1 \\\\\n",
"1 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[0 1]\n",
"[1 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Qt = matrix.identity(2) - 2*u2.column()*u2.row()/(u2*u2)\n",
"show(Qt)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ca664f11",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"1 & 0 & 0 \\\\\n",
"0 & 0 & 1 \\\\\n",
"0 & 1 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[1 0 0]\n",
"[0 0 1]\n",
"[0 1 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Q2 = matrix([[1,0,0],[0,0,1],[0,1,0]])\n",
"show(Q2)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "6a0e7255",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"1 & 1 & 1 \\\\\n",
"0 & 2 & 2 \\\\\n",
"0 & 0 & 3\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[1 1 1]\n",
"[0 2 2]\n",
"[0 0 3]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"R2 = Q2*R1\n",
"R = R2\n",
"show(R)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b76841ed",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"\\frac{16}{25} & -\\frac{3}{5} & -\\frac{12}{25} \\\\\n",
"-\\frac{12}{25} & -\\frac{4}{5} & \\frac{9}{25} \\\\\n",
"-\\frac{3}{5} & 0 & -\\frac{4}{5}\n",
"\\end{array}\\right) \\left(\\begin{array}{rrr}\n",
"1 & 0 & 0 \\\\\n",
"0 & 1 & 0 \\\\\n",
"0 & 0 & 1\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 16/25 -3/5 -12/25]\n",
"[-12/25 -4/5 9/25]\n",
"[ -3/5 0 -4/5] [1 0 0]\n",
"[0 1 0]\n",
"[0 0 1]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Q = Q1*Q2\n",
"show(Q,Q.transpose()*Q)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "fe64a9e1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{rrr}\n",
"\\frac{16}{25} & -\\frac{14}{25} & -2 \\\\\n",
"-\\frac{12}{25} & -\\frac{52}{25} & -1 \\\\\n",
"-\\frac{3}{5} & -\\frac{3}{5} & -3\n",
"\\end{array}\\right) \\left(\\begin{array}{rrr}\n",
"\\frac{16}{25} & -\\frac{14}{25} & -2 \\\\\n",
"-\\frac{12}{25} & -\\frac{52}{25} & -1 \\\\\n",
"-\\frac{3}{5} & -\\frac{3}{5} & -3\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ 16/25 -14/25 -2]\n",
"[-12/25 -52/25 -1]\n",
"[ -3/5 -3/5 -3] [ 16/25 -14/25 -2]\n",
"[-12/25 -52/25 -1]\n",
"[ -3/5 -3/5 -3]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"show(Q*R,A)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c850fa32",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "SageMath 9.5",
"language": "sage",
"name": "sagemath"
},
"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.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}