Can't find the max of the plot

I'm new to Matlab, and I have encountered the following problem: I have a vector, named x, which contains 100 element created by a linspace function between eps and pi. Now, my plot is the following: (sin(t)/(4.7*t+3))+(cos(t.^2))*0.1 and stored in a fv variable. When I enter this into the find(max(fv) == fv) function, I get 1. But the correct answer should be 22, because when I enter t(22) to the place of t, I get a bigger number, than t(1). I have been working on it several days, and I couldn't get a good solution. What did I do wrong?

 Accepted Answer

Stephen23
Stephen23 on 26 Feb 2017
Edited: Stephen23 on 26 Feb 2017
(sin(t)./(4.7*t+3))+(cos(t.^2))*0.1;
^ you need this "."
Then your function comes out as you expect it to:
>> t = linspace(eps,pi,100);
>> fv = (sin(t)./(4.7*t+3))+(cos(t.^2))*0.1;
>> plot(fv)
with the maximum at around the 22nd element of fv:
whereas what you were calculating is this:
>> fv = (sin(t)/(4.7*t+3))+(cos(t.^2))*0.1;
>> plot(fv)

More Answers (0)

Asked:

on 26 Feb 2017

Commented:

on 26 Feb 2017

Community Treasure Hunt

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

Start Hunting!