Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw4 is done #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\\bf{25.3}$\n",
"\n",
"Only matrix (a) can be obtained by left and right multiplication. Rest cannot be done.\n",
"\n",
"Matix (a) is $\\begin{bmatrix}\n",
" x & x & x \\\\ \n",
" x & x & x \\\\ \n",
" x & x & x\n",
"\\end{bmatrix}$\n",
"\n",
"\n",
"$Q_1*A=\\begin{bmatrix}\n",
" x & x & x \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & x & x\n",
"\\end{bmatrix}=A_1$\n",
"\n",
"$Q_1*A*Q_2=\\begin{bmatrix}\n",
" x & x & 0 \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & x & x\n",
"\\end{bmatrix}=A_2$\n",
"\n",
"$Q_3*Q_1*A*Q_2=\\begin{bmatrix}\n",
" x & x & 0 \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & 0 & x\n",
"\\end{bmatrix}=A_3$"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A =\n",
"\n",
" 18 19 12\n",
" 10 1 12\n",
" 15 2 2\n",
"\n",
"A1 =\n",
"\n",
" 25.47548 14.99481 14.36676\n",
" 0.00000 6.35777 8.83397\n",
" 0.00000 10.03665 -2.74904\n",
"\n",
"A2 =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 10.70228 -1.98027\n",
" 0.00000 5.34528 8.92858\n",
"\n",
"A3 =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 11.96290 2.21789\n",
" 0.00000 0.00000 -8.87254\n",
"\n",
"ans =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 11.96290 2.21789\n",
" 0.00000 0.00000 -8.87254\n",
"\n"
]
}
],
"source": [
"A=round(rand(3,3)*20)\n",
"\n",
"e1=[1;0;0];\n",
"v1=norm(A(:,1))*e1-A(:,1);\n",
"v1=v1/norm(v1);\n",
"Q1=eye(3,3)-2*(v1*v1');\n",
"A1=Q1*A;\n",
"A1(abs(A1)<0.000000001)=0 %to get rid of error which comes from machine precision\n",
"% for example [Q , R]=qr(A) ==> Q*R-A is not zero 2\n",
"\n",
"e2=[1;0];\n",
"v2=norm(A1'(2:end,1))*e2-A1'(2:end,1);\n",
"v2=v2/norm(v2);\n",
"Q2=eye(2,2)-2*(v2*v2');\n",
"Q2=[1 0 0; 0 Q2(1,:);0 Q2(2,:)]; \n",
"Q2=Q2';\n",
"A2=A1*Q2;\n",
"A2(abs(A2)<0.000000001)=0\n",
"\n",
"\n",
"e3=[1;0];\n",
"v3=norm(A2(2:end,2))*e3-A2(2:end,2);\n",
"v3=v3/norm(v3);\n",
"Q3=eye(2,2)-2*(v3*v3');\n",
"Q3=[1 0 0; 0 Q3(1,:);0 Q3(2,:)]; \n",
"A3=Q3*A2;\n",
"A3(abs(A3)<0.000000001)=0\n",
"\n",
"Q3*Q1*A*Q2"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Octave",
"language": "octave",
"name": "octave"
},
"language_info": {
"file_extension": ".m",
"help_links": [
{
"text": "GNU Octave",
"url": "https://www.gnu.org/software/octave/support.html"
},
{
"text": "Octave Kernel",
"url": "https://github.com/Calysto/octave_kernel"
},
{
"text": "MetaKernel Magics",
"url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
}
],
"mimetype": "text/x-octave",
"name": "octave",
"version": "4.0.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
144 changes: 144 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\\bf{25.3}$\n",
"\n",
"Only matrix (a) can be obtained by left and right multiplication. Rest cannot be done.\n",
"\n",
"Matix (a) is $\\begin{bmatrix}\n",
" x & x & x \\\\ \n",
" x & x & x \\\\ \n",
" x & x & x\n",
"\\end{bmatrix}$\n",
"\n",
"\n",
"$Q_1*A=\\begin{bmatrix}\n",
" x & x & x \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & x & x\n",
"\\end{bmatrix}=A_1$\n",
"\n",
"$Q_1*A*Q_2=\\begin{bmatrix}\n",
" x & x & 0 \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & x & x\n",
"\\end{bmatrix}=A_2$\n",
"\n",
"$Q_3*Q_1*A*Q_2=\\begin{bmatrix}\n",
" x & x & 0 \\\\ \n",
" 0 & x & x \\\\ \n",
" 0 & 0 & x\n",
"\\end{bmatrix}=A_3$"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A =\n",
"\n",
" 18 19 12\n",
" 10 1 12\n",
" 15 2 2\n",
"\n",
"A1 =\n",
"\n",
" 25.47548 14.99481 14.36676\n",
" 0.00000 6.35777 8.83397\n",
" 0.00000 10.03665 -2.74904\n",
"\n",
"A2 =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 10.70228 -1.98027\n",
" 0.00000 5.34528 8.92858\n",
"\n",
"A3 =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 11.96290 2.21789\n",
" 0.00000 0.00000 -8.87254\n",
"\n",
"ans =\n",
"\n",
" 25.47548 20.76651 0.00000\n",
" 0.00000 11.96290 2.21789\n",
" 0.00000 0.00000 -8.87254\n",
"\n"
]
}
],
"source": [
"A=round(rand(3,3)*20)\n",
"\n",
"e1=[1;0;0];\n",
"v1=norm(A(:,1))*e1-A(:,1);\n",
"v1=v1/norm(v1);\n",
"Q1=eye(3,3)-2*(v1*v1');\n",
"A1=Q1*A;\n",
"A1(abs(A1)<0.000000001)=0 %to get rid of error which comes from machine precision\n",
"% for example [Q , R]=qr(A) ==> Q*R-A is not zero 2\n",
"\n",
"e2=[1;0];\n",
"v2=norm(A1'(2:end,1))*e2-A1'(2:end,1);\n",
"v2=v2/norm(v2);\n",
"Q2=eye(2,2)-2*(v2*v2');\n",
"Q2=[1 0 0; 0 Q2(1,:);0 Q2(2,:)]; \n",
"Q2=Q2';\n",
"A2=A1*Q2;\n",
"A2(abs(A2)<0.000000001)=0\n",
"\n",
"\n",
"e3=[1;0];\n",
"v3=norm(A2(2:end,2))*e3-A2(2:end,2);\n",
"v3=v3/norm(v3);\n",
"Q3=eye(2,2)-2*(v3*v3');\n",
"Q3=[1 0 0; 0 Q3(1,:);0 Q3(2,:)]; \n",
"A3=Q3*A2;\n",
"A3(abs(A3)<0.000000001)=0\n",
"\n",
"Q3*Q1*A*Q2"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Octave",
"language": "octave",
"name": "octave"
},
"language_info": {
"file_extension": ".m",
"help_links": [
{
"text": "GNU Octave",
"url": "https://www.gnu.org/software/octave/support.html"
},
{
"text": "Octave Kernel",
"url": "https://github.com/Calysto/octave_kernel"
},
{
"text": "MetaKernel Magics",
"url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
}
],
"mimetype": "text/x-octave",
"name": "octave",
"version": "4.0.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}