I am trying to approximate some numerically derived functions using minimax polynomials, but would like to minimize relative error. An example (for rational approximations, anyway) is in the paper
Filip, Nakatsukasa, Trefethen and Beckermann,
Rational minimax
approximation via adaptive barycentric representations,
SIAM J. Sci. Comp., at the bottom of page A2433 and Fig. 7.3 on page A2447.
In minimax.m, in the exchange() function I changed the err_handle function:
%=========== Modified for relative error fitting=======================
err_handle = @(x) (fHandle(x) - feval(p, x))./fHandle(x);
%err_handle = @(x) fHandle(x) - feval(p, x); % original
%======================================================================
and a similar change to err_handle in findExtrema(), although this seems to have no effect.
Tmin=400;
Tmax=647.096;
nn=20;
nd=0;
f = chebfun(@(T) p_T(T),[Tmin,Tmax]);
[g,err] = minimax(f,nn);
[gr,errr] = minimax_rel(f,nn);
%semilogy((f-g)/f,'m'); % relative error
function p = p_T(T)
PCRIT=22.064;
TCRIT=647.096;
len=length(T);
p = zeros(len,1);
for i = 1:len
tau = 1.0 - T(i)/TCRIT;
p(i) = PCRIT * exp( TCRIT / T(i) * ...
(-7.85951783 * tau + 1.84408259 * tau^1.5 - 11.7866497 * tau^3 ...
+ 22.6807411 * tau^3.5 - 15.9618719 * tau^4 + 1.80122502 *tau^7.5));
end
end
where minimax_rel(f,nn) has the modified error function.
(This function gives the saturation pressure of water as a function of temperature. It is smooth and monotonically increasing.)
The error f - g plot for the standard minimax is:

The error plot f - gr is:

So it's trying to approximate with a relative error, but the relative error plot (f - gr)/f is:

But it doesn't get to equi-oscillation. It also does not converge. Here are the numbers for the first 10 iterations:
It. Max(|Error|) |ErrorRef| Delta ErrorRef Delta Ref m n
0 9.6834e-05 2.4796e-05 5.2351e-07 2.1622e+00 20 0
1 9.7825e-05 2.5128e-05 5.2829e-07 1.1274e-01 20 0
2 9.7825e-05 2.5130e-05 5.2828e-07 1.1851e-03 20 0
3 6.9977e-05 2.5130e-05 3.2591e-07 2.3527e-05 20 0
4 6.9977e-05 2.5130e-05 3.2591e-07 4.4321e-08 20 0
5 6.9977e-05 2.5130e-05 3.2591e-07 5.1080e-09 20 0
6 6.9977e-05 2.5130e-05 3.2591e-07 6.0133e-09 20 0
7 6.9977e-05 2.5130e-05 3.2591e-07 2.6183e-09 20 0
8 6.9977e-05 2.5130e-05 3.2591e-07 4.8044e-09 20 0
9 6.9977e-05 2.5130e-05 3.2591e-07 3.1897e-09 20 0
10 6.9977e-05 2.5130e-05 3.2591e-07 4.9233e-09 20 0
I'm afraid I'm just a beginner at Matlab and am stumped at this point. Does anyone have any ideas how to get an approximation based on relative error?
Thanks very much,
Tim