Anda di halaman 1dari 34

PROJECT REPORT

IAS-NASI-INSA
Summer Research Fellowship Programme 2014





Spectral methods for solving Differential
Equations







Rajesh Aggarwal
Faculty of Engineering and Technology
Gurukula Kangri Vishwavidyalaya Haridwar






Under the guidance of

Dr. Pravin Kumar Gupta
Department of Earth Sciences
Indian Institute of Technology, Roorkee
Uttarakhand




NAME OF SRF:


Rajesh Aggarwal
REGISTRATION NUMBER:


MATS605
INSTITUTE WHERE WORKING:

Indian Institute of
Technology, Roorkee
DATE OF JOINING THE PROJECT:


11/06/2014
DATE OF COMPLETION OF THE PROJECT: 06/08/2014



NAME OF THE GUIDE:


Dr. Pravin Kr. Gupta
PROJECT TITLE:











Spectral methods for
solving Differential
equations
Dr. Pravin Kumar Gupta

Rajesh Aggarwal
Department of Earth Sciences

MATS605
Indian Institute of Technology

Date:
Roorkee, Uttarakhand
Date:



06/08/2014
06/08/2014

Dr. Pravin Kumar Gupta
Department of Earth Sciences,
Indian Institute of Technology
Roorkee, Uttarakhand
E-mail: pkgptfes@iitr.ernet.in





CERTIFICATE

This is to certify that the project entitled Spectral methods for solving
Differential Equations is a bonafide work carried out by Rajesh
Aggarwal, Second Year B.Tech in Electrical Engineering , Faculty of
Engineering and Technology, Gurukula Kangri Vishwavidyalaya,
Haridwar at Indian Institute of Technology, Roorkee under my guidance,
during the period of 11
th
June 2014 to 06
th
August 2014.




(Dr. Pravin Kumar Gupta)










Acknowledgement

I would like to thank Dr. Pravin Kumar Gupta for the continuous guidance
and patience. Being my 1
st
summer project I had lot of things to learn and
the amount of knowledge and experience I have gained from him is
matchless.
I owe my sincere thanks to him.
I thank Mr. Rahul Dehiya for his guidance and overall for making it a
great learning experience.

I also thank IAS-NASI-INSA for their support throughout the programme
and for giving me this great opportunity. It would have not been possible
without this programme.




Rajesh Aggarwal







Table of Contents


1. Introduction...................................................................... 6

1.1. Analytical methods for solving Differential Equation (D.E.)
...7
1.2. Numerical Methods....8
1.2.1. Conventional finite difference method (CFDM)...8
1.2.2. Spectral finite difference method (SFDM)9

2. Methods ........................................................................ 10

2.1. Methods for solving D.E by CFDM.11
2.1.1. Matlab code for solving D.E by CFDM12
2.2. Methods for solving D.E. by SFDM14
2.2.1. Matlab code for solving D.E by SFDM15
2.2.2. Matlab code for function interpolant_raj..16
2.3. Solving Problem on Half-space with different number of grid
points ..18
2.3.1. Conventional finite difference method....18
2.3.1.1. Matlab code for CFDM18
2.3.2. Spectral finite difference method..20
2.3.2.1. Matlab code for SFDM.20
2.3.2.2. Matlab code for function points_raj_finite..23
2.3.2.3. Matlab code for function earths_k.24
2.4. Layered earth Problem....25
2.4.1. Conventional finite difference method....25
2.4.1.1. Matlab code for CFDM...25
2.4.2. Spectral finite difference method..27
2.4.2.1. Matlab code for SFDM....27

3. Conclusion........................................................30

4. References..................................................................... 32
6

























Introduction
7





1.1. Analytical methods for solving differential equations:
Analytical solutions are exact solutions of differential equations.
It satisfies differential equations and boundary conditions.
For example: For specific problem of Newton laws of cooling we have differential
equations associated with it as:
( ) 2 25
dy
y
dt
= With initial condition ( ) 0 40 y =
This problem can be easily solved analytically and give exact results having solution
as:
1
2
(25 )
dy
dt y
=

