Home > wafo > markov > mktestmat.m

# mktestmat

## PURPOSE

Makes test matrices for min-max (and max-min) matrices.

## SYNOPSIS

[F,Fh] = mktestmat(param,x0,s,lam,NOsubzero)

## DESCRIPTION

``` MKTESTMAT   Makes test matrices for min-max (and max-min) matrices.

CALL: [F,Fh] = mktestmat(param,x0,s,lam,NOsubzero)

Input:
param  = Parameter vector, [a b n], defines discretization.
x0     = Center of ellipse. [min Max]             [1x2]
s      = Standard deviation. (0<s<infinity)       [1x1]
lam    = Orientation of ellipse. (0<lam<infinity) [1x1]
lam=1 gives circles.
NOsubzero = Number of subdiagonals that are set to zero
(-Inf: no subdiagonals that are set to zero)
(Optional, Default = 0, only the diagonal is zero)

Output:
F      = min-max matrix.                          [nxn]
Fh     = max-min matrix.                          [nxn]

Makes a Normal kernel (Iso-lines are ellipses).
Each element in F =(F(i,j)) is
F(i,j) = exp(-1/2*(x-x0)*inv(S)*(x-x0)');
where
S = 1/2*s^2*[lam^2+1 lam^2-1; lam^2-1 lam^2+1]

The matrix Fh is obtained by assuming a time-reversible process.
These matrices can be used for testing.

Example:
[F,Fh] = mktestmat([-1 1 32],[-0.2 0.2], 0.25,1/2);
u=levels([-1 1 32]); cmatplot(u,u,F,3), axis('square')
[F,Fh] = mktestmat([-1 1 32],[-0.2 0.2], 0.25,1/2,-Inf);```

## CROSS-REFERENCE INFORMATION

This function calls:
 levels Calculates discrete levels given the parameter matrix. error Display message and abort function. inv Matrix inverse.
This function is called by:
 Chapter4 % CHAPTER4 contains the commands used in Chapter 4 of the tutorial f_funm Calculate min-max matrix for Model-structure. itmkurs_lab2 Script to computer exercises 2 rfcdemo2 Rainflow matrix for Switching Markov Chains of Turning Points. test_cycles Quick test of the routines in module 'cycles' test_markov Quick test of the routines in module 'markov'

## SOURCE CODE

```001 function [F,Fh] = mktestmat(param,x0,s,lam,NOsubzero)
002 %MKTESTMAT   Makes test matrices for min-max (and max-min) matrices.
003 %
004 % CALL: [F,Fh] = mktestmat(param,x0,s,lam,NOsubzero)
005 %
006 % Input:
007 %   param  = Parameter vector, [a b n], defines discretization.
008 %   x0     = Center of ellipse. [min Max]             [1x2]
009 %   s      = Standard deviation. (0<s<infinity)       [1x1]
010 %   lam    = Orientation of ellipse. (0<lam<infinity) [1x1]
011 %            lam=1 gives circles.
012 %   NOsubzero = Number of subdiagonals that are set to zero
013 %               (-Inf: no subdiagonals that are set to zero)
014 %               (Optional, Default = 0, only the diagonal is zero)
015 %
016 % Output:
017 %   F      = min-max matrix.                          [nxn]
018 %   Fh     = max-min matrix.                          [nxn]
019 %
020 % Makes a Normal kernel (Iso-lines are ellipses).
021 % Each element in F =(F(i,j)) is
022 %   F(i,j) = exp(-1/2*(x-x0)*inv(S)*(x-x0)');
023 % where
024 %   S = 1/2*s^2*[lam^2+1 lam^2-1; lam^2-1 lam^2+1]
025 %
026 % The matrix Fh is obtained by assuming a time-reversible process.
027 % These matrices can be used for testing.
028 %
029 % Example:
030 %   [F,Fh] = mktestmat([-1 1 32],[-0.2 0.2], 0.25,1/2);
031 %   u=levels([-1 1 32]); cmatplot(u,u,F,3), axis('square')
032 %   [F,Fh] = mktestmat([-1 1 32],[-0.2 0.2], 0.25,1/2,-Inf);
033
034 % Tested  on Matlab  5.3
035 %
036 % History:
037 % Revised by PJ  23-Nov-1999
038 %   updated for WAFO
039 % Created by PJ (Pär Johannesson) 1997
040 %   Copyright (c) 1997 by Pär Johannesson
041 %   Toolbox: Rainflow Cycles for Switching Processes V.1.0, 2-Oct-1997
042
043
044 % Check input arguments
045
046 ni = nargin;
047 no = nargout;
048 error(nargchk(0,5,ni));
049
050 if ni<1, param = []; end
051 if ni<2, x0 = []; end
052 if ni<3, s = []; end
053 if ni<4, lam = []; end
054 if ni<5, NOsubzero=[]; end
055
056 if isempty(param), param = [-1 1 32]; end
057 if isempty(x0), x0 = [1 1]*(param(2)+param(1))/2; end
058 if isempty(s), s = (param(2)-param(1))/4; end
059 if isempty(lam), lam = 1; end
060 if isempty(NOsubzero), NOsubzero=0;end
061
062 if isinf(NOsubzero), NOsubzero=-(param(3)+1); end
063
064 u = levels(param);
065 n = param(3);
066
067 % F - min-Max matrix
068
069 F=zeros(n,n);
070 S = 1/2*s^2*[lam^2+1 lam^2-1; lam^2-1 lam^2+1];
071
072 for i = 1:min(n-1-NOsubzero,n)
073   for j=max(i+1+NOsubzero,1):n
074     x = [u(i) u(j)];
075     F(i,j) = exp(-1/2*(x-x0)*inv(S)*(x-x0)');
076   end
077 end
078
079 % Fh - Max-min matrix
080 if no>1
081   Fh = F';   % Time-reversible
082 end
083
084
085
086
087```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003