function [D,Aw]=method_3_prep(A,W)
% This function computes two arrays in preparation for
% method 3 (the object colors case), also called the
% "LHTSS" (Least Hyperbolic Tangent Slope Squared)
% method. (This code is the same as method_2_prep.)
% A is the nx3 matrix of color matching functions.
% W is an nx1 illuminant vector, scaled arbitrarily.
% D is an nxn matrix of finite differencing constants.
% Aw is an nx3 matrix of illuminant-W-referenced CMFs.
n=size(A,1);
D=full(gallery('tridiag',n,-2,4,-2));
D(1,1)=2; D(n,n)=2;
W_normalized=W/(A(:,2)'*W);
Aw=diag(W_normalized)*A;