%% Second Derivative of Cosine Vector
% Calculate the discrete 1-D Laplacian of a cosine vector.
% Define the domain of the function.

x = linspace(-2*pi,2*pi);

% This produces 100 evenly spaced points in the range -2\pi \le x \le 2\pi.
%
% Create a vector of cosine values in this domain.

U = cos(x);

%
% Calculate the Laplacian of U using del2. Use the domain vector x to define the 1-D coordinate of each point in U.

L = 4*del2(U,x);

% Analytically, the Laplacian of this function is equal to \Delta U = -\cos(x).
%
% Plot the results.

plot(x,U,x,L)
legend('U(x)','L(x)','Location','Best')

% The graph of U and L agrees with the analytic result for the Laplacian.
% Copyright 2015 The MathWorks, Inc.