about summary refs log tree commit diff
path: root/usth/MATH2.2/labwork/1
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-02-16 14:26:55 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-02-16 14:26:55 +0700
commit82e6cf7d1046d6cee16f7e8b044ec33e7ec6c4b7 (patch)
treef7b7ae0bce69070c47a1b31a85bd2bc69dfecf09 /usth/MATH2.2/labwork/1
parent29d1001e2e21eff289bff23412e284c8b2e44595 (diff)
downloadcp-82e6cf7d1046d6cee16f7e8b044ec33e7ec6c4b7.tar.gz
[usth] Numerical Method is MATH2.4
Diffstat (limited to 'usth/MATH2.2/labwork/1')
-rw-r--r--usth/MATH2.2/labwork/1/bisect.m36
-rwxr-xr-xusth/MATH2.2/labwork/1/intro62
-rw-r--r--usth/MATH2.2/labwork/1/labwork1.pdfbin165522 -> 0 bytes
-rw-r--r--usth/MATH2.2/labwork/1/ratpoison.m15
-rw-r--r--usth/MATH2.2/labwork/1/ratpoison.py8
5 files changed, 0 insertions, 121 deletions
diff --git a/usth/MATH2.2/labwork/1/bisect.m b/usth/MATH2.2/labwork/1/bisect.m
deleted file mode 100644
index 1d9e99f..0000000
--- a/usth/MATH2.2/labwork/1/bisect.m
+++ /dev/null
@@ -1,36 +0,0 @@
-function [x fx ea iter] = bisect (f, xl, xu, es = 0.0001, maxit = 50)
-  % uses bisection method to find the root of f,
-  % with xl and xu being lower and upper guesses,
-  % es being desired relative error
-  % and maxit being maximum allowable iterations
-  % to return the real root x, fx = f(x),
-  % approximate relative error ea (%)
-  % and number of iterations iter
-  nargin < 3 && error ('bisect requires at least 3 arguments');
-  [fl fu iter] = deal (f (xl), f (xu), 0);
-  if (fl == 0)
-    [x fx ea] = deal (xl, 0, 0);
-    return;
-  elseif (fu == 0)
-    [x fx ea] = deal (xu, 0, 0);
-    return;
-  end
-  fl * fu < 0 || error ('no sign change');
-
-  [x ea] = deal (xl, 100);
-  while (ea > es && iter++ < maxit) % yes, I use Octave only
-    [xold x] = deal (x, (xl + xu) / 2);
-    fx = f (x);
-    if (fx == 0)
-      ea = 0;
-      break;
-    elseif (x)
-      ea = abs ((x - xold) / x) * 100;
-    end
-    if (f (xl) * fx < 0)
-      xu = x;
-    else
-      xl = x;
-    end
-  end
-end
diff --git a/usth/MATH2.2/labwork/1/intro b/usth/MATH2.2/labwork/1/intro
deleted file mode 100755
index 555f874..0000000
--- a/usth/MATH2.2/labwork/1/intro
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env octave
-% Exercise I.1.1
-x = 1 : 5
-printf ("x (3) + x (2) = %f\n", x (3) + x (2));
-
-% Exercise I.1.2
-x = x'
-
-% Exercise I.2.1
-A = zeros (3, 3)
-A += eye (3)
-A += [0 0 0; 2 0 0; 3 4 0]
-B = A'
-A + B
-A - B
-A * B  % matmul
-A .* B % element-wise mul
-A(1:2, 1:2)
-A(1:3)
-A(1:3, 1) % col
-A(:, 1) % col
-
-% Exercise I.3
-function avg = mean (v)
-  avg = sum (v) / numel (v);
-end
-mean (x)
-
-% Exercise I.4
-function price = ebill (kwh)
-  l = [50 50 100 100 100 Inf];
-  p = [1.484 1.533 1.786 2.242 2.503 2.587];
-  for i = 1 : 6
-    if (kwh > l(i))
-      kwh -= l(i);
-    else
-      l(i) = kwh;
-      kwh = 0;
-    end
-  end
-  price = sum (l .* p);
-end
-
-% Exercise I.5.1
-a = (@(x) x*x') (1 : 1000)
-b = sum (arrayfun (@(x) (-1)^x / (1 + x*2), [0 : 501]))
-c = sum (arrayfun (@(x) 1 / (1 + x*2)^2 / (3 + x*2)^2, [0 : 420])) - (pi^2 - 8)/16
-
-% Exercise I.5.2
-function p = permutations (n, k)
-  p = factorial (n) / factorial (n - k);
-end
-function c = combinations (n, k)
-  c = permutations (n, k) / factorial (k);
-end
-
-% Exercise I.6
-log (2) / log (1.1)
-
-% Exercise I.7
-x = linspace(-5, 5);
-plot (x, x + 1, 'color', 'green');
diff --git a/usth/MATH2.2/labwork/1/labwork1.pdf b/usth/MATH2.2/labwork/1/labwork1.pdf
deleted file mode 100644
index d8ce2d9..0000000
--- a/usth/MATH2.2/labwork/1/labwork1.pdf
+++ /dev/null
Binary files differdiff --git a/usth/MATH2.2/labwork/1/ratpoison.m b/usth/MATH2.2/labwork/1/ratpoison.m
deleted file mode 100644
index f2db823..0000000
--- a/usth/MATH2.2/labwork/1/ratpoison.m
+++ /dev/null
@@ -1,15 +0,0 @@
-function [x fx ea i] = ratpoison (f, df, x0, es = 0.00000001, imax = 20)
-  nargin < 2 && error ('ratpoison requires at least 2 ingredients');
-  [x fx dfx ea i] = deal (x0, f (x0), df (x0), 1, 0);
-  while (ea > es && i++ < imax)
-    [xold x] = deal (x, x - fx/dfx);
-    [fx dfx] = deal (f (x), df (x));
-    if (fx == 0)
-      ea = 0;
-      break;
-    elseif (x)
-      % just drop the percent BS
-      ea = abs ((x - xold) / x);
-    end
-  end
-end
diff --git a/usth/MATH2.2/labwork/1/ratpoison.py b/usth/MATH2.2/labwork/1/ratpoison.py
deleted file mode 100644
index 16aa65d..0000000
--- a/usth/MATH2.2/labwork/1/ratpoison.py
+++ /dev/null
@@ -1,8 +0,0 @@
-def ratpoison(f, df, x, es=10**-8, imax=20):
-    ea, i = 1, 0
-    while ea > es and i < imax:
-        i += 1
-        xold, x = x, x - f(x)/df(x)
-        if f(x) == 0: return x, 0, 0, i
-        if x: ea = abs((x - xold) / x)
-    return x, f(x), ea, i