Permalink
Showing
with
13,331 additions
and 6 deletions.
- +6 −6 lecture_12/lecture_12.ipynb
- BIN lecture_13/.GS_rel.m.swp
- BIN lecture_13/.GaussSeidel.m.swp
- BIN lecture_13/.Jacobi_rel.m.swp
- 0 lecture_13/.ipynb_checkpoints/{lecture_12-checkpoint.ipynb → lecture_13-checkpoint.ipynb}
- BIN lecture_13/.lambda_fcn.m.swp
- +36 −0 lecture_13/GS_rel.m
- +35 −0 lecture_13/GaussSeidel.m
- +39 −0 lecture_13/Jacobi.m
- +41 −0 lecture_13/Jacobi_rel.m
- BIN lecture_13/efficient_soln.png
- BIN lecture_13/gp_image_01.png
- +8 −0 lecture_13/lambda_fcn.m
- +59 −0 lecture_13/lecture_13.aux
- 0 lecture_13/lecture_13.bbl
- +48 −0 lecture_13/lecture_13.blg
- +5,622 −0 lecture_13/lecture_13.ipynb
- +889 −0 lecture_13/lecture_13.log
- +943 −0 lecture_13/lecture_13.md
- +16 −0 lecture_13/lecture_13.out
- BIN lecture_13/lecture_13.pdf
- +1,255 −0 lecture_13/lecture_13.tex
- BIN lecture_13/lecture_13_files/lecture_13_22_1.pdf
- +121 −0 lecture_13/lecture_13_files/lecture_13_22_1.svg
- BIN lecture_13/lecture_13_files/lecture_13_27_0.pdf
- +131 −0 lecture_13/lecture_13_files/lecture_13_27_0.svg
- BIN lecture_13/lecture_13_files/lecture_13_34_0.pdf
- +2,040 −0 lecture_13/lecture_13_files/lecture_13_34_0.svg
- BIN lecture_13/lecture_13_files/lecture_13_34_1.pdf
- +2,040 −0 lecture_13/lecture_13_files/lecture_13_34_1.svg
- +2 −0 lecture_13/nohup.out
- BIN lecture_13/norm_A.png
- BIN lecture_13/octave-workspace
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
@@ -0,0 +1,36 @@ | ||
function [x,ea,iter] = GS_rel(A,b,lambda,es,maxit) | ||
% GaussSeidel: Gauss Seidel method | ||
% x = GaussSeidel(A,b): Gauss Seidel without relaxation | ||
% input: | ||
% A = coefficient matrix | ||
% b = right hand side vector | ||
% es = stop criterion (default = 0.00001%) | ||
% maxit = max iterations (default = 50) | ||
% output: | ||
% x = solution vector | ||
if nargin<3,error('at least 2 input arguments required'),end | ||
if nargin<5|isempty(maxit),maxit=50;end | ||
if nargin<4|isempty(es),es=0.00001;end | ||
[m,n] = size(A); | ||
if m~=n, error('Matrix A must be square'); end | ||
C = A-diag(diag(A)); | ||
x=zeros(n,1); | ||
for i = 1:n | ||
C(i,1:n) = C(i,1:n)/A(i,i); | ||
end | ||
|
||
d = b./diag(A); | ||
|
||
iter = 0; | ||
while (1) | ||
xold = x; | ||
for i = 1:n | ||
x(i) = d(i)-C(i,:)*x; | ||
x(i) = lambda*x(i)+(1-lambda)*xold(i); | ||
if x(i) ~= 0 | ||
ea(i) = abs((x(i) - xold(i))/x(i)) * 100; | ||
end | ||
end | ||
iter = iter+1; | ||
if max(ea)<=es | iter >= maxit, break, end | ||
end |
@@ -0,0 +1,35 @@ | ||
function x = GaussSeidel(A,b,es,maxit) | ||
% GaussSeidel: Gauss Seidel method | ||
% x = GaussSeidel(A,b): Gauss Seidel without relaxation | ||
% input: | ||
% A = coefficient matrix | ||
% b = right hand side vector | ||
% es = stop criterion (default = 0.00001%) | ||
% maxit = max iterations (default = 50) | ||
% output: | ||
% x = solution vector | ||
if nargin<2,error('at least 2 input arguments required'),end | ||
if nargin<4|isempty(maxit),maxit=50;end | ||
if nargin<3|isempty(es),es=0.00001;end | ||
[m,n] = size(A); | ||
if m~=n, error('Matrix A must be square'); end | ||
C = A-diag(diag(A)); | ||
x=zeros(n,1); | ||
for i = 1:n | ||
C(i,1:n) = C(i,1:n)/A(i,i); | ||
end | ||
|
||
d = b./diag(A); | ||
|
||
iter = 0; | ||
while (1) | ||
xold = x; | ||
for i = 1:n | ||
x(i) = d(i)-C(i,:)*x; | ||
if x(i) ~= 0 | ||
ea(i) = abs((x(i) - xold(i))/x(i)) * 100; | ||
end | ||
end | ||
iter = iter+1; | ||
if max(ea)<=es | iter >= maxit, break, end | ||
end |
@@ -0,0 +1,39 @@ | ||
function x = Jacobi(A,b,es,maxit) | ||
% GaussSeidel: Gauss Seidel method | ||
% x = GaussSeidel(A,b): Gauss Seidel without relaxation | ||
% input: | ||
% A = coefficient matrix | ||
% b = right hand side vector | ||
% es = stop criterion (default = 0.00001%) | ||
% maxit = max iterations (default = 50) | ||
% output: | ||
% x = solution vector | ||
if nargin<2,error('at least 2 input arguments required'),end | ||
if nargin<4|isempty(maxit),maxit=50;end | ||
if nargin<3|isempty(es),es=0.00001;end | ||
[m,n] = size(A); | ||
if m~=n, error('Matrix A must be square'); end | ||
C = A-diag(diag(A)); | ||
x=zeros(n,1); | ||
for i = 1:n | ||
C(i,1:n) = C(i,1:n)/A(i,i); | ||
end | ||
|
||
d = b./diag(A); | ||
|
||
iter = 0; | ||
while (1) | ||
xold = x; | ||
x = d-C*x; | ||
% if any values of x are zero, we add 1 to denominator so error is well-behaved | ||
i_zero=find(x==0); | ||
i=find(x~=0); | ||
if length(i_zero)>0 | ||
ea(i_zero)=abs((x-xold)./(1+x)*100); | ||
ea(i) = abs((x(i) - xold(i))./x(i)) * 100; | ||
else | ||
ea = abs((x - xold)./x) * 100; | ||
end | ||
iter = iter+1; | ||
if max(ea)<=es | iter >= maxit, break, end | ||
end |
@@ -0,0 +1,41 @@ | ||
function [x,ea,iter]= Jacobi_rel(A,b,lambda,es,maxit) | ||
% GaussSeidel: Gauss Seidel method | ||
% x = GaussSeidel(A,b): Gauss Seidel without relaxation | ||
% input: | ||
% A = coefficient matrix | ||
% b = right hand side vector | ||
% es = stop criterion (default = 0.00001%) | ||
% maxit = max iterations (default = 50) | ||
% output: | ||
% x = solution vector | ||
if nargin<3,error('at least 2 input arguments required'),end | ||
if nargin<5|isempty(maxit),maxit=50;end | ||
if nargin<4|isempty(es),es=0.00001;end | ||
[m,n] = size(A); | ||
if m~=n, error('Matrix A must be square'); end | ||
C = A-diag(diag(A)); | ||
x=zeros(n,1); | ||
for i = 1:n | ||
C(i,1:n) = C(i,1:n)/A(i,i); | ||
end | ||
|
||
d = b./diag(A); | ||
|
||
iter = 0; | ||
while (1) | ||
xold = x; | ||
x = d-C*x; | ||
% Add relaxation parameter lambda to current iteration | ||
x = lambda*x+(1-lambda)*xold; | ||
% if any values of x are zero, we add 1 to denominator so error is well-behaved | ||
i_zero=find(x==0); | ||
i=find(x~=0); | ||
if length(i_zero)>0 | ||
ea(i_zero)=abs((x-xold)./(1+x)*100); | ||
ea(i) = abs((x(i) - xold(i))./x(i)) * 100; | ||
else | ||
ea = abs((x - xold)./x) * 100; | ||
end | ||
iter = iter+1; | ||
if max(ea)<=es | iter >= maxit, break, end | ||
end |
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@ | ||
function iters = lambda_fcn(A,b,lambda) | ||
% function to minimize the number of iterations for a given Ax=b solution | ||
% using default Jacobi_rel parameters of es=0.00001 and maxit=50 | ||
|
||
[x,ea,iters]= Jacobi_rel(A,b,lambda,1e-8); | ||
end | ||
|
||
|
@@ -0,0 +1,59 @@ | ||
\relax | ||
\providecommand\hyper@newdestlabel[2]{} | ||
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} | ||
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined | ||
\global\let\oldcontentsline\contentsline | ||
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} | ||
\global\let\oldnewlabel\newlabel | ||
\gdef\newlabel#1#2{\newlabelxx{#1}#2} | ||
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} | ||
\AtEndDocument{\ifx\hyper@anchor\@undefined | ||
\let\contentsline\oldcontentsline | ||
\let\newlabel\oldnewlabel | ||
\fi} | ||
\fi} | ||
\global\let\hyper@last\relax | ||
\gdef\HyperFirstAtBeginDocument#1{#1} | ||
\providecommand\HyField@AuxAddToFields[1]{} | ||
\providecommand\HyField@AuxAddToCoFields[2]{} | ||
\providecommand \oddpage@label [2]{} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {0.1}My question from last class}{1}{subsection.0.1}} | ||
\newlabel{my-question-from-last-class}{{0.1}{1}{My question from last class}{subsection.0.1}{}} | ||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces q1\relax }}{1}{figure.caption.1}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {0.2}Your questions from last class}{1}{subsection.0.2}} | ||
\newlabel{your-questions-from-last-class}{{0.2}{1}{Your questions from last class}{subsection.0.2}{}} | ||
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces q2\relax }}{2}{figure.caption.2}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {0.3}Condition of a matrix}{2}{subsection.0.3}} | ||
\newlabel{condition-of-a-matrix}{{0.3}{2}{Condition of a matrix}{subsection.0.3}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {0.3.1}\emph {just checked in to see what condition my condition was in}}{2}{subsubsection.0.3.1}} | ||
\newlabel{just-checked-in-to-see-what-condition-my-condition-was-in}{{0.3.1}{2}{\texorpdfstring {\emph {just checked in to see what condition my condition was in}}{just checked in to see what condition my condition was in}}{subsubsection.0.3.1}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {0.3.2}Matrix norms}{2}{subsubsection.0.3.2}} | ||
\newlabel{matrix-norms}{{0.3.2}{2}{Matrix norms}{subsubsection.0.3.2}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {0.3.3}Condition of Matrix}{3}{subsubsection.0.3.3}} | ||
\newlabel{condition-of-matrix}{{0.3.3}{3}{Condition of Matrix}{subsubsection.0.3.3}{}} | ||
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces Springs-masses\relax }}{5}{figure.caption.3}} | ||
\@writefile{toc}{\contentsline {section}{\numberline {1}Iterative Methods}{6}{section.1}} | ||
\newlabel{iterative-methods}{{1}{6}{Iterative Methods}{section.1}{}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}Gauss-Seidel method}{6}{subsection.1.1}} | ||
\newlabel{gauss-seidel-method}{{1.1}{6}{Gauss-Seidel method}{subsection.1.1}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.1.1}Gauss-Seidel Iterative approach}{7}{subsubsection.1.1.1}} | ||
\newlabel{gauss-seidel-iterative-approach}{{1.1.1}{7}{Gauss-Seidel Iterative approach}{subsubsection.1.1.1}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.1.2}Jacobi method}{7}{subsubsection.1.1.2}} | ||
\newlabel{jacobi-method}{{1.1.2}{7}{Jacobi method}{subsubsection.1.1.2}{}} | ||
\gdef \LT@i {\LT@entry | ||
{1}{52.97838pt}\LT@entry | ||
{1}{181.1121pt}\LT@entry | ||
{1}{35.4892pt}\LT@entry | ||
{1}{179.80707pt}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.2}Gauss-Seidel with Relaxation}{11}{subsection.1.2}} | ||
\newlabel{gauss-seidel-with-relaxation}{{1.2}{11}{Gauss-Seidel with Relaxation}{subsection.1.2}{}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.3}Nonlinear Systems}{13}{subsection.1.3}} | ||
\newlabel{nonlinear-systems}{{1.3}{13}{Nonlinear Systems}{subsection.1.3}{}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.4}Newton-Raphson part II}{14}{subsection.1.4}} | ||
\newlabel{newton-raphson-part-ii}{{1.4}{14}{Newton-Raphson part II}{subsection.1.4}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.4.1}Solution is again in the form Ax=b}{15}{subsubsection.1.4.1}} | ||
\newlabel{solution-is-again-in-the-form-axb}{{1.4.1}{15}{Solution is again in the form Ax=b}{subsubsection.1.4.1}{}} | ||
\@writefile{toc}{\contentsline {subsection}{\numberline {1.5}Example of Jacobian calculation}{15}{subsection.1.5}} | ||
\newlabel{example-of-jacobian-calculation}{{1.5}{15}{Example of Jacobian calculation}{subsection.1.5}{}} | ||
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.1}Nonlinear springs supporting two masses in series}{15}{subsubsection.1.5.1}} | ||
\newlabel{nonlinear-springs-supporting-two-masses-in-series}{{1.5.1}{15}{Nonlinear springs supporting two masses in series}{subsubsection.1.5.1}{}} |
No changes.

Oops, something went wrong.