Hello -
The following script is supposed to use the user-defined cov()
function
to initialize a matrix which is later solved. For some reason, the
global variable position is either not visible or disappears this
function. What am I doing wrong?
Thanks,
- Olumide
############################### SCRIPT ###############################
debug_on_warning(1);
debug_on_error(1);
clear height;
clear sigma;
clear position;
clear B;
position = [ 0,0,0; 256,0,0; 0,256,0; 256,256,0; 128,128,5 ];
#position = [ 0,0,0; 0,128,0; 256,128,0; 256,0,0; 0,256,0; 256,256,0;
128,128,5 ];
zeroMatrix = [ 0,0,0; 0,0,0; 0,0,0 ];
zeroVec = [ 0; 0; 0];
dim = size(position)(1);
################### Subroutines ###################
function dist = r( i , x , y )
global position;
dist = sqrt( ( x - position(i,1) )^2 + ( y - position(i,2) )^2 );
endfunction
function c = covariance( i, x, y )
rad = r( i, x, y );
c = rad^2 * log10(rad);
endfunction
function c = cov( i, j )
if(i == j)
c = 0;
else
rad = r( j, position(i,1), position(i,2) );
c = rad^2 * log10(rad);
endif
endfunction
################### Construct & solve Matrix ###################
for i = 1:dim
B(i, 1) = 1;
B(i, 2) = position(i,1);
B(i, 3) = position(i,2);
height(i,1) = position(i,3);
for j = 1:i
sigma(i,j) = sigma(j,i) = cov(i,j);
endfor
endfor
M = [[sigma, B];[B',zeroMatrix]];
I = [height;zeroVec];
O = M\I;