Problem 837. Find all the zeros of sinus , cosinus and tangent in a given interval
The aim is to find all the zeros of a function within an interval.
Input :
- fcn : an anonymous function (@sin, @cos...)
- lb : lower bound
- ub :upper bound
Output :
- output : vector with unique values for which the input function return zeroThe values must be sorted in ascending order.
Example
output = find_zeros(@sin,0,2*pi) will return :
output = [0.0000 3.1416 6.2832]
since the sinus function between [0 2pi] is zero for [0 pi 2pi]
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Richard Zapor
on 17 Jul 2012
Correction of assert function.
One of the ")" is in the wrong place.
is:
assert(all(abs(find_zeros(@sin,0,2*pi) -[0 pi 2*pi]<1e-9)))
Should be:
assert(all(abs(find_zeros(@sin,0,2*pi) -[0 pi 2*pi])<1e-9))
Rafael S.T. Vieira
on 4 Sep 2020
As mentioned by others, the 2nd test case is incorrect, -pi/2 is outside the interal [0,2*pi] for the function cosine. And if we do plot cos(x) on said interval, we notice that the cosine function crosses the x-axis only twice.
goc3
on 29 Sep 2020
The –pi/2 has been removed from that test case.
Solution Comments
Show commentsProblem Recent Solvers21
Suggested Problems
-
Return elements unique to either input
777 Solvers
-
Convert a vector into a number
603 Solvers
-
Implement simple rotation cypher
1084 Solvers
-
236 Solvers
-
Matrix multiplication across rows
347 Solvers
More from this Author30
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!