2% GETEXACTSOL gives the exact solutions for a Gaussian densities
3%
4% U = get_ExactSol(x,t,mu,t0,M,s,addProj)
5% Compute an exact solution for testing by choosing Gaussian densities
6% with at locations 'x' (may be an input vector) and time 't' (one fixed
7% time value). The Gaussians take the form
8% sig(t) = exp(-mu*(t - t0)^2) where 'mu' and 't0' are vectors of size 'M'
9% where 'M' is the number of sources and 's' represents the source
10% locations s = [s(1),...,s(M)]
11%
12% If addProj == 1, the exact solution computed is the one corresponding to
13% the solution of the free-space problem
14% If addProj == 0, the exact solution is the one corresponding to the
15% solution of the periodic problem
17if nargin == 0, test_getExactSol; return; end
19Ng = length(x);
20U = zeros(Ng,1);
22sqrtpi = sqrt(pi);
23sqrtmu = sqrt(mu);
25%%% Without the images
26for i = 1:Ng % for each x value
27 for m = 1:M % for each source
28 if(t>abs(x(i) - s(m))) % check needed for integration
29 A = t - abs(x(i) - s(m));
30 U(i) = U(i) + (sqrtpi/(4*sqrtmu(m)))*(erf(sqrtmu(m)*t0(m)) - erf(sqrtmu(m)*(t0(m) - A)));
31 end
32 end
33end
35end % end function
37function test_getExactSol
38ax = -pi; bx =pi; Nx = 50;
39as = -pi; bs = pi;
40dt = 1e-1;
41t = 0:dt:4*pi; Nt = length(t);
42M = 100; Ns = M;
43x = linspace(ax,bx,Nx);
44s = linspace(as,bs,Ns); s = s(randperm(Ns,M));
45mu = linspace(10,50,M);
46t0 = linspace(0.5,t(end)-0.5,M);
48u = zeros(Nx,Nt);
49for n = 1:Nt
50 u(:,n) = get_ExactSol(x(:),t(n),mu,t0,M,s);
51end
53u = real(u);
55imagesc(x,t,log10(abs(u))'); axis xy;
56% hold on; plot(s,0,'|r','MarkerSize',10); hold off;
57a=axis; a(1:2)=[-pi,pi]; axis(a);
58xlabel x; ylabel t; colorbar; title('u(x,t)');
60% plot(x,U,'LineWidth',2);
61% title(sprintf('solution evaluated at t = %1.2f',t));
62% xlabel('x'); ylabel('u'); axis tight;
64end % end the test function