=> 2 ,
(25 )
dy
dt
y
=

=> 2 ,
(25 )
dy
dt
y
=

} }

=>
0
( 1) ln 25 2 y t C = +
=> ln 25 2 y t C = +
=>
2 2
25
t C t C
y e e e
+
= =
=>
2
25
C t
y e e

=
=>
2 2
25 25 ,
C t t
y e e Ae

= = +
On putting initial conditions we get
2
25 15
t
y e

= +
But all real physical system do not provide such simple differential equation
And it is tough task to solve complicated differential equations with analytical methods.
So, we need another methods that can be used to solve differential equations
associated with physical system.


8


1.2. Numerical Methods:
Numerical methods provide numerical approximation to the solutions of differential
equations.
Numerical methods do not provide exact solutions of differential equations. They give
approximation to the results.
We will deal with finite difference method methods for solving differential equations:
(1). Conventional finite difference method (CFDM)
(2). Spectral finite difference method (SFDM)
1.2.1. Conventional finite difference method:

In conventional finite difference method we convert our differential equation to
difference equation and then solve it to get our desired result.

Differential equations can be converted to difference equation by replacing first and
second prime by respective difference formula.
The derivative of a function f at a point x is defined by the limit
0
( ) ( )
( ) lim
h
f x h f x
f x
h

+
' =
And, double derivative of a function f at a point x is defined by the limit
2
0
( ) 2 ( ) ( )
( ) lim
h
f x h f x f x h
f x
h

+ +
'' =
The above two formula can be derived by considering Taylor series of function f.
2
( ) ( )
( ) ( ) ( )
1! 2!
f a f a
f a h f a h h O h
' ''
+ = + + +
Where ( ) O h denotes higher order terms or by simply neglecting all higher order terms
we can write
( )
( ) ( )
1!
f a
f a h f a h
'
+ ~ +
Or,
( ) ( )
( )
f a h f a
f a
h
+
' ~


9


1.2.2 Spectral finite difference methods:

When data are smooth Spectral finite difference methods can be used to solve
ordinary differential equations and partial differential equations with high accuracy in
simple domain.
Spectral finite difference methods can achieve high accuracy then conventional finite
difference methods (spectral finite difference methods can achieve accuracy up to ten
digits while finite difference can up to 2 digits with the same number of grid points).
In spectral finite difference methods we write the differential equations as the sum of
basic functions and find there coefficient such that the resultant function can satisfy
the differential equations.
For example: To solve any differential equation we can take a function
( ) ( )
n n
n
f x a x |

=
=


Such that ( ) f x satisfy ( )
j j
f x u =
Where
j
u is corresponding value of function at
j
x
Here we are free to choose ( )
n
x | , ( )
n
x | can be either
(i) trigonometric,
(ii) exponentials or
(iii) Simple combinations of polynomials.










10



























Methods
11


2.1. Methods for solving differential equations by CFDM:
Let the given differential equation be:
2
2
2
0
d y
k y
dx
=
.. <01>
With boundary conditions (0) 1 y = & (1)
k
y e = and k=1

To solve this equation by conventional finite difference method we need to convert this
differential equations to difference equations using:
0
( ) ( )
( ) lim
h
f x h f x
f x
h

+
' = , And
2
0
( ) 2 ( ) ( )
( ) lim
h
f x h f x f x h
f x
h

+ +
'' =
Or say
1 1
2
2
( )
i i i
i
y y y
y x
h
+
+
'' = where
1 1
( )
i i
y y x
+ +
= (value of y at
1 i
x
+
),
i
x denotes the grid
points where we have to evaluate the value of differential equation and denotes space
between these grid points.
Then our differential equation will become:
=>
2 1 1
2
2
0
i i i
i
y y y
k y
h
+
+
=
Or,
2 2
1 1
(2 ) 0
i i i
y k h y y
+
+ + = --------------------- <02>
Let we have to solve this differential equation in interval [0, 1], here we can discretise
our data in as many interval we want by choosing appropriate value of h .
And get points as
i
x ih = where i =0, 1, 2,
Let h =0.25 then from equation 02 we get set of algebraic equations as:
2 2
2 1 0
(2 (0.25) ) 0 y k y y + + =
2 2
3 2 1
(2 (0.25) ) 0 y k y y + + =
2 2
4 3 2
(2 (0.25) ) 0 y k y y + + =
2 2
5 4 3
(2 (0.25) ) 0 y k y y + + =
Now writing these set of equations in matrix form as:
Ay B =

