How do I get my code to display the associated x values for maximum and minimum

In addition, How do I get it to label the coordinates in the graph it makes? I tried getting it to display Xmax or Xmin, but it says not defined.
a = -7.0;
b = 1.0;
c = 2.0;
d = 20.0;
e = 2.0;
f = 5.0;
p = @(x) c * x.^3 + d * x.^2 + e * x + f;
CP = quadratic(3 * c, 2 * d, e);
crit_pt1 = CP(1);
crit_pt2 = CP(2);
if isreal(crit_pt1)
disp('Crit Point 1:');
disp(crit_pt1);
disp('p(Crit Point 1):');
disp(p(crit_pt1));
disp('Crit Point 2:');
disp(crit_pt2);
disp('p(Crit Point 2):');
disp(p(crit_pt2));
else
disp('The critical points are complex.');
end
disp('Left Endpoint:');
disp(a);
disp('p(Left Endpoint):');
disp(p(a));
disp('Right Endpoint:');
disp(b);
disp('p(Right Endpoint):');
disp(p(b));
Q=[p(a),p(b),p(crit_pt1),p(crit_pt2)];
disp('p(Xmax):');
disp(max(Q));
disp('p(Xmin):');
disp(min(Q));
delta = (b - a) / 100;
x = a:delta:b;
y = p(x);
plot(x, y)

 Akzeptierte Antwort

You can use the text() command. Or, you can do
set(axis_handle,'XTick',whatever)
to have the x-axis show "whatever".

4 Kommentare

cakey
cakey am 21 Sep. 2014
Bearbeitet: cakey am 21 Sep. 2014
In whatever, do I put the p(Xmax)? And it says undefined function at axis_handle.
Matt J
Matt J am 21 Sep. 2014
Bearbeitet: Matt J am 21 Sep. 2014
"whatever' must be a vector of all values you want tick marked on the axis.
axis_handle is not a function call. You need to pass a handle to your plot axis, either as obtained by gca() or some other means.
Yes, I do not understand the language. Is there anywhere where I can read how to do it?
About axis handles? You can start with "doc gca" and pages that it links to.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 21 Sep. 2014

Kommentiert:

am 22 Sep. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by