SlideShare a Scribd company logo
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:06/08/2014
Roorkee, Uttarakhand
Date: 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 11th
June 2014 to 06th
August 2014.
(Dr. Pravin Kumar Gupta)
Acknowledgement
I would like to thank Dr. Pravin Kumar Gupta for the continuous guidance
and patience. Being my 1st
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 CFDM………………………12
2.2. Methods for solving D.E. by SFDM…………………………14
2.2.1. Matlab code for solving D.E by SFDM………………………15
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 CFDM………………………………………18
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 40y 
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 2y t C   
=> ln 25 2y 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
20
( ) 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 jf x u
Where ju is corresponding value of function at jx
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) 1y  & (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
20
( ) 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 iy y x  (value of y at 1ix  ), ix 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:
=> 21 1
2
2
0i i i
i
y y y
k y
h
  
 
Or, 2 2
1 1(2 ) 0i i iy 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 ix 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) ) 0y k y y   
2 2
3 2 1(2 (0.25) ) 0y k y y   
2 2
4 3 2(2 (0.25) ) 0y k y y   
2 2
5 4 3(2 (0.25) ) 0y 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=qc; 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-value
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) 1y  & (1) k
y e and k=1
To solve the given equation by spectral finite difference methods we have to choose
an interpolant ( ) ( )i iy x L x y  such that it satisfy the differential equation.
Then we can write ( ) ( )i iy x L x y   and ( ) ( )i iy 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=qc; 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-values
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 j where  = earth conductivity,  = Permeability having value,
 = 7
4 10 
 and  = 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=qc; 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=qc; 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 j where  = earth conductivity,  = Permeability, having value
 = 7
4 10 
 and  = angular frequency
In this differential equation since for different earth layer  is different or say  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=qc; 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=qc; 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 1st
layer=1500
Depth of 2nd
layer=1500
Frequency=1
Sigma 1 =1 and 2 =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

More Related Content

What's hot

Graph Theory
Graph TheoryGraph Theory
Graph Theory
Prateek Pandey
 
Power series
Power series Power series
Power series
Pranav Veerani
 
Complex form fourier series
Complex form fourier seriesComplex form fourier series
Complex form fourier series
derry92
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
Amr E. Mohamed
 
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONSAPPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
AYESHA JAVED
 
Trapezoidal Method IN Numerical Analysis
Trapezoidal Method IN  Numerical AnalysisTrapezoidal Method IN  Numerical Analysis
Trapezoidal Method IN Numerical Analysis
Mostafijur Rahman
 
linear transformation
linear transformationlinear transformation
linear transformation
mansi acharya
 
PROPERTIES OF LAPLACE TRANSFORM
PROPERTIES OF LAPLACE TRANSFORMPROPERTIES OF LAPLACE TRANSFORM
PROPERTIES OF LAPLACE TRANSFORM
Ranit Sarkar
 
The method of frobenius
The method of frobeniusThe method of frobenius
Lesson 8: Curves, Arc Length, Acceleration
Lesson 8: Curves, Arc Length, AccelerationLesson 8: Curves, Arc Length, Acceleration
Lesson 8: Curves, Arc Length, Acceleration
Matthew Leingang
 
Differential equations of first order
Differential equations of first orderDifferential equations of first order
Differential equations of first order
vishalgohel12195
 
Sturm liouville problems6
Sturm liouville problems6Sturm liouville problems6
Sturm liouville problems6
Nagu Vanamala
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equation
Nofal Umair
 
Ode powerpoint presentation1
Ode powerpoint presentation1Ode powerpoint presentation1
Ode powerpoint presentation1
Pokkarn Narkhede
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
wraithxjmin
 
Curve sketching
Curve sketchingCurve sketching
Curve sketching
Rnold Wilson
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - Notes
Dr. Nirav Vyas
 
Differential calculus maxima minima
Differential calculus  maxima minimaDifferential calculus  maxima minima
Differential calculus maxima minima
Santhanam Krishnan
 
Laplace transform of periodic functions
Laplace transform of periodic functionsLaplace transform of periodic functions
Laplace transform of periodic functions
Syed Saeed
 
Gamma function
Gamma functionGamma function
Gamma function
Solo Hermelin
 

What's hot (20)

Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Power series
Power series Power series
Power series
 
Complex form fourier series
Complex form fourier seriesComplex form fourier series
Complex form fourier series
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
 
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONSAPPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
APPLICATION OF HIGHER ORDER DIFFERENTIAL EQUATIONS
 
