clc;
close all;
clear all;
size=5;
h=1/size;
element=zeros(size+1,3);
fterm=zeros(size+1,1);
for i=1:1:size
% element(i,i)=element(i,i)+1/h+h/3;
% element(i,i+1)=-1/h+h/6;
% element(i+1,i)=-1/h+h/6;
% element(i+1,i+1)=1/h+h/3;
element(i,i)=element(i,i)+1/h;
element(i,i+1)=-1/h;
element(i+1,i)=-1/h;
element(i+1,i+1)=1/h;
x1=(i-1)*h;
x2=i*h;
% fterm(i,1)=fterm(i,1)+(-2*pi*(x1-x2)*cos(2*pi*x1)+sin(2*pi*x1)-sin(2*pi*x2))/(h*pi);
% fterm(i+1,1)=(2*pi*(x1-x2)*cos(2*pi*x2)-sin(2*pi*x1)+sin(2*pi*x2))/(h*pi);
syms x
fterm(i,1)=fterm(i,1)+int(4*pi*pi*sin(2*pi*x)*(x2-x)/h,x,x1,x2);
fterm(i+1,1)=int(4*pi*pi*sin(2*pi*x)*(x-x1)/h,x,x1,x2);
% fterm(i,1)=(-2*x2*cos(2*pi*x2))/h+(2*x2*cos(2*pi*x2))/h-sin(2*pi*x2)/(h*pi)...
% -((-2*x2*cos(2*pi*x1))/h+(2*x1*cos(2*pi*x1))/h-sin(2*pi*x1)/(h*pi));
% fterm(i+1,1)=4*cos(2*pi*x2)-6*x2*cos(2*pi*x2)+(3*sin(2*pi*x2))/pi...
% -(4*cos(2*pi*x1)-6*x1*cos(2*pi*x1)+(3*sin(2*pi*x1))/pi);
end
copy1=element;
copy2=fterm;
element(1,1)=1;
element(1,2)=0;
element(size+1,size)=0;
element(size+1,size+1)=1;
fterm(1,1)=0;
fterm(size+1,1)=0;
% fterm(2,1)=1.82699+0.653987;
% fterm(3,1)=-0.653987-1.82699;
element
fterm
ansmatrix=inv(element)*fterm
%ansmatrix=element\fterm
% for i=1:1:size
% x1=(i-1)*h;
% x2=i*h;
%
% H1=@(x) (x2-x)/h;
% H2=@(x) (x-x1)/h;
%
% u=@(x) H1(x)*ansmatrix(i,1)+H2(x)*ansmatrix(i+1,1);
% end
x=linspace(0,1,size+1);
y=sin(2*pi*x);
figure
plot(x,ansmatrix)
hold on
plot(x,y,'r')
% copy1*ansmatrix
% copy2(1,1)