Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------- P
- k0 = 0.01;
- kmax = 2.6;
- iterations = 100;
- increase = (kmax - k0)/iterations;
- W = zeros(iterations, 2);
- Kp = k0;
- for i = 1:iterations
- sim('BorLech3_P');
- values = simout.data;
- time = simout.time;
- deviation = mean(simout.data(end-8:end));
- error_term = time.*(values - deviation).^2;
- Error = trapz(time, error_term);
- W(i,1) = Kp;
- W(i,2) = Error;
- Kp = Kp + increase;
- end
- f1 = figure;
- plot(W(:,1),W(:,2));
- Qmin = min(W(:,2));
- index = find(W(:,2) == Qmin);
- k_opt = W(index, 1);
- disp(k_opt);
- Kp = k_opt;
- sim('BorLech3_P');
- v = simout.data;
- t = simout.time;
- f2 = figure;
- plot(t, v);
- --------------------- PI
- Ti0 = 0.01;
- Timax = 2.6;
- iterations = 100;
- increase = (Timax - Ti0)/iterations;
- W = zeros(iterations, 2);
- Kp = 2.2;
- Ti = Ti0;
- for i = 1:iterations
- sim('BorLech3_PI');
- values = simout.data;
- time = simout.time;
- deviation = mean(simout.data(end-8:end));
- error_term = time.*(values - deviation).^2;
- Error = trapz(time, error_term);
- W(i,1) = Ti;
- W(i,2) = Error;
- Ti = Ti + increase;
- end
- Qmin = min(W(:,2));
- index = find(W(:,2) == Qmin);
- Ti_opt = W(index, 1);
- disp(Ti_opt);
- Ti = Ti_opt;
- sim('BorLech3_PI');
- v = simout.data;
- t = simout.time;
- f1 = figure;
- plot(t, v);
- --------------------- PID
- Td0 = 0.01;
- Tdmax = 2.6;
- iterations = 100;
- increase = (Tdmax - Td0)/iterations;
- W = zeros(iterations, 2);
- Kp = 0.3;
- Ti = 0.6316;
- Td = Td0;
- for i = 1:iterations
- sim('BorLech3_PID');
- values = simout.data;
- time = simout.time;
- deviation = mean(simout.data(end-8:end));
- error_term = time.*(values - deviation).^2;
- Error = trapz(time, error_term);
- W(i,1) = Td;
- W(i,2) = Error;
- Td = Td + increase;
- end
- Qmin = min(W(:,2));
- index = find(W(:,2) == Qmin);
- Td_opt = W(index, 1);
- disp(Td_opt);
- Td = Td_opt;
- sim('BorLech3_PID');
- v = simout.data;
- t = simout.time;
- f1 = figure;
- plot(t, v);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement