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

    %% Interpolate to a matrix of values  
% This example shows how to interpolate a solution to a scalar problem
% using a |pOut| matrix of values.

% Copyright 2015 The MathWorks, Inc.


%% 
% Solve the equation $-\Delta u = 1$ on the unit disk with zero Dirichlet conditions. 
g0 = [1;0;0;1]; % circle centered at (0,0) with radius 1
sf = 'C1';
g = decsg(g0,sf,sf'); % decomposed geometry matrix
problem = allzerobc(g); % zero Dirichlet conditions
[p,e,t] = initmesh(g);
c = 1;
a = 0;
f = 1;
u = assempde(problem,p,e,t,c,a,f); % solve the PDE  

%% 
% Construct an interpolator for the solution.
F = pdeInterpolant(p,t,u);  

%% 
% Generate a random set of coordinates in the unit square. Evaluate the
% interpolated solution at the random points.
rng default % for reproducibility
pOut = rand(2,25); % 25 numbers between 0 and 1
uOut = evaluate(F,pOut);
numNaN = sum(isnan(uOut)) 

%%
% |uOut| contains some |NaN| entries because some points in |pOut| are outside
% of the unit disk.