%% % Example6_7.m % % % Construct synthetic data for the 2 parameter spring model. This data is % subsequent used in Example 11.21 and Example 12.11. % clear all %% % Specify parameter and measurement variance values. % K = 22.1; C = 1.3; sigma = .1; var = sigma^2; %% % Construct and save the synthetic data. % t = 0:.01:5; error = sigma*randn(size(t)); n = length(t); factor = sqrt(K - C^2/4); denom = sqrt(4*K - C^2); f = 2*exp(-C*t/2).*cos(factor*t); obs = f + error; obs(1) = 2; % Enforce the initial condition Res = obs - f; %spring_data = [t' obs']; %save('spring_data.txt','spring_data','-ascii') %% % Plot the model response, synthetic data, and residuals. One notes in the residual % plot that the 2 sigma interval contains approximately 95% of the residuals. % figure(1) plot(t,f,'k','linewidth',2) hold on plot(t,obs,'bx','linewidth',1) plot(t,0*f,'k','linewidth',2) hold off set(gca,'Fontsize',[20]); legend('Model','Synthetic Data','Location','NorthEast') xlabel('Time (s)') ylabel('Displacement') %print -depsc fig3_6a figure(2) plot(t,Res,'bx',t,0*f,'k','linewidth',2) hold on plot(t,2*sigma*ones(size(t)),'--r',t,-2*sigma*ones(size(t)),'--r','linewidth',3) hold off set(gca,'Fontsize',[20]); xlabel('Time (s)') ylabel('Residuals') %print -depsc fig3_6b