MATLAB Answers

0

how do you get the max y value in an fplot?

Asked by Cameron Ernest on 17 Jun 2019
Latest activity Edited by Stephen Cobeldick on 17 Jun 2019
How would I find the max y value in the following fplot
mu = @(theta) (sind(theta)/(1.8925 + cosd(theta)));
fplot(mu,[0 180]);

  0 Comments

Sign in to comment.

Tags

3 Answers

Answer by madhan ravi
on 17 Jun 2019

h = fplot(...);
MAX = max(h.YData)

  0 Comments

Sign in to comment.


Answer by dpb
on 17 Jun 2019

Look at the documentation and see what else you can do with fplot...
fp=fplot(mu,[0 100]);
[mxMu,imx]=max(fp.YData); % max, location
NB: Above is the maximum of the calculated points, not necessarily the functional maximum.
ADDENDUM: To avoid the warning message from fplot write your function with the "dot" operator ./ instead of just /

  0 Comments

Sign in to comment.


Answer by Stephen Cobeldick on 17 Jun 2019
Edited by Stephen Cobeldick on 17 Jun 2019

If you actually want to find the numerical solution (and not just whatever fplot happens to have calculated) then you can trivially use fminsearch:
>> fun = @(theta) (sind(theta)./(1.8925 + cosd(theta)));
>> xm = fminsearch(@(t)-fun(t),100)
xm =
121.9
>> ym = fun(xm)
ym =
0.62239
And checking:
>> fplot(fun,[0,180])
>> hold on
>> plot(xm,ym,'*r')

  1 Comment

[xm,fun_at_xm] = fminsearch(@(x)-fun(x),100)
xm =
121.9
fun_at_xm =
-0.62239

Sign in to comment.