From 638d4bf030ad6e29555bab7e3d45fbc7d11abad0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Tue, 27 Sep 2022 10:03:10 +0200 Subject: [PATCH] push --- diff.asv | 55 ------------------------------------------------------- diff.m | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 59 deletions(-) delete mode 100644 diff.asv diff --git a/diff.asv b/diff.asv deleted file mode 100644 index 41e56bc..0000000 --- a/diff.asv +++ /dev/null @@ -1,55 +0,0 @@ -%% Center - -D_x_center = diag(0.5*ones(5,1),1) - diag(0.5*ones(5,1),-1); -D_x_center(1,1) = 1; -D_x_center(6,6) = 1; -interval = [0:1/5:1]; -h = 1/5; -D_x_center - -f_x_1 = [1;1;1;1;1;1]; -f_x_2 = interval.'; -f_x_3 = (interval.^2).'; - -diff1 = 1/h * D_x_center * f_x_1 -diff2 = 1/h * D_x_center * f_x_2 -diff3 = 1/h * D_x_center * f_x_3 - -%% Forward - -D_x_forward = diag(ones(5,1),1) - diag(ones(6,1), 0); -D_x_forward(6,5) = -1; -D_x_forward(6,6) = 1; - -interval = [0:1/5:1]; -h = 1/5; - -f_x_1 = [1;1;1;1;1;1]; -f_x_2 = interval.'; -f_x_3 = (interval.^2).'; - -diff1 = 1/h * D_x_forward * f_x_1 -diff2 = 1/h * D_x_forward * f_x_2 -diff3 = 1/h * D_x_forward * f_x_3 - -%% Backwards - -D_x_back = D_x_forward; - -interval = [0:1/5:1]; -h = 1/5; - -f_x_1 = [1;1;1;1;1;1]; -f_x_2 = interval.'; -f_x_3 = (interval.^2).'; - -diff1 = 1/h * D_x_back * f_x_1 -diff2 = 1/h * D_x_back * f_x_2 -diff3 = 1/h * D_x_back * f_x_3 - - - -%% Bias - -bound_low = ((-3*f_x_1(1)) + (4*f_x_1(2)) - (f_x_1(3)))/(2*h) -bound_up = ((f_x_1(4)) - (4*f_x_1(5)) + (3*f_x_1(6)))/(2*h) \ No newline at end of file diff --git a/diff.m b/diff.m index 64eff1a..64e8bf7 100644 --- a/diff.m +++ b/diff.m @@ -57,19 +57,30 @@ bound_up = ((f_x_3(4)) - (4*f_x_3(5)) + (3*f_x_3(6)))/(2*h) %% EXP +N = 100; -D_x_center = diag(0.5*ones(5,1),1) - diag(0.5*ones(5,1),-1); +D_x_center = diag(0.5*ones(N,1),1) - diag(0.5*ones(N,1),-1); D_x_center(1,1) = 1; -D_x_center(6,6) = 1; +D_x_center(N+1,N+1) = 1; + +D_x_forward = diag(ones(N,1),1) - diag(ones(N+1,1), 0); +D_x_forward(N+1,N) = -1; +D_x_forward(N+1,N+1) = 1; -N = 5; interval = [0:1/N:1]; h = 1/N; - +f = zeros(length(interval), 1); f_prim = zeros(length(interval), 1); for i=1:length(interval) + f(i) = 4*exp(sin(4*interval(i))); f_prim(i) = 4*exp(sin(4*interval(i)))*cos(4*interval(i)); end + +D_x_center +interval +f + +approx = (1/h) * D_x_center * f f_prim @@ -84,3 +95,4 @@ f_prim + -- 2.30.2