![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992520/image.png)
How to plot this function with the interval of [-2,2]?
조회 수: 11 (최근 30일)
이전 댓글 표시
답변 (2개)
Clay Swackhamer
2022년 5월 9일
% 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!