# Turn function to zero when it reach specific value.

6 views (last 30 days)
Hello everyone, I am trying to apply sinusoidal force to my structure with a given function, and I want to stop the force whenever it reach the variable "Pu". I try to write this code but it seems doesn't working.Can anyone help me to solve this out?
x = linspace (0,180,1800);
y = 1. * ((exp (-0.01. * x)). * (sin (x)-(x. * cos (x / 2))));
Pu = 30;
for i = 1: length (x)
if x (i)> x (abs (y)> = 30)
y (i) = 0;
end
end
subplot (1,1,1);
axis ([0 180 -50 50]);
grid on
xlabel ( 'Time (min)' )
ylabel ( 'Force (kN)' )
ani1 = animatedline ( 'Color' , 'r' , 'LineStyle' , '-' );
legend ( 'Force Applied' )
for k = 1: length (x)
addpoints (ani1, x (k), y (k));
drawnow
pause (0.01);
end

Vladimir Sovkov on 22 Dec 2019
x = linspace (0,180,1800);
y = 1. * ((exp (-0.01 .* x)) .* (sin (x)-(x .* cos (x / 2))));
Pu = 30;
y(find(y>=Pu,1):end)=0;
% for i = 1: length (x)
% if x (i) > x (abs (y) >= 30)
% y (i) = 0;
% end
% end
figure;
subplot (1,1,1);
axis ([0 180 -50 50]);
grid on
xlabel ( 'Time (min)' )
ylabel ( 'Force (kN)' )
ani1 = animatedline ( 'Color' , 'r' , 'LineStyle' , '-' );
legend ( 'Force Applied' )
for k = 1: length (x)
addpoints (ani1, x (k), y (k));
drawnow
pause (0.01);
end
##### 2 CommentsShowHide 1 older comment
Abdul Kadir Alhamid on 22 Dec 2019
It works! Thanks a lot