[Up]
Päivitetty: Tue Feb 24 13:08:33 EET 1998

Linear systems

Linear homog. systems of the form y'=A y can be solved by means of eigenvalues in case there are enough eigenvectors. If not, then the generalized eigenvectos are needed.

A general way to solve such systems is to use the matrix exponential function (see ?linalg,exponential). Matlab includes a numerical implementation of it under the name expm .

In our matlab-directory we have a code, linsys.m for solving any linear constant coefficient homog. system using expm.

Give the command (in UNIX) (but be careful not to loose something useful you might already have):
cp /p/edu/mat-1.192/matlab/startup.m ~/matlab/ or just

>> path(path,'/p/edu/mat-1.192/matlab/');
in your Matlab-session. Then this code will be available to you
function [t,y] = linsys(A,x0,T,siz)
% Input: Matriisi A, alkuarvovektori x0, loppuaika T (aikaväli: 0 .. T)
% Valinnainen siz: kuinka moneen osaan aikaväli jaetaan, oletus 100.
%
% Output: t - vektori:  diskretoitu aika-akseli (oletus 100-pituinen)
%         y - matriisi: 100 x n, kukin sarake edustaa ratkaisufunktion
%                       arvoja t-aikapisteissä.
% 
% Esim: A=[1 0 0;1 3 0;0 1 1];x0=[1;2;3];
%       [t,y]=linsys(A,x0,2);
%       plot(t,y)                       % aikariippuvuusparvi (mieliv. n)
%       plot(y(:,1),y(:,2))             % faasitaso (1,2)  
%       plot3(y(:,1),y(:,2),y(:,3))     % faasiavaruus (3-d)
%       plot(y(:,i),y(:,j))             % projektio (i,j)-faasitasossa
%                                       % (jos n > 2)
if nargin < 4, siz = 100; end; 
t = linspace(0,T,siz);
m=size(A);m=m(1);
y = zeros(m,siz);
for i=1:siz,
y(:,i) = expm(A * t(i)) * x0;
end;
y=y';      % Transponoidaan y-matriisi,jotta yhdenmukainen ode-funkt. kanssa


This page created by < Heikki.Apiola@hut.fi>