And then after putting boundary conditions and solving the matrix equation for y we
get our desired result.
12


2.1.1 Matlab codes for solving this differential equations
clc; clear;
A=input('enter lower limit');
B=input('enter upper limit');
h=input('enter value of h');
K=input('enter value of k');
P=(B-A)/h+1;
for i=0:P-1
Q(i+1)=A+i*h;
end
for i=1:P+1;
E(i,i)=1;
E(i,i+1)=-2;
E(i,i+2)=1;
end
E=E./(h^2);
E=E(1:P,2:P+1);
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
% solving differential equation starts here
R=E; I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K^2).*I(k,k);
end
m=R-L;
j=1; p=P;
y(j)=a; y(p)=b; e=zeros(1,P);
c=zeros(1,P); d=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1);
c=c';
q=m;
q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
plot (Q,abs(O));


13










Table 1: solution of differential equations
2
2
2
0
d y
k y
dx
=
by CFDM

Graph 1: Solution of given differential equation by conventional finite difference
method



x Calculated
y
Exact y Error
0 1.0000 1.0000 0
0.25 1.2847 1.2840 0.0006803
0.50 1.6497 1.6487 0.0009844
0.75 2.1178 2.1170 0.0008121
1.0 2.7183 2.7183 0
0
0.5
1
1.5
2
2.5
3
0 0.2 0.4 0.6 0.8 1 1.2
y
-
v
a
l
u
e
x-value
solution of
14




2.2. Methods for solving differential equations by SFDM:
WE can solve the same problem by spectral finite difference methods:
Our differential equation is:
2
2
2
0
d y
k y
dx
=
.. <01>
With boundary conditions (0) 1 y = & (1)
k
y e = and k=1

To solve the given equation by spectral finite difference methods we have to choose
an interpolant ( ) ( )
i i
y x L x y =

such that it satisfy the differential equation.


Then we can write ( ) ( )
i i
y x L x y ' ' =

and ( ) ( )
i i
y x L x y '' '' =


Now on putting value of ( ) y x '' and ( ) y x in equation (01) we get a matrix in form:
Ay B =
.
And then after putting boundary conditions and solving the matrix equation for y we
get our desired result.










15


2.2.1 Matlab codes for solving this differential equations by SFDM:

clc; clear;
A=input('enter lower limit');
B=input('enter upper limit');
h=input('enter value of h');
K=input('enter value of k');
P=(B-A)/h+1;
for i=0:P-1
Q(i+1)=A+i*h;
end
E=interpolant_raj(Q); % this function provides D-matrix
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
% solving differential equation starts here
R=E^(2); I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K^2).*I(k,k);
end
m=R-L;
j=1; p=P;
y(j)=a; y(p)=b; e=zeros(1,P);
c=zeros(1,P); d=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1);
c=c';
q=m;
q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
plot (Q,O);




16

2.2.2 Matlab code for function interpolant_raj.
function E=interpolant_raj(T) % T is vector containing points where we
have to interpolate
% E is D matrix
x=T; s=x;
[~, n]=size(x);
A=zeros(1,n); D=zeros(1,n);
B=ones(1,n); E=zeros(n,n);
k=1;
for j=1:n

for i=1:n
if i~=j
A(k)=A(k)+1/(s(j)-x(i));
B(k)=B(k).*(s(j)-x(i));
D(k)=B(k).*A(k);
E(k,k)=A(k);
end

end
k=k+1;
end

G=ones(n,n); k=1;
if n>2
for j=1:n
l=1:n;
l(:,j)=[];
m=1;
for v=1:n-1
z=l(v);
for i=1:n
if i~=j && i~=z
G(k,m)=G(k,m).*(s(j)-x(i));
E(k,z)=G(k,m)./B(z);
end

end
m=m+1;
end
k=k+1;
end
else

for j=1:n
l=1:n;
l(:,j)=[];
m=1;
for v=1:n-1
z=l(v);
for i=1:n
E(k,z)=G(k,m)./B(z);
end
m=m+1;
end
k=k+1;
end
end
17










Table 2: solution of differential equations
2
2
2
0
d y
k y
dx
=
by SFDM



Graph 2: Solution of given differential equation by SFDM


X Calculated y Exact y Error
0
1.000000000000000 1.000000000000000 0
0.25

1.283972703420206

1.284025416687741
0.00005271
0.50

1.648733207743882

1.648721270700128
-0.00001193
0.75

2.117079044491258

2.117000016612675
-0.00007902
1.0

2.718281828459046

2.718281828459046
0
0
0.5
1
1.5
2
2.5
3
0 0.2 0.4 0.6 0.8 1 1.2
y
-
v
a
l
u
e
s
x-values
Solution of D.E.
18

2.3. Solving Problem on Half-space with different number of grid
points and comparing results:
Let our differential equation be
2
2
2
0
d E
k E
dx
+ = this differential equation is arises due
to decay of electric field when it pass through earth surface of different conductivity.
Here
2
k jeo = where o = earth conductivity, = Permeability having value,
=
7
4 10 t

and e = angular frequency.


2.3.1. Conventional finite difference method:
For solving this differential equation by conventional finite difference method we will
first need to discretise the interval [0, 3000] into number of subinterval. Let h be gap
between two consecutive subintervals and N denotes number of subintervals.
2.3.1.1 Matlab code to check what happens when we increase number of grid
points (N) in CFDM.
Clc
clear
n=input('enter number of earth layer');
H=zeros(1,n); N=zeros(1,n);
for i=1:n
H(i)=input('Enter Depth of layers');

end
M=input('enter frequency');
M=M*8*(pi)^2*(1e-07);
S=zeros(1,n);
for i=1:n
S(i)=input('Enter sigma for each layer');
end
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
%h=input('enter h');
for N=3:3:30

h=H/N ;


[Q P]=points_raj_finite(n,h,H,N);

K=earths_k(n,M,S,N,Q,P);
for i=1:P+1;
E(i,i)=1;
E(i,i+1)=-2;
E(i,i+2)=1;
end
E=E./(h^2);
19

E=E(1:P,2:P+1);

% solving differential equation starts here
R=E; I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K(k)).*I(k,k);
end
m=R+(L*1i);
j=1; p=P;
y(j)=a; y(p)=b; e=zeros(1,P);
c=zeros(1,P); d=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1);
c=c';
q=m;
q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
T=(exp(1i*Q*(K(1)*1i)^(1/2)));
J=abs(T);
error = norm(J-abs(O),inf);
loglog(N,error,'marker','*');
hold on
end
grid on, xlabel N, ylabel error
title('Convergence of conventional finite difference method')


For:
Number of earth layer,(n)=1
Depth of layer=3000
Frequency=1
Sigma=1
Enter boundary conditions
Initial condition (0) E =1
Final condition (3000) E =0

20


Graph 3: Variation in error as we increase number of grid points in conventional finite
difference method

2.3.2. Spectral finite difference method:
For solving this differential equation by spectral finite difference method we will first
discretise the interval [0, 3000] into number of subinterval. Let h be gap between two
consecutive subintervals and N denotes number of subintervals.
2.3.2.1 Matlab code to check what happens when we increase number of grid
points (N) in SFDM.
Clc
clear
n=input('enter number of earth layer');
H=zeros(1,n); N=zeros(1,n);
for i=1:n
H(i)=input('Enter Depth of layers');

end
M=input('enter frequency');
M=M*8*(pi)^2*(1e-07);
S=zeros(1,n);
for i=1:n
S(i)=input('Enter sigma for each layer');
21

end
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
%h=input('enter h');
for N=3:3:30

h=H/N ;


[Q P]=points_raj_finite(n,h,H,N);

