Populating a vector between upper and lower bound?
Ältere Kommentare anzeigen
I'm trying to simulate a cyclic loading in Matlab by varying strain between a positive upper bound and negative lower bound.
The code below stops at the upper bound, but ignores the lower bound. Ideally, I would be able to set however many loops I want and get values that incrementally alternate between e_max and -emax.
For the code below, the vector values should have gone up to 4 and down to -4 several times. Instead they continue down to -16 after hitting the upper bound.
e = [0 1]; %Initial strain values
e_max = 4; %Max strain values
e_t = 1; %Strain rate
delta_t = 1; %Time interval
for i = 2:1:24
if e(i) < e_max && e(i) > e(i-1); %Increases strain as long as strain is below upper bound
e(end+1) = e(i) + e_t*delta_t;
else e(i) > -e_max && e(i-1) > e(i); %Decreases strain as long as strain is below upper bound
e(end+1) = e(i) - e_t*delta_t;
end
end
>> e
e =
0 1 2 3 4 3 2 1 0 -1 -2 -3 -4 -5
-6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Clocks and Timers finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!