This commit is contained in:
LinlyBoi
2023-05-07 15:19:34 +03:00
parent 1060ad7f8a
commit b5b05e13ce
3 changed files with 71 additions and 0 deletions

38
curve-fittingig.m Normal file
View File

@@ -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)

12
curvefittingig.m Normal file
View File

@@ -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");

21
differentiating-deez.m Normal file
View File

@@ -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