Question 5
Contents
5(a) - First order system
The second order system for the linear oscillator
can be written as the first order system
5(b) - Explicit solution
For :
For (resonance case):
5(c) - Numerical Experiments
function q5_solution
figure; hold on; for omega=[2.5,2.9,3.1,3,sqrt(3)] [t,x] = ode23(@(t,x)oscillator(t,x,omega), [0, 50], [1, 0]); plot(t, x(:,1), 'DisplayName', ['\omega = ' num2str(omega)]); end xlabel('t'); ylabel('x'); legend('Location','SouthWest');

Modified oscillator function
Modified version of oscillator.m to allow to be passed as arg
end function y = oscillator(t, x, omega) % OSCILLATOR Right hand side for harmonic oscillator equation: % % x_1' = x_2 % x_2' = -b x_1 - a x_2 + c cos(\omega t) a = 0; b = 9; c = 10; A = [0 1; -b -a]; r = [0; c*cos(omega*t)]; y = A*x + r; end