K=earths_k(n,M,S,N,Q,P);
E=interpolant_raj(Q);

% solving differential equation starts here
R=E^2; I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K(k)).*I(k,k);
end
m=R+(L*1i);
j=1; p=P;
y(j)=a; y(p)=b; e=zeros(1,P);
c=zeros(1,P); d=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1);
c=c';
q=m;
q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
T=(exp(1i*Q*(K(1)*1i)^(1/2)));
J=abs(T);
error = norm(J-abs(O),inf);
loglog(N,error,'marker','*');
hold on
end
grid on, xlabel N, ylabel error
title('Convergence of spectral finite difference method')


22




For:
Number of earth layer,(n)=1
Depth of layer=3000
Frequency=1
Sigma=1
Enter boundary conditions
Initial condition (0) E =1
Final condition (3000) E =0


Graph 4: Variation in error as we increase number of grid points in SFDM




23


2.3.2.2 Matlab code for function points_raj_finite(n,h,H,N):
function [Q P]=points_raj_finite(n,h,H,N)
% n is scalar having number of earth layer
% H is vector containing Depth of each layers from the end of last one
% N is vector containing number of points we want to calculate in each
% layer
% Q is vector containing coordinate of interpolated points
% P is scalar having total number of points
y=zeros(n,N(n));

for i=1:N(1)
y(1,i)=i*h;

end

for i=1:(n-1)
a=0;
for l=1:i
a=a+H(l);
end
for k=1:N(i+1)+1

y(i+1,k)=a+(k)*h;

end
end
P=sum(N)+1; k=2; Q(1)=0;
for j=1:n
for i=1:N(j)
Q(k)=y(j,i);
k=k+1;
end
end










24



2.3.2.3 Matlab code for function earths_k:
function K=earths_k(n,M,S,N,Q,P)
j=1;K=zeros(1,P);
% N is vector containing number of points we want to calculate in each
% layer
% n is scalar having number of earth layer
% Q is vector containing coordinate of interpolated points
% P is scalar having total number of points
% K is vector having value of K for each corresponding points in Q
% M Define (i*w*miu) here (scalar product of j,omega,miu)
% S define sigma (vector(1,n) sigma for different layer)
for i=1:N(1)
K(i)=M*S(j);
end
h=N(1); a=2;
for j=1:n-1
v=h+a;
h=h+N(j+1);
for i=v:h
K(i)=M*S(j+1);
end
end
a=1;
for j=1:n-1

K(N(j)+a)=M*((S(j)*(Q(N(j)+a)-Q(N(j)+a-1))+S(j+1)*(Q(N(j)+a+1)-
Q(N(j)+a)))/(Q(N(j)+a)-Q(N(j)+a-1)+Q(N(j)+a+1)-Q(N(j)+a)));
a=a+N(j);
end


Comparison of error of CFDM and SFDM:
From Graph 3 and Graph 4 we can conclude that Spectral finite difference method
provide error of approx.
3
10

with only 9 grid points while conventional finite difference


method with 20 grid points and more.





25


2.4. Layered earth Problem:
Solving nonlinear differential equations arises due to Layered earth of different
conductivity by numerical methods:
Let us consider one example to understand this method.
Let our differential equation be
2
2
2
0
d E
k E
dx
+ = this differential equation is arises due to
decay of electric field when it pass through earth surface of different conductivity.
Here
2
k jeo = where o = earth conductivity, = Permeability, having value
=
7
4 10 t

and e = angular frequency
In this differential equation since for different earth layer o is different or say o is
function of x therefore
2
k will be function of x .
We will solve this differential equation by conventional finite difference method and
spectral finite difference method and compare the results.
2.4.1. Conventional finite difference method:
For solving this differential equation by conventional finite difference method we will
first need to discretise the interval [0, 3000] into number of subinterval. Let h be gap
between two consecutive subintervals and N denotes number of subintervals.
2.4.1.1 Matlab code for solving this differential equation by CFDM:
clc
clear
n=input('enter number of earth layer');
H=zeros(1,n); N=zeros(1,n);
h=input('enter h');
for i=1:n
H(i)=input('Enter Depth of layers');
N(i)=H(i)/h ;
end
[Q P]=points_raj_finite(n,h,H,N);
M=input('enter frequency');
M=M*8*(pi)^2*(1e-07);
S=zeros(1,n);
for i=1:n
S(i)=input('Enter sigma for each layer');
end
K=earths_k(n,M,S,N,Q,P);
for i=1:P+1;
E(i,i)=1;
26

