How to find zero on plot?

44 views (last 30 days)
Mitul Dattani
Mitul Dattani on 8 Jan 2018
Commented: Star Strider on 8 Jan 2018
I have the code:
function [out] = iteration(N)
if N<0
error('less than 0');
end
x(1)=1;
for k=1:N-1
x(k+1) = exp(-sin(x(k)));
end
fprintf('Iteration given: '), x;
f = @(x) exp(-sin(x)) - x;
fplot(f, [0, pi]);
title('Searching for zero');
xz=fzero(fun,1);
out=x;
end
I need to find and display the zero values using xz=fzero(fun,1). How would I go about this been stuck here for a while now.

Accepted Answer

Star Strider
Star Strider on 8 Jan 2018
When I plotted your function, there is only one zero. I would plot it as:
f = @(x) exp(-sin(x)) - x;
xz=fzero(f,1);
figure(1)
fplot(f, [0, pi])
hold on
plot(xz, 0, '+r')
hold off
  2 Comments
Mitul Dattani
Mitul Dattani on 8 Jan 2018
the question wants me to use fzero to find it and show it
Star Strider
Star Strider on 8 Jan 2018
The code in my Answer does just that!
Run it to see.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!