% ispravljac, primer, Vout + R

deg = linspace(0, 360, 360 * 2 + 1);
wt = deg * pi / 180;

min = sin(wt);
amin = abs(min);
smin = sign(min);

Mout = linspace(0, 1, 201);
n = length(Mout);
Jout = zeros(1, n);

for i = 1 : n

    mout = Mout(i);
    moutline = mout * ones(1, length(deg));
    mx = max([amin; moutline]);
    mr = mx - mout;
    jout = mr;
    Jout(i) = mean(jout);
    jin = jout .* smin;
    
    figure(1)
    subplot(2, 2, 1)
    plot(deg, min)
    axis([0 360 -1.2 1.2])
    set(gca, 'XTick', [0:30:360])
    xlabel('wt [deg]')
    ylabel('v_{IN} / V_m')
    subplot(2, 2, 2)
    plot(deg, amin, 'b', deg, moutline, 'c', deg, mx, 'r')
    axis([0 360 -1.2 1.2])
    set(gca, 'XTick', [0:30:360])
    xlabel('wt [deg]')
    ylabel('|v_{IN}|/V_m, V_{OUT}/V_m, v_X/V_m')
    subplot(2, 2, 3)
    plot(deg, jout)
    axis([0 360 -1.2 1.2])
    set(gca, 'XTick', [0:30:360])
    xlabel('wt [deg]')
    ylabel('R i_{OUT} / V_m')
    subplot(2, 2, 4)
    plot(deg, jin)
    axis([0 360 -1.2 1.2])
    set(gca, 'XTick', [0:30:360])
    xlabel('wt [deg]')
    ylabel('R i_{IN} / V_m')
    
    pause(0.5)
    
end

figure(2)
plot(Mout, Jout)
xlabel('M_{OUT}')
ylabel('J_{OUT}')
title('kriva regulacije')

outdata = [Mout' Jout'];
save outdata outdata