E(i,i+1)=-2;
E(i,i+2)=1;
end
E=E./(h^2);
E=E(1:P,2:P+1);
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
% solving differential equation starts here
R=E; I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K(k)).*I(k,k);
end
m=R+(L*1i);
j=1; p=P;
y(j)=a; y(p)=b; e=zeros(1,P);
c=zeros(1,P); d=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1);
c=c';
q=m;
q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
plot (Q,abs(O),'marker','*');
grid on, xlabel Depth-from-earth, ylabel Electric-field
title(['Calulation using finite difference D-Matrix for h=',num2str(h)])








27

2.4.2. Spectral finite difference method:
For solving this differential equation by Spectral finite difference method we will first
need to discretise the interval [0, 3000] into number of subinterval. Let h be gap
between two consecutive subintervals and N denotes number of subintervals.
2.4.2.1 Matlab code for solving this differential equation by SFDM:
Clc; clear;
n=input('enter number of earth layer');
H=zeros(1,n); N=zeros(1,n);
h=input('enter h');
for i=1:n
H(i)=input('Enter Depth of layers');
N(i)=H(i)/h ;
end
[Q P]=points_raj_finite(n,h,H,N);
M=input('enter frequency');
M=M*8*(pi)^2*(1e-07); S=zeros(1,n);
for i=1:n
S(i)=input('Enter sigma for each layer');
end
K=earths_k(n,M,S,N,Q,P);
E=interpolant_raj(Q);
disp('Enter boundary conditions');
a=input('Enter initial condition');
b=input('Enter final condition');
% solving differential equation starts here
R=E^2; I=eye(P);L=zeros(P,P);
for k=1:P
L(k,k)=(K(k)).*I(k,k);
end
m=R+(L*1i);
j=1; p=P; c=zeros(1,P); d=zeros(1,P); y(j)=a; y(p)=b; e=zeros(1,P);
for i=1:P;
e(i)=-1*(m(i,j)*y(j));
end
for i=1:P;
d(i)=-1*(m(i,p)*y(p));
end
for i=1:P;
c(i)=e(i)+d(i);
end
c=c(2:P-1); c=c'; q=m; q=q(2:P-1,2:P-1);
l=q\c; O=zeros(1,P);
for i=1:P
if i==1
O(1)=y(j);
elseif i==P
O(P)=y(p);
else
O(i)=l(i-1);
end
end
plot (Q,abs(O),'marker','*');
grid on, xlabel Depth-from-earth, ylabel Electric-field
title(['Calulation using Spectral finite difference method D-Matrix for
h=',num2str(h)])
28

For:
Number of earth layer,(n)=2
Depth of 1
st
layer=1500
Depth of 2
nd
layer=1500
Frequency=1
Sigma
1
o =1 and
2
o =0.8
Enter boundary conditions
Initial condition (0) E =1
Final condition (3000) E =0

Comparing Accuracy of conventional finite difference and spectral finite difference
method with different number of grid points
Conventional finite difference method Spectral
conventional finite
difference method
N=10 N=30 N=50 N=10
x E x E x E x E
0
300
600
900
1200
1500
1800
2100
2400
2700
3000
1
0.5421
0.2935
0.1589
0.0871
0.0494
0.0289
0.0173
0.0102
0.0049
0
0
100
200
300
400
500
600
700
800
900
1000
1100
1200
1300
1400
1500
1600
1700
1800
1900
2000
2100
2200
2300
2400
1
0.8193
0.6712
0.5499
0.4504
0.3688
0.302
0.2472
0.2023
0.1657
0.1358
0.1115
0.0919
0.0761
0.0633
0.0529
0.0443
0.0372
0.0313
0.0264
0.0223
0.019
0.0161
0.0136
0.0114
0
60
120
180
240
300
360
420
480
540
600
660
720
780
840
900
960
1020
1080
1140
1200
1260
1320
1380
1440
1
0.8875
0.7877
0.699
0.6204
0.5505
0.4885
0.4335
0.3846
0.3412
0.3027
0.2685
0.2382
0.2112
0.1874
0.1663
0.1476
0.131
0.1165
0.1036
0.0923
0.0824
0.0737
0.066
0.0593
0
300
600
900
1200
1500
1800
2100
2400
2700
3000
1
0.5557
0.3053
0.1678
0.0937
0.0546
0.0327
0.0188
0.0083
0.0034
0
29

2500
2600
2700
2800
2900
3000
0.0094
0.0074
0.0055
0.0037
0.0018
0
1500
1560
1620
1680
1740
1800
1860
1920
1980
2040
2100
2160
2220
2280
2340
2400
2460
2520
2580
2640
2700
2760
2820
2880
2940
3000
0.0533
0.0479
0.0431
0.0388
0.035
0.0315
0.0285
0.0257
0.0233
0.0211
0.0191
0.0173
0.0157
0.0142
0.0128
0.0115
0.0103
0.009
0.0079
0.0067
0.0056
0.0045
0.0034
0.0022
0.0011
0

Table 3: Solution of differential equation
2
2
2
0
d E
k E
dx
+ = with different number of grid points (N).
From the above table we can conclude that spectral finite difference methods give
better results with less number of grid points while conventional finite difference
method give the same result with at least 3 to 5 times number of grid points that
required by spectral finite difference methods.





30


























Conclusion
31

[01]. All differential equations associated with real physical problems are not easily
solved with analytical methods so we need numerical methods to solve them.
[02]. We have compared the results of two numerical methods to solve our differential
equations:
(01). Conventional finite difference method
(02). Spectral finite difference method
[03]. Spectral finite difference methods give better results than conventional finite
difference method.
[04]. Spectral finite difference methods require less number of grid points as compared
conventional finite difference method to solve a problem with the same accuracy.

















32



























References
33

[01] Trefethen, L.N,(2000), Spectral methods in Matlab, SIAM publication.
[02]. Abramowitz and Stegun, (1972), Handbook of Mathematical Function, National
Bureau of Standards
[03]. Gilberto E. Urroz,( 2004), Numerical Solution to Ordinary Differential Equations
[04]. http://en.wikipedia.org/wiki/Finite_difference_method
[05]. http://www.engr.sjsu.edu/trhsu/Chapter%209%20Intro%20to%20FDM.pdf
[06]. http://en.wikipedia.org/wiki/Spectral_method
[07]. http://en.wikipedia.org/wiki/Finite_difference
[08]. http://www.csc.kth.se/utbildning/kth/kurser/DN2266/matmod11/Fourier3_2p.pdf
[09]. maths-people.anu.edu.au/~mike/NQinODE.pdf
[10]. tutorial.math.lamar.edu/Classes/DE/BoundaryValueProblem.aspx
[11].http://www.cdeep.iitb.ac.in/nptel/Mechanical/Heat%20and%20Mass%20Transfer
/Conduction/Module%205/main/5.1.html
[12]. en.wikipedia.org/wiki/Differential_equation
[13].https://www.whitman.edu/mathematics/multivariable/multivariable_17_Differentia
l_Equations.pdf

[14]. F. N. van de Vosse P. D. Minev ,Spectral element methods: theory and
applications (w3.pppl.gov/m3d/reference/se5_nov_28_07.pdf)

[15]. Katarina Gustavsson, Spectral differentiation
(www.math.nus.edu.sg/~matgkv/Lecture5.pdf)

[16]. A.N. Malyshev,On the spectral differentiation
(www.ii.uib.no/~sasha/INF263/spectral.pdf)

[17]. Lu Yixin , Introduction to Spectral conventional finite difference methods,
September 26, 2007

[18]. ms.mcmaster.ca/~bprotas/CES712a/diff_02_4.pdf

Anda mungkin juga menyukai