%    CAMPG/MATLAB - GENERATED MODEL DESCRIPTION:
 %      The following files have been generated
 %
 %      campgmod.m  => m file containing model parameters
 %                    intial conditions, sources and simulation controls
 %      campgequ.m  => m function containing the system
 %                    first order differential equations
 %      campgsym.m  => m file containing system matrices,tranfer fuctionss in symbolic form
 %      campgnum.m  => m file containing system matrices,tranfer functions in numeric form
 %
 %    For simulation and control, edit these files
 %     Enter values for physical parameters, initial
 %     conditions,inputs and time controls
 %     in places where the ? marks appear
 %     Standard generalized variables in Bond Graph notation used.
 %
 %......CAMPGMOD.M - MATLAB MODEL INPUT FILE  ......
   clear
   more off

 % ......  Initial conditions  ........
    % All initial conditions are zero
              Q9IN= 0  ; P8IN= 0  ;
              Q5IN= 0  ; P3IN= 0  ;
   initial = [Q9IN; P8IN; Q5IN; P3IN] ;

 % ......System Physical Parameters........
   global R2 I3 C5 R7 I8 C9
              R2 = 2  ; % Ohms
              I3 = 1  ; % Henries
              C5 = .02  ; % Ferads
              R7 = 4  ; % Ohms
              I8 = 2  ; % Henries
              C9 = 0.8  ; % Ferads

 % ...... External inputs se(t), sf(t) ......
   global SE1
              SE1 = 10  ; % Voltage

 %..... Simulation Time Control .....
              t0= 0  ;     %  Initial Time
              tfinal= 2  ; %  Final Time
              tspan= [t0 tfinal];
 %.....  Define Outputs .....
   global TIME STEP EFFORTS FLOWS
   STEP=1;
 % ......  Computer Simulation ......
 %  Solution of system equations using Matlab "ode23 or ode45" function
 %  The "campgequ.m" function contains the system differential
 %  equations in state variable form.
 %
 %  It returns the vector [t,p-q] where:
 %   t = time and p-q = vector of state variables
 %   [t,p_q] is a column vector with rows [t, p_q(1) p_q(2)  p_q(3) ...]
   [t,p_q] = ode45('campgequ',tspan,initial);
 %          Q9= p_q(1) ; %          P8= p_q(2) ;
 %          Q5= p_q(3) ; %          P3= p_q(4) ;
 % p_q = [Q9; P8; Q5; P3] ;
 %
 % Sample Matlab structure for plotting simulation results (Plotting first two state variables)
   figure(1)
   subplot (211),plot(t,p_q(:,1),'b'),grid
   title(' Variable p_q(:,1) (stored in column 1),color blue')
   ylabel ('p_q(1) (units)'),xlabel('Time (seconds)')
   subplot (212),plot(t,p_q(:,2),'m'),grid
   title(' variable p_q(:,2) (stored in column 2), color magenta')
   ylabel ('p_q(2) (units)'),xlabel('Time (seconds)')
 %
 % Sample structure for plotting Output Variables as defined in "campgequ.m"
 %   Example:  If the efforts and flows were defined as:
 %    EFFORTS(STEP,:) = [e1 e11 e4];
 %    FLOWS(STEP,:)	 = [f1 f9  f8];
    figure(2)
 %  Plot e1 vs TIME (First column of "EFFORTS" vector)
    subplot (211), plot (TIME,EFFORTS(:,1),'b'),grid
    title(' Effort variable of vector "EFFORTS(:,1)" stored in column 2')
 %  Plot f1 vs time  (First column of "FLOWS" vector)
    subplot (212), plot (TIME,FLOWS(:,1),'m'),grid
    title(' Flow variable of vector "FLOWS(:,1)" stored in column 3')

             %..........BOND GRAPH NOTATION.............
           %  GENERALIZED VARIABLES BOND GRAPH NOTATION :
 %---------------------------------------------------------------------
 %                      MECHANICAL         ELECTRICAL    HYDRAULIC
 %              | TRANSLATION| ROTATION  |            |
 %--------------|------------|-----------|------------|----------------
 %E (Effort)    |Force       |Torque     |Voltage     |Pressure
 %F (Flow)      |Velocity    |Ang Vel.   |Current     |Volume Flow Rate
 %Q (Gen Disp)  |Displacement|Angle      |Charge      |Volume
 %P (Gen Momentum)|Momentum  |Ang.Moment.|Flux Linkage|Pressure Moment.
 %---------------------------------------------------------------------
 % TF (M) (Transformer Modulus)      SE Source Effort
 % GY (R) (Gyrator Modulus)          SF Source Flow
 %---------------------------------------------------------------------

        %*********************    ********************
             %....... BOND GRAPH ANALYSIS .......

  %SYSTEM  DESCRIPTION:


 % POWER FLOW:
 % BOND    FROM                                TO
 % ----    ----                                --
 %   1   SE_1                                1_1_2_3_4
 %   2   1_1_2_3_4                           R_2
 %   3   1_1_2_3_4                           I_3
 %   4   1_1_2_3_4                           0_4_5_6
 %   5   0_4_5_6                             C_5
 %   6   0_4_5_6                             1_6_7_8_9
 %   7   1_6_7_8_9                           R_7
 %   8   1_6_7_8_9                           I_8
 %   9   1_6_7_8_9                           C_9

 % CAUSALITY FLOW:

 % NOTE:  FROM -----| TO

 % BOND    FROM                                TO
 % ----    ----                                --
 %   1   SE_1                                1_1_2_3_4
 %   2   R_2                                 1_1_2_3_4
 %   3   1_1_2_3_4                           I_3
 %   4   0_4_5_6                             1_1_2_3_4
 %   5   C_5                                 0_4_5_6
 %   6   0_4_5_6                             1_6_7_8_9
 %   7   R_7                                 1_6_7_8_9
 %   8   1_6_7_8_9                           I_8
 %   9   C_9                                 1_6_7_8_9


 % End of model