60 likes | 338 Views
clearclose allclcformat compact A = 5; % initial amplitudeT = 1/60; % period of oscillationtau = 2*T; % attenuation envelope time constanttTotal = 8*T; % total timen = 1000; % total points dt = tTotal/(n-1); for i = 1:1:n t(i) = (i-1)*dt; a(i) = A*exp(-t(i)/tau); f(i) = a(i)*sin(2*pi*t(i)/T);end plot(t,f,'-xk', t,a,'--r', t,-a,'--r');title('Damped Oscillator');xlabel('time (s)');ylabel('amplitude');.
E N D
1. Matlab ‘for’ and ‘while’ loops This presentation should be viewed as a slideshow. Use the alt-tab key combination to switch between the slideshow and Matlab as you work through the examples.
Pay close attention to each program step and explanation. Be sure that you understand the purpose of each program instruction. It is not a typing exercise.