%% Compute the Maximum and Minimum Values of a Spline
% This example shows how to calculate the maximum and minimum values of a spline in f using the fnmin function.
%% Calculate the Maximum Value
% Construct and plot a spline f with 21 knots and 15 random coefficients.

f = spmak(1:21,rand(1,15)-.5);
fnplt(f)

% Compute the maximum value of f as the negative of the minimum of -f, then plot it as a horizontal line at the height of the computed maximum.

maxval = -fnmin(fncmb(f,-1));
hold on, plot(fnbrk(f,'interv'),maxval([1 1])), hold off

%
%% Calculate the Minimum Value
% Construct and plot a spline using the spmak function.

f2 = spmak(1:5,-1);
fnplt(f2)

% Compute the minimum value of f2 and the site at which the spline takes on this minimum value.

[y,x] = fnmin(spmak(1:5,-1))

% Copyright 2019 The MathWorks, Inc.