aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/40-eigenwerte/images/spbeispiel.m
diff options
context:
space:
mode:
authorAndreas Müller <andreas.mueller@othello.ch>2021-01-18 21:01:26 +0100
committerAndreas Müller <andreas.mueller@othello.ch>2021-01-18 21:01:26 +0100
commit812a80acf52275699afb285db46aa76be03006c2 (patch)
treed603bf9c54cd29909551d1cb7f5fd7b66c64ca4e /buch/chapters/40-eigenwerte/images/spbeispiel.m
parentneue Sachen zur linearen Algebra (diff)
downloadSeminarMatrizen-812a80acf52275699afb285db46aa76be03006c2.tar.gz
SeminarMatrizen-812a80acf52275699afb285db46aa76be03006c2.zip
add more stuff about spectral radius
Diffstat (limited to '')
-rw-r--r--buch/chapters/40-eigenwerte/images/spbeispiel.m51
1 files changed, 51 insertions, 0 deletions
diff --git a/buch/chapters/40-eigenwerte/images/spbeispiel.m b/buch/chapters/40-eigenwerte/images/spbeispiel.m
new file mode 100644
index 0000000..81160b9
--- /dev/null
+++ b/buch/chapters/40-eigenwerte/images/spbeispiel.m
@@ -0,0 +1,51 @@
+#
+# spbeispiel.m
+#
+# (c) 2020 Prof Dr Andreas Müller, Hochschule Rapperswil
+#
+N = 30
+R = 0.05 * rand(N,N);
+R = R + R';
+A = eye(N) + R;
+L = tril(A,-1)
+U = tril(A',-1)'
+D = diag(diag(A))
+
+A
+
+function r = spektralradius(A)
+ r = max(abs(eig(A)));
+end
+
+gaussseidel = spektralradius(inverse(L+D)*U)
+jacobi = spektralradius(inverse(D)*(L+U))
+richardson = spektralradius(A - eye(N))
+
+fd = fopen("sppaths.tex", "w");
+
+fprintf(fd, "\\def\\richardson{\n")
+tau = 0.1;
+r = spektralradius((1/tau) * A - eye(N))
+fprintf(fd, "\\draw[line width=1.4pt,color=red] ({\\sx*0.1},{\\sy*%.5f})", r);
+for tau = (11:300) / 100
+ r = spektralradius((1/tau) * A - eye(N));
+ fprintf(fd, "\n--({\\sx*%.5f},{\\sy*%.5f})", tau, r);
+end
+fprintf(fd, "\n;}\n");
+
+fprintf(fd, "\\def\\sor{\n");
+omega = 1/100
+B = (1/omega) * D + L;
+C = (1-1/omega) * D + U;
+r = spektralradius(inverse(B) * C)
+fprintf(fd, "\\draw[line width=1.4pt,color=red] ({\\sx*%.3f},{\\sy*%.3f})", omega, r);
+for omega = (2:200) / 100
+ B = (1/omega) * D + L;
+ C = (1-1/omega) * D + U;
+ r = spektralradius(inverse(B) * C);
+ fprintf(fd, "\n--({\\sx*%.5f},{\\sy*%.5f})", omega, r);
+end
+fprintf(fd, ";\n}\n");
+
+fclose(fd);
+