function [resulty, resultI, resultV]=Recmodel(y121, I121, V121)
load datatra.mat
numIterations = 600;
F = zeros(numIterations, 2);

y = Data(:,3);
I = Data(:,1);
V = Data(:,2);

I(121) = I121;
V(121) = V121;
y(121) = y121;

for k = 121:2540

y_pred = sim(arx_model, iddata(y(1:k), [I(1:k), V(1:k)], 1));
yy = y_pred.OutputData;

N = 0.5;
n = 0.2;
P = 0.5;
r = 0.5;
y_d = 5.825;

F(120,:) = [3, -0.03];
u = [I V];  

F(k,:) = F(k-1,:) + (N .* (u(k-1,:) - u(k-2,:)) .* ((sum(yy(1:k))/k) - y(k) - F(k-1,:) .* (u(k-1,:) - u(k-2,:)))) / (n + norm(u(k-1,:))^2);    
u(k+1,:) = u(k,:) + (P * F(k,:) * (y_d - (sum(yy(1:k))/k))) / (r + norm(F(k,:))^2);
y(k+1) = (sum(yy(1:k))/k);

if u(k+1,1) > 190
   u(k+1,1) = 190;
elseif u(k+1,1) < 80
   u(k+1,1) = 80;
end

if u(k+1,2) > 2.75
   u(k+1,2) = 2.75;
elseif u(k+1,2) < 0.05
   u(k+1,2) = 0.05;
end

if y(k+1) > 13
    y(k+1) = 12;
elseif y(k+1) < 5.25
    y(k+1) = 5.35;
end

if abs(y(k+1)-y(k)) > 0.1
    if y(k+1) - y(k) > 0
        y(k+1) = y(k) + 0.1;
    elseif y(k+1) - y(k) < 0
        y(k+1) = y(k) - 0.1;
    end
end

I(k+1) = u(k+1,1);
V(k+1) = u(k+1,2);

end

for k = 122:133
if I(121) == 80
    if V(121) == 0.05 || 0.2
       V(k+1) = V(k)+0.05;
       V(135:end) = V(135:end)+(0.6/(133-122));
    end
    if V(121) == 0.65
       V(122:end) = V(122:end)-(0.2/(133-122));
    end
    if V(121) == 0.8 || 1.1
       V(122:end) = V(122:end)-(0.3/(133-122));
    end
    if V(121) == 0.95
       V(122:end) = V(122:end)-(0.4/(133-122));
    end
end
if I(121) == 90
    if V(121) == 0.2 || 0.35
       V(k+1) = V(k)+0.05;
       V(135:end) = V(135:end)+(0.55/(133-122));
    end
    if V(121) == 0.65 || 0.8
       V(122:end) = V(122:end)-(0.2/(133-122));
    end
    if V(121) == 1.1
       V(122:end) = V(122:end)-(0.3/(133-122));
    end
    if V(121) == 1.25 || 1.4
       V(122:end) = V(122:end)-(0.4/(133-122));
    end
end
if I(121) == 100
    if V(121) == 0.35 || 0.5
       V(k+1) = V(k)+0.05;
       V(135:end) = V(135:end)+(0.3/(133-122));
    end
    if V(121) == 0.8 || 0.95 || 1.1
       V(122:end) = V(122:end)-(0.2/(133-122));
    end
    if V(121) == 1.25
       V(122:end) = V(122:end)-(0.3/(133-122));
    end
    if V(121) == 1.4
       V(122:end) = V(122:end)-(0.4/(133-122));
    end
    if V(121) == 1.55 || 1.7
       V(122:end) = V(122:end)-(0.5/(133-122));
    end
end
if I(121) == 110
    if V(121) == 0.35
       V(122:end) = V(122:end)+(0.2/(133-122));
    end
    if V(121) == 1.25
       V(122:end) = V(122:end)-(0.3/(133-122));
    end
    if V(121) == 1.4
       V(122:end) = V(122:end)-(0.4/(133-122));
    end
    if V(121) == 1.55
       V(122:end) = V(122:end)-(0.5/(133-122));
    end
    if V(121) == 1.7
       V(122:end) = V(122:end)-(0.65/(133-122));
    end
end
if I(121) == 120
    if V(121) == 1.1 || 1.25
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
    if V(121) == 1.4 || 1.55
       V(122:end) = V(122:end)-(0.55/(133-122));
    end
end
if I(121) == 130
    if V(121) == 0.95 || 1.1 || 1.25 
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
    if V(121) == 1.4
       V(122:end) = V(122:end)-(0.35/(133-122));
    end
    if V(121) == 1.55 || 1.7
       V(122:end) = V(122:end)-(0.45/(133-122));
    end 
end
if I(121) == 140
    if V(121) == 0.65 || 0.8 || 1.1
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
    if V(121) == 1.25 || 1.4 || 1.7
       V(122:end) = V(122:end)-(0.35/(133-122));
    end
    if V(121) == 1.85 || 2
       V(122:end) = V(122:end)-(0.45/(133-122));
    end
end
if I(121) == 150
    if V(121) == 0.8 || 0.95 || 1.85
       V(122:end) = V(122:end)-(0.35/(133-122));
    end
    if V(121) == 1.1 || 1.25 || 1.7
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
    if V(121) == 2 || 2.15
       V(122:end) = V(122:end)-(0.55/(133-122));
    end
end
if I(121) == 160
    if V(121) == 0.95 || 1.1 
       V(122:end) = V(122:end)-(0.45/(133-122));
    end
     if V(121) == 1.25 || 1.4 || 1.55
       V(122:end) = V(122:end)-(0.15/(133-122));
     end
     if V(121) == 1.7 || 1.85
       V(122:end) = V(122:end)-(0.35/(133-122));
     end
    if V(121) == 2 || 2.15
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
end
if I(121) == 170
    if V(121) == 1.1 || 1.25
       V(122:end) = V(122:end)-(0.65/(133-122));
    end
    if V(121) == 1.4 || 1.55 || 1.7
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
    if V(121) == 1.85 || 2 || 2.15
       V(122:end) = V(122:end)-(0.15/(133-122));
    end
end
if I(121) == 180
    if V(121) == 1.25 || 1.4
       V(122:end) = V(122:end)-(0.85/(133-122));
    end
    if V(121) == 1.7 || 1.85
       V(122:end) = V(122:end)-(0.25/(133-122));
    end
end
if I(121) == 190
    if V(121) == 1.4 || 1.55
       V(122:end) = V(122:end)-(1.15/(133-122));
    end
end
end

resultV = V(121:end);
resultI = I(121:end);
resulty = y(121:end);

end

