for i = 1:maxgen
    k1 = find(urisk<=optx(i),1,"first");
    if isempty(k1)
        k1 = 2000;
    elseif k1==1
        k1=2;
    end
    k2 = k1-1;
    r = umeans(k1) + (umeans(k2)-umeans(k1))*(optx(i)-urisk(k1))/...
        (urisk(k2)-urisk(k1));
    k1 = find(umeans<=opty(i),1,"first");
    if isempty(k1)
        k1 = 2000;
    elseif k1==1
        k1=2;
    end
    k2 = k1-1;
    v = urisk(k1) + (urisk(k2)-urisk(k1))*(opty(i)-umeans(k1))/...
        (umeans(k2)-umeans(k1));
    err(i) = min(abs((opty(i)-r)/r*100),abs((optx(i)-v)/v*100));
end
mean(err)
median(err)