clear; set(0,'defaultaxesfontsize',14);format long
%%% sine map, with and without model noise
%%% based on Ex 2.3 in: Law, Stuart, Zygalakis (2015), "Data Assimilation"


N=10000;% number of steps
alpha=2.5;% dynamics determined by alpha
sigma=0.25;% model noise variance is sigma^2
sd=1;rng(sd);% choose random number seed
x=zeros(N+1,1);  xnoise=zeros(N+1,1);% preallocate space
x(1)=0.1;xnoise(1)=1;% initial conditions

for i=1:N
    x(i+1)=alpha*sin(x(i));
    xnoise(i+1)=alpha*sin(xnoise(i))+sigma*randn;
end

figure(1), plot([0:1:N],x); xlim([0,100]); ylim([0, 3]); title('w/o noise')
figure(2), plot([0:1:N],xnoise); xlim([0,100]); ylim([0, 3]); title('with noise')
figure(3), plot([0:1:N],xnoise); title('with noise (long-time behaviour)')



