
function [t,W]=mytrig(A,I,wa,h)
% mytrig - solves the initial value problem for the system of
%          ordinary differential equations w'=Aw
%   Syntax:
%           [t,W]=mytrig(A,I,wa,h)
%   Arguments:
%           A   - nxn-matris
%           I   - 1x2 matrix specifying a time interval, I=[a,b]
%           wa  - nx1 matrix specifying an initial value
%           h   - positive number, the stepsize
%   Returns:
%           t - row vector containg the time points with t(1)=a
%           W - nxlength(t) matrix containing the approximate solution
%   Description:
%           The program computes an approximate solution of the intial
%           value problem  w'=Aw, a<t<b; w(a)=wa.  Here w
%           and wa are column vectors.
%           The program returns the row vector t of time points with
%           t(1)=a and the nxlength(t) matrix W with column number i containing
%           the solution vector at time t(i).
%           The program uses the Euler forward method.
%   Examples:
%          [t,W]=mytrig([0 1; 1 0],[0,pi], [0;1], 1e-3);
%          computes half a period of sin(t)
%          plot(t,W)             plots the solution curves
%          plot(W(1, :), W(2, :))   plots the phase portrait
%

%----------------------------------------------------------------------
%
%   Date created:
%
%   Author:
%   Revised: Niklas Eriksen   2008-12-19
%------------------------------+---------------------------------------+

t = (I(1):h:I(2))';

W(:, 1) = wa;

for i = 2:length(t)
  W(:, i) = W(:, i-1) + h*A*W(:,i-1);
end



