www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/BenefitsOfUsingGridBasedInterpolationExample.m

    %% Benefits of Using Grid-Based Interpolation

% Copyright 2015 The MathWorks, Inc.


%% Section 1
% To illustrate the power of binary searches, consider the following
% example. Before the advent of electronic credit card authorizations, the
% only protection merchants had against fraudulent credit card purchases
% was to compare the account number on each customer's credit card
% against a list of "bad" account numbers. These lists were
% bound booklets with tens of thousands of card numbers arranged in
% ascending order. How many comparisons would be required to search through
% a list of 10,000 account numbers for one sale? It turns out that for any
% list of |n| ordered items, the maximum number of comparisons will be no
% more than the number of times you can divide the list in half, or
% |log2(n)|. Therefore, the credit card search will take no more than
% |log2(10e3)| or about 13 comparisons. That's a pretty impressive
% if you consider how many comparisons it would take to perform a
% sequential search.

%%
% By contrast, consider a problem with a scattered data set.
x = rand(20,1);
y = rand(20,1);
scatter(x,y)

%%
% To find the points in close proximity to a query point would require many
% more operations. If your data can be approximated as a grid, grid-based
% interpolation will provide substantial savings in computation and memory
% usage.