function kyvadlo()
%kyvadlo / diferencialni rovnice
clear; clc;

global C C2;

m=1;
J=10;
g=9.8;
d=0.3;

C=m*g*d/J;

omega=sqrt(C);

%tlumeni kyvadla
T=0;
C2=T/J;

% pocatecni podminky
fi0=50/180*pi; % pocatecni uhel vychyleni
omega0=0; % pocatecni uhlova rychlost


%kyvadlo netlumene
options = odeset('RelTol',1e-4);
[t,y] = ode45(@kyvadlofce,[0 60],[fi0 omega0],options);

y2=fi0*exp(-C2*t).*cos(omega*t);

figure(1)
plot(t,y(:,1)*180/pi,'r')
hold on
plot(t,y2*180/pi,'b')
hold off
title('Netlumene kmity kyvadla','FontSize',13);
legend('presne reseni','linearizovane reseni');
xlabel('Cas t [s]');
ylabel('Uhlova vychylka [ ^o]');

%kyvadlo tlumene

%tlumeni kyvadla
T=0.5;
C2=T/J;


[t,y] = ode45(@kyvadlofce,[0 60],[fi0 omega0],options);


y2=fi0*exp(-C2*t).*cos(omega*t);

figure(2)
plot(t,y(:,1)*180/pi,'r')
hold on
plot(t,y2*180/pi,'b')
hold off
title('Tlumene kmity kyvadla','FontSize',13);
legend('presne reseni','linearizovane reseni');
xlabel('Cas t [s]');
ylabel('Uhlova vychylka [ ^o]');

function dy=kyvadlofce(t,y)
global C C2;
dy=[y(2); -C*sin(y(1))-C2*y(2)];


