%%%This code is an example for extracting the coefficients of an approximation
%%%from the data set and plotting the corresponding relative error
%%%Authors: Islam M. Tanash, Taneli Riihonen
close all
clear all
clc

error_type='relative_error';
function_Q='p_1';
variation='approximation_emax';
N=20;
right_end_point=6;%only for relative error
[a,b]=func_extract_coef(error_type,function_Q,variation,N,right_end_point);
p=1;
x_dB = linspace(-160,20*log10(6),2001);
x_range = 10.^(x_dB/20);
qapprox=0;
for i=1:N
    qapprox=qapprox+(a(i).*exp(-(b(i)).*x_range.^2));
end
d=qapprox-(qfunc(x_range)).^p;
r=d./(qfunc(x_range)).^p;
figure,plot(x_dB,(r))
title('Approximation with Minimax Relative Error, N=20')
xlabel('x(dB)')
ylabel('Relative error, r(x)')