function grxxm011
% grxxm011.m (Aufgabe 1.1)

% Oscillation equation, constant coefficients 
% m x'' + k x' + c x = f(t) , 0 < t <= T,
% 0 < m, 0 < c, 0 <= k,
% x(0)=x0,  x'(0) = v0,
% f(t) inhomogeneous (disturbed) function 

clf           % initialize graphics

T=20;
m=2;
k=4;
c=3;

% inline function and function handle
f=inline('cos(t)','t');
F=@(t,y) [y(2);-k/m*y(2)-c/m*y(1)+f(t)/m];
  %% MATLAB and OCTAVE higher then v. 3.0

x0=1;
v0=0;

tspan=[0,T];
y0=[x0;v0];
%% We use for simplicity a numerical method (see later)
opts=odeset('RelTol',1.e-6,'AbsTol',1.e-4,'MaxStep',1.0);
[t0, x0] = ode23(F,tspan,y0,opts);
plot(t0, x0,'o');
title('Analytic Solution');

%% a other variant
figure(2)
opts1=odeset('RelTol',1.e-2,'AbsTol',1.e-3,'InitialStep',0.2,'MaxStep',0.5);
ode23(@FF,tspan,y0,opts1);

% ==========================================================

function ydot1 = FF(t,y)
  global m k c;
    f = inline('cos(t)','t');
    ydot1 = [y(2) ;
        -k/m*y(2)-c/m*y(1)+f(t)/m];

% ==========================================================

