Turn function to zero when it reach specific value.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abdul Kadir Alhamid
le 22 Déc 2019
Commenté : Abdul Kadir Alhamid
le 22 Déc 2019
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
0 commentaires
Réponse acceptée
Vladimir Sovkov
le 22 Déc 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 commentaires
Vladimir Sovkov
le 22 Déc 2019
If you want to stop when the ABSOLUTE value of y reaches Pu, use y(find(abs(y)>=Pu,1):end)=0;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!