* number of breakeven points set POINTS /1*4/; *values to check for the maximum error set xxx /1*4/; parameter data_int(xxx); data_int('1') = -11.3199; data_int('2') = -10.3699; data_int('3') = -9.4199; data_int('4') = -8.4697; display data_int; *upper e lower bound parameter LB, UB; variables x(POINTS) y(POINTS) delta_x(POINTS) delta_y(POINTS) m(POINTS) OFval f_lin(XXX,POINTS) f_lin_max(XXX) max_err(XXX) ; equations xval(POINTS) fval(POINTS) e_delta_x(POINTS) e_delta_y(POINTS) e_m(POINTS) e_worst_point(POINTS,PPP) e_f_lin(XXX,POINTS) e_f_lin_max(XXX,POINTS) e_max_err(XXX) e_var_x_up(POINTS) e_var_x_lo(POINTS) e_obj ; LB = -11.3199; UB = -8.4697; fval(POINTS).. y(POINTS) =e= exp(x(POINTS)); e_delta_x(POINTS)$[ord(POINTS) ne card(POINTS)].. delta_x(POINTS) =e= x(POINTS+1) - x(POINTS); e_delta_y(POINTS)$[ord(POINTS) ne card(POINTS)].. delta_y(POINTS) =e= y(POINTS+1) - y(POINTS); e_m(POINTS)$[ord(POINTS) ne card(POINTS)].. m(POINTS) =e= delta_y(POINTS) / delta_x(POINTS); delta_x.l(POINTS) = 1; e_f_lin(XXX,POINTS)$[ord(POINTS) ne card(POINTS)].. f_lin(XXX,POINTS) =e= m(POINTS) * (data_int(XXX) - x(POINTS)) + y(POINTS); e_f_lin_max(XXX,POINTS)$[ord(POINTS) ne card(POINTS)].. f_lin_max(XXX) =g= f_lin(XXX,POINTS); f_lin_max.lo(XXX) = 0; e_max_err(XXX).. max_err(XXX) =e= (f_lin_max(XXX) - exp(data_int(XXX)))/ f_lin_max(XXX)*100; f_lin_max.l(XXX) = 1; e_var_x_up(POINTS)$[ord(POINTS) ne card(POINTS)].. x(POINTS) =l= x(POINTS+1); * force the first and last point to be LB and UB x.fx(POINTS)$(ord(POINTS) eq 1 ) = LB; x.fx(POINTS)$(ord(POINTS) eq card(POINTS) ) = UB; e_obj.. OFval =e= sum(XXX, max_err(XXX)); model approx_func / fval e_delta_x e_delta_y e_m e_f_lin e_f_lin_max e_max_err e_var_x_up e_obj / ; option limrow = 1000; option limcol = 1000; solve approx_func minimizing OFval using nlp; parameter corrado; corrado = smax(XXX, max_err.l(XXX)); display corrado;