Trapezoidal Method IN Numerical Analysis
Trapezoidal Method IN  Numerical AnalysisTrapezoidal Method IN  Numerical Analysis
Trapezoidal Method IN Numerical Analysis
 
linear transformation
linear transformationlinear transformation
linear transformation
 
PROPERTIES OF LAPLACE TRANSFORM
PROPERTIES OF LAPLACE TRANSFORMPROPERTIES OF LAPLACE TRANSFORM
PROPERTIES OF LAPLACE TRANSFORM
 
The method of frobenius
The method of frobeniusThe method of frobenius
The method of frobenius
 
Lesson 8: Curves, Arc Length, Acceleration
Lesson 8: Curves, Arc Length, AccelerationLesson 8: Curves, Arc Length, Acceleration
Lesson 8: Curves, Arc Length, Acceleration
 
Differential equations of first order
Differential equations of first orderDifferential equations of first order
Differential equations of first order
 
Sturm liouville problems6
Sturm liouville problems6Sturm liouville problems6
Sturm liouville problems6
 
First order linear differential equation
First order linear differential equationFirst order linear differential equation
First order linear differential equation
 
Ode powerpoint presentation1
Ode powerpoint presentation1Ode powerpoint presentation1
Ode powerpoint presentation1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Curve sketching
Curve sketchingCurve sketching
Curve sketching
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - Notes
 
Differential calculus maxima minima
Differential calculus  maxima minimaDifferential calculus  maxima minima
Differential calculus maxima minima
 
Laplace transform of periodic functions
Laplace transform of periodic functionsLaplace transform of periodic functions
Laplace transform of periodic functions
 
Gamma function
Gamma functionGamma function
Gamma function
 

Similar to Spectral methods for solving differential equations

Numerical Solutions of Burgers' Equation Project Report
Numerical Solutions of Burgers' Equation Project ReportNumerical Solutions of Burgers' Equation Project Report
Numerical Solutions of Burgers' Equation Project Report
Shikhar Agarwal
 
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
cscpconf
 
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
ieijjournal
 
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
ieijjournal
 
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
IRJET Journal
 
Numerical solution of linear volterra fredholm integro-
Numerical solution of linear volterra fredholm integro-Numerical solution of linear volterra fredholm integro-
Numerical solution of linear volterra fredholm integro-
Alexander Decker
 
Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology
Amro Elfeki
 
Numerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi scheme
xingangahu
 
Numerical Solution of Diffusion Equation by Finite Difference Method
Numerical Solution of Diffusion Equation by Finite Difference MethodNumerical Solution of Diffusion Equation by Finite Difference Method
Numerical Solution of Diffusion Equation by Finite Difference Method
iosrjce
 
arijit ppt (1) (1).pptx
arijit ppt (1) (1).pptxarijit ppt (1) (1).pptx
arijit ppt (1) (1).pptx
RadharamanRoy3
 
article_imen_ridha_2016_version_finale
article_imen_ridha_2016_version_finalearticle_imen_ridha_2016_version_finale
article_imen_ridha_2016_version_finale
Mdimagh Ridha
 
least squares approach in finite element method
least squares approach in finite element methodleast squares approach in finite element method
least squares approach in finite element method
sabiha khathun
 
H023078082
H023078082H023078082
H023078082
inventionjournals
 
H023078082
H023078082H023078082
H023078082
inventionjournals
 
vj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pbvj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pb
Engr M Javaid
 
hankel_norm approximation_fir_ ijc
hankel_norm approximation_fir_ ijchankel_norm approximation_fir_ ijc
hankel_norm approximation_fir_ ijc
Vasilis Tsoulkas
 
lec_slides.pdf
lec_slides.pdflec_slides.pdf
lec_slides.pdf
MalluKomar
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptx
SayedulHassan1
 
NPDE-TCA
NPDE-TCANPDE-TCA
NPDE-TCA
rishav rai
 
Some Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial DerivativesSome Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial Derivatives
SanjaySingh011996
 

Similar to Spectral methods for solving differential equations (20)

Numerical Solutions of Burgers' Equation Project Report
Numerical Solutions of Burgers' Equation Project ReportNumerical Solutions of Burgers' Equation Project Report
Numerical Solutions of Burgers' Equation Project Report
 
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
EXACT SOLUTIONS OF A FAMILY OF HIGHER-DIMENSIONAL SPACE-TIME FRACTIONAL KDV-T...
 
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
 
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
FITTED OPERATOR FINITE DIFFERENCE METHOD FOR SINGULARLY PERTURBED PARABOLIC C...
 
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
 
