From b5b05e13ceb8de7ca573f99da17eb1cf856fa77b Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Sun, 7 May 2023 15:19:34 +0300 Subject: [PATCH] AAA --- curve-fittingig.m | 38 ++++++++++++++++++++++++++++++++++++++ curvefittingig.m | 12 ++++++++++++ differentiating-deez.m | 21 +++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 curve-fittingig.m create mode 100644 curvefittingig.m create mode 100644 differentiating-deez.m diff --git a/curve-fittingig.m b/curve-fittingig.m new file mode 100644 index 0000000..65df023 --- /dev/null +++ b/curve-fittingig.m @@ -0,0 +1,38 @@ +clear, clc, close all +#xf = [0:0.05:10]; +#Yf = sin (2*pi*xf/5); +#xp = [0:10]; +#Yp = sin (2*pi*xp/5); +#lin = interp1 (xp, Yp, xf); +#near = interp1 (xp, Yp, xf, "nearest"); +#pch = interp1 (xp, Yp, xf, "pchip"); +#spl = interp1 (xp, Yp, xf, "spline"); +#plot (xf,Yf,"r", xf,near,"g", xf,lin,"b", xf,pch,"c", xf,spl,"m", +# xp,Yp,"r*"); +#legend ("original", "nearest", "linear", "pchip", "spline"); +x = [0 4 8 12]; + +y = [5 3 10 13]; + +n = length(x); + +Y = log(y); + +coeff = [sum(x) n; sum(x.^2) sum(x)]; + +free = [sum(Y); sum(x.*Y)]; + +V = coeff\free # inv(coeff) * free + +A = V(1) +#exp: +a = exp(A) + +b = V(2) + +Sr = (sum(Y - a*x - b).^2) + +f = a*x + b; + +plot(x,y,'*',x,f) + diff --git a/curvefittingig.m b/curvefittingig.m new file mode 100644 index 0000000..3622cd5 --- /dev/null +++ b/curvefittingig.m @@ -0,0 +1,12 @@ +clear, clc +xf = [0:0.05:10]; +yf = sin (2*pi*xf/5); +xp = [0:10]; +yp = sin (2*pi*xp/5); +lin = interp1 (xp, yp, xf); +near = interp1 (xp, yp, xf, "nearest"); +pch = interp1 (xp, yp, xf, "pchip"); +spl = interp1 (xp, yp, xf, "spline"); +plot (xf,yf,"r", xf,near,"g", xf,lin,"b", xf,pch,"c", xf,spl,"m", + xp,yp,"r*"); +legend ("original", "nearest", "linear", "pchip", "spline"); diff --git a/differentiating-deez.m b/differentiating-deez.m new file mode 100644 index 0000000..2cfb69f --- /dev/null +++ b/differentiating-deez.m @@ -0,0 +1,21 @@ +clear,clc +pkg load symbolic +f = inline('exp(x)') +h = 0.1; +x = [1.4 1.5 1.6] +y = f(x) +first_diff_forward_y = (y(3) - y(2)) / h +first_diff_backward_y = (y(2) - y(1)) / h +first_diff_central_y = (y(3) - y(1)) / (2*h) +syms x; +Y = exp(x); +Y1 = diff(Y) +Y2 = diff(Y,2) + +YY1 = inline(Y1) +y1e = YY1(1.5) +YY2 = inline(Y2) +y2e = YY2(1.5) +M = [ first_diff_backward_y first_diff_central_y first_diff_forward_y] +RPE = (abs(y1e - M) / y1e) * 100 +