How to marker a fplot(anonymous function) function on a specific point which user enters.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Khashayar Asadi
am 24 Aug. 2021
Kommentiert: Khashayar Asadi
am 24 Aug. 2021
Hello, I wrote a function which needs a (t) as input and it graphs something i want to marker the point which user inputs on the graph for example if user defines t=10 I want to marker the graph on point t=10 and x(t)=10. how should I do that. here is my code
function x=calcDisplacement(t)
m=1100;
k=570;
c=430;
x0=0.05;
v0=0;
omega_d = sqrt((4*m*k)-(c^2))/(2*m);
sigma = c/(2*m);
alpha = x0/2;
beta = -((v0+x0)/(2*(omega_d)));
displacement=@(t) 2*exp(-2*(sigma).*t).*(((alpha)*cos((omega_d).*t))-(beta)*sin((omega_d).*t));
x=displacement(t);
fplot(displacement,[0 50],'color','blue')
ylim([-0.1 0.1])
legend ('Displacement of suspension')
ylabel('Displacement(m)')
xlabel('Time(s)')
title('Graph of displacement in car suspension')
hold on;
end
0 Kommentare
Akzeptierte Antwort
Turlough Hughes
am 24 Aug. 2021
Bearbeitet: Turlough Hughes
am 24 Aug. 2021
You can add it in at the end of your function using plot:
function x=calcDisplacement(t)
m=1100;
k=570;
c=430;
x0=0.05;
v0=0;
omega_d = sqrt((4*m*k)-(c^2))/(2*m);
sigma = c/(2*m);
alpha = x0/2;
beta = -((v0+x0)/(2*(omega_d)));
displacement=@(t) 2*exp(-2*(sigma).*t).*(((alpha)*cos((omega_d).*t))-(beta)*sin((omega_d).*t));
x=displacement(t);
fplot(displacement,[0 50],'color','blue')
ylim([-0.1 0.1])
ylabel('Displacement(m)')
xlabel('Time(s)')
title('Graph of displacement in car suspension')
hold on;
plot(t,x,'ok','LineWidth',2)
legend ('Displacement of suspension','point of interest')
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!