This is the first of several lab assignments whose overall g
Solution
%%% MATLAB Code
 clc
 clear all
 t = 0:0.01:1;
 %% Analytical
 theta1 = sin(pi.*t);
 theta1_dot = pi*cos(pi.*t);
 theta1_ddot = -pi^2*sin(pi.*t);
%% Numerical
 theta1_num_dot = zeros(101);
 theta1_num_ddot = zeros(101);
 theta1_num_dot(1) = (theta1(2)-theta1(1))/0.01;
for i = 2:100
 theta1_num_dot(i) = (theta1(i+1)-theta1(i-1))/(2*0.01);
 end
theta1_num_ddot(1) = (theta1(3)-2*theta1(2)+theta1(1))/(0.01^2);
for i = 2:100
 theta1_num_ddot(i) = (theta1(i+1)-2*theta1(i)+theta1(i-1))/(0.01^2);
 end
%plot(t,theta1,t,theta1_dot,t,theta1_ddot,t,theta1_num_dot,t,theta1_num_ddot);
%% Numerical noise
 temp = 0.001*randn(1,size(t,2));
 for j = 1:101
 theta1_noise(j) = theta1(j) + temp(j);
 end
 theta1n_num_dot = zeros(101);
 theta1n_num_ddot = zeros(101);
 theta1n_num_dot(1) = (theta1_noise(2)-theta1_noise(1))/0.01;
for i = 2:100
 theta1n_num_dot(i) = (theta1_noise(i+1)-theta1_noise(i-1))/(2*0.01);
 end
theta1n_num_ddot(1) = (theta1_noise(3)-2*theta1_noise(2)+theta1_noise(1))/(0.01^2);
for i = 2:100
 theta1n_num_ddot(i) = (theta1_noise(i+1)-2*theta1_noise(i)+theta1_noise(i-1))/(0.01^2);
  end
figure (1)
 plot(t,theta1,t,theta1_noise,\'linewidth\',2);
 title(\'Angular displacement\')
 xlabel(\'time (sec)\')
 ylabel(\'Angular displacement (rad)\')
 grid on
figure (2)
 plot(t,theta1_dot,t,theta1_num_dot,t,theta1n_num_dot,\'linewidth\',2);
  title(\'Angular velocity\')
 xlabel(\'time (sec)\')
 ylabel(\'Angular velocity (rad/sec)\')
 grid on
figure (3)
 plot(t,theta1_ddot,t,theta1_num_ddot,t,theta1n_num_ddot,\'linewidth\',2);
  title(\'Angular acceleration\')
 xlabel(\'time (sec)\')
 ylabel(\'Angular acceleration (rad/sec^2)\')
 grid on


