clear all, clc;

%%
%Beispiel 1:
%u''+u=0, I=[0,pi]
%u(0)=0, u'(pi)=-1
%Lösung: u(t)=sin(t)
f=@(t) zeros(length(t),1);
p=@(t) -ones(length(t),1);
q=@(t) zeros(length(t),1);
r=@(t) ones(length(t),1);

a=0;
b=pi;

alpha=0;
beta=-1;

err=[];

for N=[10 50 100 500 1000];

    u = FDM_RB(f,p,q,r,a,b,N,alpha,beta);
    t = linspace(a,b,N+2);
    err=[err max(abs(u-sin(t')))];

end

semilogy(err,'b')

err=[];


pause

%%
%Beispiel 2:
%u''-u=0, I=[0,1]
%u(0)=1, u'(1)=-1/exp(1)
%Lösung: u(t)=exp(-t)
f=@(t) zeros(length(t),1);
p=@(t) -ones(length(t),1);
q=@(t) ones(length(t),1);
r=@(t) zeros(length(t),1);

a=0;
b=1;

alpha=1;
beta=-1/exp(1);

err=[];

for N=[10 50 100 500 1000];

    u = FDM_RB(f,p,q,r,a,b,N,alpha,beta);
    t = linspace(a,b,N+2);
    err=[err max(abs(u-exp(-t')))];

end

semilogy(err,'b')

err=[];