控制系統數字模擬與CAD-第一次實驗-附完整程式碼
阿新 • • 發佈:2018-11-13
實驗內容
1. 分別用尤拉法和四階龍格庫塔法求解如下:
(1)R=4K,C=1F,L=1H,模擬時間:0.03s
(2)R=280,C=8F,L=2H,模擬時間:0.1s
兩組引數下電路的單位階躍響應。(初始條 件均為零)。
熟悉並理解掌握MATLAB模型轉換以及引數提取指令(針對上述系統寫出它們的執行結果)
G=tf (num, den)
G1=tf(G) G=zpk (z, p, k)
G1=zpk (G) G=ss (A, B, C, D)
G3=ss (G)
[num, den] = tfdata (G)
[Z, P,K] = zpkdata (G)
[A, B, C, D] = ssdata (G)
1.引數提取:
% -----引數提取----------------
clear;
clc;
L = 2;
C = 0.000008;
R = 280;
num = [1];
den = [L*C, R*C, 1];
[z,p,k] = tf2zp(num,den)
[A,B,C,D] = tf2ss(num,den)
2.尤拉法求解(1)R=4K,C=1F,L=1H,模擬時間:0.03s :
function [z]=fun(X) R =4000; C =0.000001; L = 1; A = [0, 1/C;-1/L,-R/L]; B = [0;1/L]; z = A*X+B; end
clear; clc; % ---------------尤拉法------------- h = 0.0001; y = [0;0]; for i = 0:1:300 t = i*h; x(i+1) = t; k1 = fun(y); k2 = fun(y+h*k1); y = y + (k1 +k2)*h/2; output1(i+1) = y(1,1); end plot(x,output1) %------------四階-龍格-庫塔----------- % h = 0.0001; % y = [0;0]; % for i = 0:1:1000 % t = i*h; % x(i+1) = t; % k1 = fun(y); % k2 = fun(y+h*k1/2); % k3 = fun(y+h*k2/2); % k4 = fun(y+h*k3); % y = y + (k1 + 2*k2 +2*k3 + k4)*h/6; % output1(i+1) = y(1,1); % end % plot(x,output1)
執行結果如下:
四階龍格庫塔(2)R=280,C=8F,L=2H,模擬時間:0.1s:
function [z]=fun(X)
R =280;
C =0.000008;
L = 2;
A = [0, 1/C;-1/L,-R/L];
B = [0;1/L];
z = A*X+B;
end
clear;
clc;
% ---------------尤拉法-------------
% h = 0.0001;
% y = [0;0];
% for i = 0:1:300
% t = i*h;
% x(i+1) = t;
% k1 = fun(y);
% k2 = fun(y+h*k1);
% y = y + (k1 +k2)*h/2;
% output1(i+1) = y(1,1);
% end
% plot(x,output1)
%------------四階-龍格-庫塔-----------
h = 0.0001;
y = [0;0];
for i = 0:1:1000
t = i*h;
x(i+1) = t;
k1 = fun(y);
k2 = fun(y+h*k1/2);
k3 = fun(y+h*k2/2);
k4 = fun(y+h*k3);
y = y + (k1 + 2*k2 +2*k3 + k4)*h/6;
output1(i+1) = y(1,1);
end
plot(x,output1)
執行結果如下:
你可以在這裡找到完整的程式碼.