-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExampleA.m
executable file
·88 lines (82 loc) · 2.62 KB
/
ExampleA.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
close all
clear options
%clc
% Add directory to current path
addpath('..')
% Parameters
n = 2; % Number of interfaces
sigma = [1,1,1]; % Diffusivities
xj = [1/3,2/3,1]; % Location of interfaces
u0 = @(x) x.^3; % Initial condition
beta = [1,0,1,0]; % Boundary conditions
f1 = @(t) 0.; % LHS Boundary condition
f2 = @(t) 1.; % RHS Boundary condition
tspan = [.01,.1,1]; % Times at which to compute solution
options.NX = 25; % Number of places to evaluate solution
options.NN = 10; % Integration bounds
options.Ny = 200; % Number of points to use in integration
tic
[u,xf] = UTM_Heat(n,sigma,xj,u0,beta,f1,f2,tspan,'Perfect',options);
toc
%EXACT solution. Only works for Dirichlet data
clear f1; clear f2;
f1=0; f2= 1.;
nspace=1:1000;
ue=cell(length(tspan),1);
c=zeros(1,length(nspace));
intx=linspace(0,1,200);
for j=1:length(nspace)
c(1,j)=2*trapz(intx,(u0(intx)-f1.*(1-intx)-f2.*intx).*sin(j*pi*intx));
end
for tau=1:length(tspan)
ue{tau}= @(x) f1*(1-x)+f2*x+sum(exp(-nspace.^2.*pi^2.*tspan(tau)).*sin(nspace.*pi.*x).*c);
end
uexact=zeros(length(xf),length(tspan));
for j=1:length(tspan)
for y=1:length(xf)
uexact(y,j)=ue{j}(xf(y));
end
end
% Plot
figure;
for i = 1:n+1,
plot([xj(i),xj(i)],[min(min(u)),max(max(u))],'Color',[0.9,0.9,0.9], 'LineWidth',1.)
hold on
end
plot(xf,uexact,'black-','LineWidth',2.0)
plot(xf,u,'r--','LineWidth',2.0)
axis([0,1,0,1])
xlabel('$x$','Interpreter','LaTeX','FontSize',20)
ylabel('$u(x,t)$','Interpreter','LaTeX','FontSize',20)
set(gca,'FontSize',14,'Layer','top')
saveas(gcf,'ExA.pdf')
for j=1:length(tspan)
figure
for i = 1:n+1,
plot([xj(i),xj(i)],[min(min(u)),max(max(u))],'Color',[0.9,0.9,0.9], 'LineWidth',1.)
hold on
end
plot(xf,uexact(:,j),'black-','LineWidth',2.0)
plot(xf,u(:,j),'r--','LineWidth',2.0)
axis([0,1,0,1])
xlabel('$x$','Interpreter','LaTeX','FontSize',20)
ylabel('$u(x,t)$','Interpreter','LaTeX','FontSize',20)
title(['$t=$ ',num2str(tspan(j))],'Interpreter','LateX','FontSize',20)
set(gca,'FontSize',14,'Layer','top')
filename=['ExA_t', num2str(tspan(j))];
filename(filename==['.'])=[];
saveas(gcf,[filename '.pdf'])
end
%%For Paper
figure;
for i = 1:n+1,
plot([xj(i),xj(i)],[min(min(u))-.1,max(max(u))+.1],'Color',[0.9,0.9,0.9], 'LineWidth',1.)
hold on
end
plot(xf,uexact,'black-','LineWidth',2.0)
plot(xf,u,'r--','LineWidth',2.0)
axis([0,1,0,1])
ax=gca;
ax.XTickLabel={};
ax.YTickLabel={};
saveas(gcf,'ExA_p.pdf')