'Problem' with fzero
1 view (last 30 days)
Show older comments
Hi, hope you all are well. I am here due to a problem with the function called 'fzero'.
On one hand, I have this file: f.m
function y=f(x)
y= besselj(1,x);
And on the other hand: exercise.m
D=fzero(@f,[0 10]);
tam=length(D);
for i=1:tam
fprintf(' Possible MAX or MIN: f(%f) \n',D(i))
end
When I run exercise.m, I get this output:
Possible MAX or MIN: f(0.000000)
I know where this values should be located...
What am I doing wrong? Thanks in advance. PD: I have to use fzero and besselj(1,x) at [0:10]
0 Comments
Accepted Answer
Matt J
on 30 Jun 2015
Edited: Matt J
on 30 Jun 2015
Looks like the code succeded to me. Your function does have a root at x=0.
No idea why you display a message involving MAX and MIN unless you were really trying to minimize/maximize the function. But as its name implies, fzero finds zeros, not max's and min's. You might have been looking to use fminsearch()
More Answers (0)
See Also
Categories
Find more on Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!