Experiment 1: state equation, transfer function model for the simulation system

First, the purpose of the experiment
  1. The master parameters into the mathematical model between the mathematical model to obtain, acquire the relevant MATLAB command
  2. grasp Euler method and RK recurrence formula method
  3. grasp Euler method and RK Law of MATLAB algorithms achieve
Second, the experimental content
  1 are expressed by the Euler method and the Runge - to solve the following system Kutta method:
  (. 1) R & lt = 4K [Omega] , C =. 1 [mu] F. , L = IH , simulation time: 0.03s   (2 )  R & lt = 280 [Omega] , C =. 8 [mu] F. , L = 2H , simulation time: 0.1s 

  

     The two lower circuit unit step response parameters. (Initial conditions are zero).

  2.  familiar with and understand the master MATLAB model parameter conversion and extract instruction fetch (write operation thereof results for the above system)

   G=tf(num,den)    G1=tf(G)

   ZPK = G (z, p, k) = G1 ZPK (G)

  G=ss(A,B,C,D)    G3=ss(G)

  [Num, den] = tfdat (G)

  [Z, P, K] = zpkdata (G)

  [A,B,C,D]=ssdata(G)

Third, the experimental requirements
  1. preview content and complete the experiment
  2. The complete test report, including at least: theoretical analysis, experimental procedure, the results of running the program and the results of
analysis.

Fourth, the experiment content

  1. Modeling

  Column equation:

  

   State space representation (time domain):

   

    Written in matrix form:

  

    Laplace transform to obtain the transfer function (Complex):

  

    2. Experimental Code:

********** parameter extraction *************%
R = 4000;
C = 0.000001;
L = 1;
= a [1];
den = [L * C, R * C, 1];
G = tf (num, den)
G1 = tf(G)
G2 = ZPK (G)
G3 = ss(G)
[N, den] = tfdat (G)
[Z, P, K] = zpkdata (G)
[A, B, C, D] = ssdata(G)

  Question 1):  

clear;
clc;
%******************************************%%
%               Question 1
%******************************************%%
R 1 = 4000;
C1 = 0.000001;
L1 = 1;
A1 = [0, 1 / C 1, -1 / L1, -R 1 / L1];
B1 = [0;1/L1];
h1 = 0.00003;       % step size
y1 = [0;0];
y2 = [0; 0];
% ********  Euler method  **********%
for i1 = 0:1:1000   
    t1 = i1*h1;     % simulation time: 0.03s
    x1(i1+1) = t1;
    k1 = A1 * y1 + B1;
    k2 = A1 * (y1+h1*k1) + B1;
    y1 = y1 + (k1 +k2)*h1/2;
    result_for_Euler_1(i1+1) = y1(1,1);
end
% ********  4 order Runge-Kutta method  **********%
for i2 = 0:1:1000   
    t2 = i2*h1;     % simulation time: 0.03s
    x2(i2+1) = t2;
    k1 = A1 * y2 + B1;
    k2 = A1 * (y2+h1*k1/2) + B1;
    k3 = A1 * (y2+h1*k2/2) + B1;
    k4 = A1 * (y2+h1*k3) + B1;
    y2 = y2 + (k1 +k2)*h1/2;
    result_for_RK_1(i2+1) = y2(1,1);
end
subplot(2,2,1);plot(x1,result_for_Euler_1,'b');
xlabel(' time  /s ');ylabel(' Uc /V ');title('Result for Euler method');legend('Euler');
subplot(2,2,2);plot(x2,result_for_RK_1,'r');
xlabel(' time  /s ');ylabel(' Uc /V ');title('Result for Runge-Kutta method');legend('Runge-Kutta');
subplot(2,1,2);plot(x1,result_for_Euler_1,'b', x2,result_for_RK_1,'r');
xlabel(' time  /s ');ylabel(' Uc /V ');
title('Comparision of results between Euler and RK');legend('Euler','Runge-Kutta');

  问题(2):

clear;
clc;
%******************************************%%
%               Question 2
%******************************************%%
R1 = 280;
C1 = 0.000008;
L1 = 2;
A1 = [0, 1/C1;-1/L1,-R1/L1];
B1 = [0;1/L1];
h1 = 0.0002;       % step size
y1 = [0;0];
y2 = [0;0];
% ********  Euler method  **********%
for i1 = 0:1:500
    t1 = i1*h1;     % simulation time: 0.1s
    x1(i1+1) = t1;
    k1 = A1 * y1 + B1;
    k2 = A1 * (y1+h1*k1) + B1;
    y1 = y1 + (k1 +k2)*h1/2;
    result_for_Euler_1(i1+1) = y1(1,1);
end

% ********  4 order Runge-Kutta method  **********%
for i2 = 0:1:500   
    t2 = i2*h1;     % simulation time: 0.1s
    x2(i2+1) = t2;
    k1 = A1 * y2 + B1;
    k2 = A1 * (y2+h1*k1/2) + B1;
    k3 = A1 * (y2+h1*k2/2) + B1;
    k4 = A1 * (y2+h1*k3) + B1;
    y2 = y2 + (k1 +k2)*h1/2;
    result_for_RK_1(i2+1) = y2(1,1);
end
subplot(2,2,1);plot(x1,result_for_Euler_1,'b');
xlabel(' time  /s ');ylabel(' Uc /V ');title('Result for Euler method');legend('Euler');
subplot(2,2,2);plot(x2,result_for_RK_1,'r');
xlabel(' time  /s ');ylabel(' Uc /V ');title('Result for Runge-Kutta method');legend('Runge-Kutta');
subplot(2,1,2);plot(x1,result_for_Euler_1,'b', x2,result_for_RK_1,'r');
xlabel(' time  /s ');ylabel(' Uc /V ');
title('Comparision of results between Euler and RK');legend('Euler','Runge-Kutta');

  3. 运行结果

   问题(1):

   

   问题(2):

  

 

Guess you like

Origin www.cnblogs.com/KaifengGuan/p/11837496.html