forked from sed12008/ME3255S2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
13,331 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}{}} |
Empty file.
Oops, something went wrong.