From f5047d4d780e996a8b8f7738c1ac7c884a07f135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Sun, 13 Mar 2022 23:26:58 +0100 Subject: new stuff about beta, test2 --- buch/chapters/040-rekursion/images/betadist.m | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 buch/chapters/040-rekursion/images/betadist.m (limited to 'buch/chapters/040-rekursion/images/betadist.m') diff --git a/buch/chapters/040-rekursion/images/betadist.m b/buch/chapters/040-rekursion/images/betadist.m new file mode 100644 index 0000000..5b466a6 --- /dev/null +++ b/buch/chapters/040-rekursion/images/betadist.m @@ -0,0 +1,58 @@ +# +# betadist.m +# +# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule +# +global N; +N = 201; +global nmin; +global nmax; +nmin = -4; +nmax = 7; +n = nmax - nmin + 1 +A = 3; + +t = (nmin:nmax) / nmax; +alpha = 1 + A * t .* abs(t) +#alpha(1) = 0.01; + +#alpha = [ 1, 1.03, 1.05, 1.1, 1.25, 1.5, 2, 2.5, 3, 4, 5 ]; +beta = alpha; +names = [ "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; + "nine"; "ten"; "eleven"; "twelve" ] + +function retval = Beta(a, b, x) + retval = x^(a-1) * (1-x)^(b-1) / beta(a, b); + if (retval > 100) + retval = 100 + end +end + +function plotbeta(fn, a, b, name) + global N; + fprintf(fn, "\\def\\beta%s{\n", strtrim(name)); + fprintf(fn, "\t({%.4f*\\dx},{%.4f*\\dy})", 0, Beta(a, b, 0)); + for x = (1:N-1)/(N-1) + X = (1-cos(pi * x))/2; + fprintf(fn, "\n\t--({%.4f*\\dx},{%.4f*\\dy})", + X, Beta(a, b, X)); + end + fprintf(fn, "\n}\n"); +end + +fn = fopen("betapaths.tex", "w"); + +for i = (1:n) + fprintf(fn, "\\def\\alpha%s{%f}\n", strtrim(names(i,:)), alpha(i)); + fprintf(fn, "\\def\\beta%s{%f}\n", strtrim(names(i,:)), beta(i)); +end + +for i = (1:n) + for j = (1:n) + printf("working on %d,%d:\n", i, j); + plotbeta(fn, alpha(i), beta(j), + char(['a' + i - 1, 'a' + j - 1])); + end +end + +fclose(fn); -- cgit v1.2.1