![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992520/image.png)
How to plot this function with the interval of [-2,2]?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992485/image.png)
0 commentaires
Réponses (2)
Clay Swackhamer
le 9 Mai 2022
% Define x
x = linspace(-2,2,1000);
% Define function
y = x + 1-2*sin(pi*x);
% Estimate roots as values less than a tolerance
tol = 0.01
ix = find(abs(y)<tol)
% Plot function
plot(x,y)
hold on
% Plot roots
plot(x(ix), y(ix), 'ro')
% Add legend
legend('F(x)', 'Roots')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992520/image.png)
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots 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!