Numerical solution of linear volterra fredholm integro-
Numerical solution of linear volterra fredholm integro-Numerical solution of linear volterra fredholm integro-
Numerical solution of linear volterra fredholm integro-
 
Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology Lecture 5: Stochastic Hydrology
Lecture 5: Stochastic Hydrology
 
Numerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi scheme
 
Numerical Solution of Diffusion Equation by Finite Difference Method
Numerical Solution of Diffusion Equation by Finite Difference MethodNumerical Solution of Diffusion Equation by Finite Difference Method
Numerical Solution of Diffusion Equation by Finite Difference Method
 
arijit ppt (1) (1).pptx
arijit ppt (1) (1).pptxarijit ppt (1) (1).pptx
arijit ppt (1) (1).pptx
 
article_imen_ridha_2016_version_finale
article_imen_ridha_2016_version_finalearticle_imen_ridha_2016_version_finale
article_imen_ridha_2016_version_finale
 
least squares approach in finite element method
least squares approach in finite element methodleast squares approach in finite element method
least squares approach in finite element method
 
H023078082
H023078082H023078082
H023078082
 
H023078082
H023078082H023078082
H023078082
 
vj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pbvj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pb
 
hankel_norm approximation_fir_ ijc
hankel_norm approximation_fir_ ijchankel_norm approximation_fir_ ijc
hankel_norm approximation_fir_ ijc
 
lec_slides.pdf
lec_slides.pdflec_slides.pdf
lec_slides.pdf
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptx
 
NPDE-TCA
NPDE-TCANPDE-TCA
NPDE-TCA
 
Some Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial DerivativesSome Engg. Applications of Matrices and Partial Derivatives
Some Engg. Applications of Matrices and Partial Derivatives
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 

Spectral methods for solving differential equations

  • 1. 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
  • 2. 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:06/08/2014 Roorkee, Uttarakhand Date: 06/08/2014
  • 3. 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 11th June 2014 to 06th August 2014. (Dr. Pravin Kumar Gupta)
  • 4. Acknowledgement I would like to thank Dr. Pravin Kumar Gupta for the continuous guidance and patience. Being my 1st 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
  • 5. 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 CFDM………………………12 2.2. Methods for solving D.E. by SFDM…………………………14 2.2.1. Matlab code for solving D.E by SFDM………………………15 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 CFDM………………………………………18 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
  • 7. 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 40y  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 2y t C    => ln 25 2y 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. 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 20 ( ) 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. 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 jf x u Where ju is corresponding value of function at jx Here we are free to choose ( )n x , ( )n x can be either (i) trigonometric, (ii) exponentials or (iii) Simple combinations of polynomials.
  • 11. 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) 1y  & (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 20 ( ) 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 iy y x  (value of y at 1ix  ), ix 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: => 21 1 2 2 0i i i i y y y k y h      Or, 2 2 1 1(2 ) 0i i iy 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 ix 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) ) 0y k y y    2 2 3 2 1(2 (0.25) ) 0y k y y    2 2 4 3 2(2 (0.25) ) 0y k y y    2 2 5 4 3(2 (0.25) ) 0y 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. 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=qc; 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. 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-value x-value solution of
  • 14. 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) 1y  & (1) k y e and k=1 To solve the given equation by spectral finite difference methods we have to choose an interpolant ( ) ( )i iy x L x y  such that it satisfy the differential equation. Then we can write ( ) ( )i iy x L x y   and ( ) ( )i iy 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. 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=qc; 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. 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. 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-values x-values Solution of D.E.
  • 18. 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 j where  = earth conductivity,  = Permeability having value,  = 7 4 10   and  = 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. 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=qc; 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. 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. 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=qc; 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. 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. 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. 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. 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 j where  = earth conductivity,  = Permeability, having value  = 7 4 10   and  = angular frequency In this differential equation since for different earth layer  is different or say  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. 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=qc; 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. 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=qc; 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. 28 For: Number of earth layer,(n)=2 Depth of 1st layer=1500 Depth of 2nd layer=1500 Frequency=1 Sigma 1 =1 and 2 =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. 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.
  • 31. 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.
  • 33. 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