-
Notifications
You must be signed in to change notification settings - Fork 1
/
singledrivendampedoscillator_student.m
69 lines (46 loc) · 1.61 KB
/
singledrivendampedoscillator_student.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [wd_vec,zMax]=singledrivendampedoscillator_student
%computing the dynamics of a single oscillator which is driven and damped
close all;
% paramenters
k=16; %elastic constant of spring1
m=1; %mass of first object
F0=1; %amplitude of forcing
gamma=.5; %viscous resistance
% % test of different resonance frequencies
% wr=sqrt(k/m); %approximated resonance frequency
% wm=wr-1; %a bit below the resonance frequency
% wp=wr+1; %a bit above the resonance frequency
n=200;
wd_vec=linspace(0.1,20,n);
zMax=zeros(n,1);
for i=1:n
wd=wd_vec(i);
param=[m,k,F0,wd,gamma]; %parameters of evolution on resonance
[twr,zwr]=ode45( @(t,z) rhs(t,z,param), [0 60], [0 1], param);
length=size(zwr(:,1));
final=round(0.7*length(1));
final_z=zwr(final:length(1),1);
zMax(i) = max(final_z);
end
figure;
plot(wd_vec,zMax);
% param=[m,k,F0,wp,gamma]; %parameters of evolution above resonance
% [twp,zwp]=ode45( @(t,z) rhs(t,z,param), [0 60], [0 1], param );
%
% param=[m,k,F0,wm,gamma]; %parameters of evolution below resonance
% [twm,zwm]=ode45( @(t,z) rhs(t,z,param), [0 60], [0 1], param );
%
% figure;
% plot(twm,zwm(:,1),'b',twr,zwr(:,1),'g',twp,zwp(:,1),'r');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dzdt=rhs(t,z,param) % here we write the differential equation that we want to solve
m=param(1);
k=param(2);
F0=param(3);
wd=param(4);
gamma=param(5);
dzdt_1 = z(2);
dzdt_2 = F0/m*sin(wd*t)-2*gamma*z(2)-(k/m)*z(1);
dzdt=[dzdt_1; dzdt_2];
end
end