# How to plot this function with the interval of [-2,2]?

18 views (last 30 days)
ken on 9 May 2022
Answered: Star Strider on 9 May 2022
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Answers (2)

Clay Swackhamer on 9 May 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')
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Star Strider on 9 May 2022
Use fimplicit
syms x
f(x) = x + 1 - 2*sin(pi*x)
f(x) =
figure
fimplicit(f, [-2 2])
grid
xlabel('x')
.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on Line Plots in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!