How to find the point the graph crosses the x axis

25 vues (au cours des 30 derniers jours)
Luis
Luis le 18 Nov 2024
Commenté : Luis le 25 Nov 2024 à 13:15
Hello,
So I am trying to find the value when it crosses the x axis for the first time on the dammped spring graph each and label it so that I can a specific value. Any help would be very much appreciated
t = 0:0.005:5;
x = (0.3) .* exp(-3 .*t) .* cos(4 .* t) + 0.2 .*exp(-3 .* t) .* sin(4 .* t);
%% graphs part
plot(t,x)
hold on
yline(0,'LineStyle','--','Color','m')
xline(0.5397,'LineStyle','--','Color','r')
grid on
xlabel('Time/s')
ylabel('Displacement/m')

Réponse acceptée

Matt J
Matt J le 19 Nov 2024
x = @(t) (0.3) .* exp(-3 .*t) .* cos(4 .* t) + 0.2 .*exp(-3 .* t) .* sin(4 .* t);
firstroot = fzero(x,[0,1])
%% graphs part
fplot(x,[0,5])
hold on
yline(0,'LineStyle','--','Color','m')
xline(firstroot,'LineStyle','--','Color','r')
grid on
xlabel('Time/s')
ylabel('Displacement/m')
  1 commentaire
Luis
Luis le 25 Nov 2024 à 13:15
Thank you for helping me

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 18 Nov 2024
if x(1) == 0
crossing_location = 1;
elseif x(1) < 0
%crossing from negative to positive
crossing_location = find(x >= 0, 1, 'first');
else
%crossing from positive to negative
crossing_location = find(x <= 0, 1, 'first');
end
if isempty(crossing_location)
%no crossings!
else
t_crossing = t(crossing_location);
x_crossing = x(crossing_location);
end

Catégories

En savoir plus sur Graph and Network Algorithms 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!

Translated by