Max and Min of matlab function

6 views (last 30 days)
KYLE ALVAREZ
KYLE ALVAREZ on 21 Oct 2019
Commented: KYLE ALVAREZ on 22 Oct 2019
This is my code to create a function. I have looked over many of the other questions regarding the max and min of a function and I keep getting error codes for max function and get function. This is my basic function:
f = @(r) (150.*(((1 + r).^36)-1) - 4500.*(r.*(1 + r).^36));
t = fplot(f,[0.0001 0.02]);
t
I have tried:
y = get(t,'YData');
imin = find(min(y) == y);% find the index of the min and max
imax = find(max(y) == y);
and it does not work. Any help is appreciated! Thank you!

Accepted Answer

Stephan
Stephan on 21 Oct 2019
f = @(r) (150.*(((1 + r).^36)-1) - 4500.*(r.*(1 + r).^36));
t = fplot(f,[0.0001 0.02]);
high = max(t.YData)
low = min(t.YData)
  3 Comments
Stephan
Stephan on 22 Oct 2019
f = @(r) (150.*(((1 + r).^36)-1) - 4500.*(r.*(1 + r).^36));
t = fplot(f,[0.0001 0.02]);
[high, idh] = max(t.YData);
[low, idl] = min(t.YData);
hold on
scatter([t.XData(idl), t.XData(idh)], [low, high], 'or')
text(0.004,1,"Y Maximum = 2.592")
text(0.014,-25,"Y Minimum = -27.6068")
hold off

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!