Documente Academic
Documente Profesional
Documente Cultură
According to the problem we are here to find the solution of the diffusion equation
given by:
2 2
= +
t x2 y2
( x , y , t=0)=sin xy
Now from the above equation we may assume the solution would be in the form of
xy +t
(x , y , t)=sin
Hence for the Forward Euler case we need to consider truncation point for the next
concurrent points.
Therefore,
Result:
clear all;
close all;
%t = [0:0.1:1];
dx = 0.05;
dy=0.05;
%clear;
a=0;
b=5;
y0=sin(pi*dx*dy);
n=100;
f=@(x,y,t) sin(pi*x*y+t);
h=(b-a)/n; % interval length
x(1)=a;
y(1)=y0;
t(1) =sin(pi*x);
for K=1:n
x(K+1)=x(K)+h;
t(K+1) = t(K)+h;
y(K+1)=y(K)+h*f(x(K),y(K),t(K));
end
plot3(x,t,y);
Question 2:
Solution: for the given wave equation for explicit condition we have,
( i+ 1n+ ni1)
n+ 1 2
i = (1)
n
n1
i +2( 1 2 ) i +
We have,
t
2
= x )2
In order to investigate the stability of the explicit scheme (1) we start with the usual
ansatz we have,
ni +1 = gn eikxl
which leads to the following expression for the amplication factor g(k)
After several transformations the last expression becomes just a quadratic equation
for g, namely
2
g 2g+1=0 ..(3)
where
g1,2= 21 (5)
Notice that if > 1 then at least one of absolute value of g 1,2 is bigger that one.
Therefor one should desire for < 1, i.e.,
That is, the scheme (1) is conditional stable. The stability condition reads
1 12 * 2sin 2 (k*x /2) 1, finally we can re arrange this into standard sin form
as:
k x /2
sin ()
0 2
(k x )
Where x=
2
Result:
C=0.1:0.1:0.4;
%% Region of Stability
figure(1)
thetha = -180:0.5:180;
for i=1:length(C)
xpoint = sind(thetha);
ypoint = 1 -4* C(i) * xpoint.^2;%%% Von Neum stability
for Wave Eqaution
hold on
scatter(xpoint,ypoint)
end
legend('Courent No. = 0.1','Courent No. = 0.2',...
'Courent No. = 0.3','Courent No. = 0.4')
title('Complex plane')
axis([-2 2 -2 2])
grid
dz
= z ..(1)
dt
2 = 1+2z, namely
The two roots lead to two linearly independent solutions, so in general yn has the
form y n= 1 + 2 ..(4)
The absolute stability region of the method is the region S in Re(z) 0 such that if z
S, then |yn| is bounded for all n. For linear multistep methods like the midpoint
method, this is equivalent to the region in the left-half complex plane where the
characteristic roots have magnitude no greater than 1.
All we need right now is the observation that if the eigenvalue is pure imaginary, =
i, and (h)2 1, then both roots satisfy
||2 = (h)2+[1(h)2] =1. This says that the method is stable for z in the interval [i,
+i].
Question 4>
u
( 2) v2 u
=
x x2 for 0 x 1 .(1)
u
+0.5
t
For a differential scheme whose criteria matches with the criteria of EF/Up-
winding scheme in soling partial differential scheme.
Consider case 3 and 4 here
For Up winding scheme we have the solution of equations as shown below:
u
u
u
u
u
u 2
2
j+1n 2unj
+ ..2
( j unj ) v
n +1
=
t 2
v
2
n+ 1 n
By rearranging the above equation 1 for u j +1 , u j and delayed cases of
n+ 1 n
u j +1 , uj in both n and j subscripts we have,
n +1 n
un+
j
1
1+ ( vc
vc n +1
)
x 2 x
u j1+
vc n+1 n+1 vc
2 x
u j +1 =u j +1
2 x (u c
j+1
2s
+u nj ) (
vc u jc
+
2 x 2 s )
+1 +
vc
2 x
vc
u nj1
2 x .(3)
In case of a & b we assume AB3 and CN diffusion for the above Berger equation
1.
u u u u
u u ( j +1n ) ( j +1n1 ) ( j+1n2 )
u u u u u
+ - +
( j unj ) v
n +1
v
= 23 16 5
t 2 2
24 1 1
(4)
By rearranging the above equation, we get
un+ 1
j +1 ( 2vc x )+u ( 1+ 2vc x )+u ( 2vc x )+u ( 16
n +1
j
n +1
j
24
c u )+u (
n1
j+1
16
24
n1
j+1
5
c u )+u ( c u )+u (
24
n1
j
16
24
n 1
cu
j
n2
j +1
n2
j+1
n2
j +1
Hence from the equation 3,4,5 we have the solution for solving in matrix form as
given below:
n+1 n 1 n2 n
Cf 1 u +Cf 2u +Cf 3 u =Cf 4 u
Hence
un+ 1=cf 11 (Cf 2u n1 Cf 3 un2 +Cf 4 un )
Equally
% 1981
v = 0.003;
thresh = 0.1;
dx = 0.04;
N = (1/dx) + 1;
dt = dx/100;
c = dt/dx;
% c=0
%% X grid
X_grid = 0:dx:1;
%% Initliak conditions
prev_u = -sin(pi * X_grid)';
%% Constructing system matrix with boundary conditions
cf12 = cf1in(prev_u,c,v,dx);
cf23 = cf2in(c,v,dx,N);
cf23_INV = inv(cf23);
%% Boundary conditions of Matrix
%% Solution
figure(1)
plot(X_grid,prev_u,'LineWidth',5.5)
grid
h = xlabel('X');
g = ylabel('U');
title(sprintf('Solution U for dx = %1.1d',dx))
set(h,'FontSize',10);
set(g,'FontSize',10);
set(gca,'fontsize',10)
hold on
hold on
i=1;
count=1;
while(true)
new_u = cf23_INV * cf12 * prev_u;
prev_u = new_u;
if(mod(i,3000)==0)
count = count+1;
plot(X_grid,prev_u,'LineWidth',5.5)
end
max(abs(prev_u))
cf12 = cf1in(prev_u,c,v,dx);
i=i+1;
if(max(abs(prev_u)) < thresh)
break;
end
end
t(1) = 0;
Legend=cell(count,1)% two positions
for i=2:count
t(i) = t(i-1) + (dt*(i-1))
end
for j=1:count
Legend{j} = sprintf(('t = %1.1d'),t(j))
end
legend(Legend);