How to use this code in simulink without using For loop?
    2 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Gokulraj Nattamangalathar Raju
 le 19 Déc 2023
  
    
    
    
    
    Commenté : Gokulraj Nattamangalathar Raju
 le 21 Déc 2023
            v0 = 89 / 60;                                            % [m/s] velocity of preheating roller 4
v1 = 89.2 / 60;                                          % [m/s] velocity of drawing roller 1
L = 0.7193;                                              % [m] length between preheating roller 4 and drawing roller 1
t_end = 10;                                             % [s] final time value of simulation
s0 = 0.0003537;                                          % previous strain from preheating rollers
Dt = 0.001;                                              % [s] step size in time
i_t = [0 : Dt : t_end]';                                 % [s] timeperiod required for simulation
Q_out = zeros(size(i_t));                                % vector representation of amount of materials coming out
Q_in = Q_out;                                            % vector representation of amount of materials going in
s1 = Q_out;                                              % vector representation of strain from drawing roller 1
s1(1) = s0;                                              % assigning strain 1 (strain from drawing roller 1) for 1st calculation as strain 0 (strain from preheating roller 4)
for k = 1:numel(i_t)-1
    Q_in(k) = (v0 * Dt) / (1 + s0);
    Q_out(k) = (v1 * Dt) / (1 + s1(k));
    s1(k+1) = s1(k) + ((Q_out(k) - Q_in(k)) / L);
    disp(s1(k))
end
0 commentaires
Réponses (1)
  madhan ravi
      
      
 le 20 Déc 2023
        Make use of Unit Delay block to use the value from previous timestep.
4 commentaires
  VBBV
      
      
 le 21 Déc 2023
				  Q_in(k) = (v0 * Dt) / (1 + s0);  % this line in the loop is constant block
The above line in the loop can be implemented as constant value i.e. constant block. 
Then for the vector which uses the amount of material output and strain from drawing roller 1,  
- use two signal blocks separately in same sequence
- use the summer block before the above two signal blocks
- use the Unit Delay block after the above two signal blocks
- connect the output from Unit Delay to the summer before the above two signal blocks to create a feedback
Note: Set the simulation interval time according to the time length specified in the unit delay block
Hope this helps 
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


