Download An Integrated, Modular Simulation System for Education and
Transcript
RK4 (Runge-Kutta) Help file %script RK4() %RK4.m % Given the transfer function 0.0165/(s^2+0.186s+0.0165) solving the differential % equation, this routine returns the values at the next time step % In this version we use the fourth-order Runge-Kutta method % to integrate. % % integrate to get current state % dt=time increment % Theta = pitch angle % deltaE = elevator angle % This function is free to copy and distribute for educational purposes as long % as this notice is included. No guarantee expressed or otherwise is made of the % accuracy of the code. % Eric Vinande/Doug Hiranaka 4-98 % Copyright (c) 1998 by Cal Poly San Luis Obispo hold on; %clear; DegToRad = 0.01745329; %***** begin inputs ***** K = 1.0; wn = 0.12845; zeta = 0.5; deltaE = 1.0; dt = 0.5; tFinal = 100; %***** end of inputs ***** %***** coefficients for Runge-Kutta method ***** a = 2.0*zeta*wn; b = wn^2.0; c = wn^2.0; Theta(1)=0; z(1)=0; t = dt; Time(1)=0; index=2; while t <= tFinal; k1=dt*z(index-1); l1=dt*(-a*(z(index-1))-b*(Theta(index-1))+K*c*deltaE); k2=dt*(z(index-1)+l1/2.0); l2=dt*(-a*(z(index-1)+l1/2.0)-b*(Theta(index-1)+k1/2.0)+K*c*deltaE); k3=dt*(z(index-1)+l2/2.0); l3=dt*(-a*(z(index-1)+l2/2.0)-b*(Theta(index-1)+k2/2.0)+K*c*deltaE); 91