function VHDLSpline() close all x=[50; 150; 250; 350]; y=[-1845; -456; 1277; 2047]; h0=x(2) - x(1); h1=x(3) - x(2); h2=x(4) - x(3); d0=(y(2) - y(1)) / (x(2) - x(1)); d1=(y(3) - y(2)) / (x(3) - x(2)); d2=(y(4) - y(3)) / (x(4) - x(3)); g1= 6*d1 - 6*d0; g2= 6*d2 - 6*d1; %g1=(3/h1)*(y(3)-y(2)) - (3/h0)*(y(2)-y(1)); %schlechter %g2=(3/h2)*(y(4)-y(3)) - (3/h1)*(y(3)-y(2)); %schlechter s = Gauss(h0, h1, h2, g1, g2); a=y(1); b=d1 - (h1/6)*(s(2)+(2*s(1))); c=s(1)/2; d=(s(2)-s(1))/(6*h1); %a=y(1); %schlechter %b=(1/h1)*(y(3)-y(2))-(h1/3)*(2*s(1)+s(2)); %schlechter %c=g1; %schlechter %d=(s(2)-s(1))/(3*h1); %schlechter coef=[a, b, c, d]; res = a + b*(175) + c*(175)^2 + d*(175)^3; fprintf('res=%.6e\n',res); fprintf('coef=%.6e\n',coef); end function f=Gauss(h0, h1, h2, g1, g2) lo=2*(h0+h1); ru=2*(h1+h2); lu=h1; ro=h1; mult=lo/lu; ro=ro-(mult*ru); g=g1-(mult*g2); s2=g/ro; s1=(g2-(s2*ru))/lu; f=[s1, s2]; end function f=Cramer(h0, h1, h2, g1, g2) det=(2*(h0+h1))*(2*(h1+h2)) - h1*h1; det1=g1*(2*(h1+h2)) - g2*h1; det2=(2*(h0+h1))*g2 - h1*g1; s1=det1/det; s2=det2/det; f=[s1, s2]; end