You are on page 1of 1

//Program to plot Damped Harmonic Oscillator

//Developed by ANURAG PRIYADARSHI //Roll No. 1117


clc
clf
clear
c = -2
for (i = 1:3)
function
dz=f(t, z);
dz(1) = m*z(2);
dz(2) = -k*z(1)-c*z(2);
endfunction
m = 1; k = 4; c = c+3;
t0 = 0; z(1) = 0; z(2) = 1;
t = 0:0.1:10
sol = ode([z(1);z(2)],t0,t,f)
plot2d(t,sol(1,:),c+5)
xlabel('t Axis')
ylabel('y Axis')
end
d = gca();
d.x_location = 'origin'
d.y_location = 'origin'
hl = legend(['Overdamped';'Critically damped';'Unerdamped'])
xtitle('Plot of Damped Harmonic Oscillator')

You might also like