-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspsurfun.m
42 lines (41 loc) · 1.48 KB
/
spsurfun.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [f,g] = spsurfun(y, z)
% SPSURFUN Evaluate the sparse grid interpolant at single point
% IP = SPSURFUN(Y,Z) Computes the interpolated value IP at
% the single point [Y1, ..., YD] for the sparse grid
% interpolant Z.
%
% [IP,IPGRAD] = SPSURFUN(Y,Z) Computes the interpolated
% value IP and the gradient vector IPGRAD.
%
% Example:
% f = inline('x.^2 + y.^2 - 2.*z');
% g1 = inline('2*x + 0*y + 0*z');
% g2 = inline('2*y + 0*x + 0*z');
% g3 = inline('-2 + 0*x + 0*y + 0*z');
% z = spvals(f,3,[],spset('GridType','Chebyshev'));
% [ip,ipgrad] = spsurfun([0.5, 0.2, 0.2], z)
% f_exact = f(0.5, 0.2, 0.2)
% g_exact = [g1(0.5, 0.2, 0.2); ...
% g2(0.5, 0.2, 0.2); ...
% g3(0.5, 0.2, 0.2)]
%
% See also SPINTERP, SPVALS.
%
% Note:
% SPSURFUN is provided for conveniece to be used as an
% alternative to SPINTERP, where the point Y to be
% evaluated is given as a row or column vector. This
% functional form is often adopted by multivariate
% optimization algorithms (such as fminsearch) in
% Matlab.
% Note that this form allows the evaluation of the sparse
% grid interpolant at a single point only. Therefore, It
% is recommended to use SPINTERP instead if multiple
% evaluations of the interpolant can be performed
% simultaneously.
if nargout <= 1
f = spinterp(z, y);
elseif nargout == 2
[f,g] = spinterp(z, y);
g = g{1,1};
end