
%This is a function from the solution proposal for exercise 5, which will
%be implented in exercise 6.

function [OUT1,OUT2,OUT3,OUT4]=FDGrid(IN1,IN2)
OUT1=zeros(1,IN1); %Also OUT1(1,1)=0 satisfied.
OUT2=zeros(1,IN1);
OUT3=zeros(IN1,IN1); OUT4=OUT3;

%Spatial "x" array.
for i=1:IN1-1
    OUT1(i+1)=i*IN2;
end

%Weights "w" array
OUT2(1)=IN2/2; OUT2(end)=IN2/2;
for i=2:IN1-1
    OUT2(i)=IN2;
end

%Matrix "A" for 1st spatial derivative
OUT3(1,1)=-1/IN2; OUT3(1,2)=1/IN2; OUT3(end,end-1) = -1/IN2;
OUT3(end,end) = 1/IN2;
for i=2:IN1-1
       OUT3(i,i)= -1/IN2;
       OUT3(i,i+1) = 1/IN2;
end

%Matrix "B" for 2nd spatial derivative
OUT4(1,1) = 1/(IN2^2); OUT4(1,2) = -2/(IN2^2); OUT4(1,3) = 1/(IN2^2);   
OUT4(end,end-2) = 1/(IN2^2); OUT4(end,end-1) = -2/(IN2^2);
OUT4(end,end) = 1/(IN2^2);    
for i=2:IN1-1
    OUT4(i,i-1) = 1/(IN2^2);
    OUT4(i,i) = -2/(IN2^2);
    OUT4(i,i+1) = 1/(IN2^2);
end

end
