How to use this code in simulink without using For loop?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
madhan ravi
2023-12-20
Make use of Unit Delay block to use the value from previous timestep.
4 个评论
VBBV
2023-12-21
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!