Page 53 - Computational Colour Science Using MATLAB
P. 53
40 COMPUTING CIE TRISTIMULUS VALUES
dim = size(p);
if (dim(1) == 1) | (dim(2) == 1)
p = p(:)’; % force to be a row matrix
else
disp(’p must be a row matrix’);
return;
end
N = length(p);
for i=1:N-1
if (i==1)
index1 = i;
index2 = 1.5;
elseif (i==N-1)
index1 = i-2;
index2 = 3.5;
else
index1 = i-1;
index2 = 2.5;
end
tempy = p(index1:index1+3);
tempx = [1 2 3 4];
tempx = tempx(:);
tempy = tempy(:);
% Construct Vandermonde matrix.
V(:,3+1) = ones(length(tempx),1);
for j = 3:-1:1
V(:,j) = tempx.*V(:,j+1);
end
% Solve least squares problem
g = V\tempy;
r = tempy - V*g;
temp(i) = g(4) + g(3)*index2 + g(2)*index2*index2 +
g(1)*index2*index2*index2;
end
for i=1:N-1
s(i*2 - 1) = p(i);