function [u, du_da1, du_da2] = temperatures(a, r)
% Returns the temperature field in a hollow cylinder composed of two
% materials, heated from the inside, and held at a fixed temperature at the
% outside.
% The second and third optional output returns the partial derivative of the 
% temperature vector with respect to the two heat conduction parameters 
% 
% Input:
% a:      2-vector with heat conduction parameter. First and second component indicates the 
%         inner and outer material
% r:      The radial position in which the temperature is evaluated
%
% Output:
% u:      The temperature at radial position r 
% du_da1: The partial derivative of u with respect to the first component of a (optional output)
% du_da2: The partial derivative of u with respect to the second component of a (optional output)
%
% Martin Berggren, september 2004
%
[RR, g]= param; 
%
rc = RR(1); 
r12 = RR(2);
R = RR(3);
if r >= r12
    u = g*log(R/r)/a(2);
else
    u = g*(log(r12/r)/a(1) + log(R/r12)/a(2));
end
if nargout > 1  % In case derivatives are required
    if r >= r12
        du_da2 = -g*log(R/r)/(a(2)*a(2));
        du_da1 = 0;
    else
        du_da1 = -g*log(r12/r)/(a(1)*a(1));
        du_da2 = -g*log(R/r12)/(a(2)*a(2));
    end
end