47 lines
1.1 KiB
Matlab

% Parameters
m = 0.75;
L = 1.25;
c = 0.15;
g = 9.81;
A0 = 4;
omega = 2;
% Time span
tspan = [0 20];
dt = 1e-3;
t_eval = 0:dt:20;
% ODE Function
odefun = @(t, x) [
x(2);
(1/(m*L^2)) * (A0*sin(omega*t) - c*x(2) - m*g*L*x(1))
];
x0 = [0; 0]; % Initial conditions
[t, x] = ode45(odefun, t_eval, x0); % Solve
% Plots
figure('Name', 'System responce', 'Position', [100, 100, 1280, 860]);
subplot(2,1,1);
plot(t, x(:,1)); ylabel('q(t) [rad]'); grid on; title('Γωνία');
subplot(2,1,2);
plot(t, x(:,2), 'r'); ylabel('dq(t) [rad/s]'); xlabel('t [sec]'); grid on; title('Γωνιακή Ταχύτητα');
saveas(gcf, 'Prob1_responce_20s.png');
% Time span
tspan = [0 90];
t_eval = 0:dt:90;
x0 = [0; 0]; % Initial conditions
[t, x] = ode45(odefun, t_eval, x0); % Solve
% Plots
figure('Name', 'System responce', 'Position', [100, 100, 1280, 860]);
subplot(2,1,1);
plot(t, x(:,1)); ylabel('q(t) [rad]'); grid on; title('Γωνία');
subplot(2,1,2);
plot(t, x(:,2), 'r'); ylabel('dq(t) [rad/s]'); xlabel('t [sec]'); grid on; title('Γωνιακή Ταχύτητα');
saveas(gcf, 'Prob1_responce_90s.png');