function xdot = nonlinear (t, x) % % Nonlinear system simulation example % USE THIS FILE AS A TEMPLATE BY SUBSTITUTING YOUR OWN % EQUATIONS ETC % % This is an example of an m-file function for the simulation % of linear and non-linear dynamic systems represented as a % system of first order dfqs % % this function may be called by ode23, ode45, rk45, etc. % % Inputs: % x : vector of current states % t : time value % % Output: % xdot : vector with results % % Define Local Parameters % omsq = 10.0 ; alpha = 3.0 ; % % Establish the input % u = 0.0; % % Perform any algebraic calculations % % % Describe the Nonlinear / Linear dynamics % Example for a case where the dynamics change % depending on the time ie % system parameters are time depended % if t > 1 xdot(1) = x(2); xdot(2) = -10.0 * omsq * x(1) - 2.0 * alpha * x(2) + omsq*u; else xdot(1) = x(2); xdot(2) = -omsq * x(1) - 20.0 * alpha * x(2) + omsq*u; end xdot = xdot'; % transpose first order dfq equations % end of m-file =========================== % Solving this problem using Matlab and ode23 function % MATLAB COMMAND WINDOW - MATLAB COMMAND WINDOW % NOTE: % you can get help about ode23 using >> help ode23 > x0 = [1 0]; % Define Initial Conditions > simtime = [0 10]; % Define the simulation time > [t, y] = ode23('nonlinear', simtime, x0 ); % call ode23 > plot(t,y) % Plot results