You are on page 1of 1

clc;

x=[0;pi/6;pi/4;pi/3;pi/2];
y=[0;1/2;sqrt(2)/2;sqrt(3)/2;1];
n=5;
di=1;dn=0;
for i=1;n-1
h(i+1)=x(i+1)-x(i);
end
M=zeros(n,1);
b=zeros(n,1);
A=zeros(n,1);
%pt b
b(1)=(y(2)-y(1))-h(2)-di;
for i=2:n-1
b(i)=(y(i+1)-y(i))/h(i+1)-(y(i)-y(i-1)/h(i));
end
b(n)=dn-(y(n)-y(n-1))/h(i);
%ptA
A(i,1)=h(2)/3;A(1,2)=h(2)/6;
for i =2:n-1
A(i,i)=(h(i)+h(i+1))/3;
A(i,i-1)=h(i)/6;
A(i,i+1)=h(i+1)/6;
end
A(n,n-1)=h(n)/6;A(n,n)=h(n)/3;
M=inv(A)*b;
%in ce interval se afla a
i=2:n
for j=2:n
if a>x(j);
i=(i+1);
end
end
C=y(i)/h(i+1)-h(i+1)*M(i)/6;
D=y(i+1)/h(i+1)-h(i+1)*M(i+1)/6;
S=M(I)/(6*h(i+1))*((x(i+1)-a)^3)+M(i+1)/(6*h(i+1))*((a-x(i))^3)+C*(x(i+1)-A+D*(A-
x(i))));

You might also like