1. PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
2. OBJECTIVE
1. Create an M-file to implement
finite difference method for solving ODE.
2.Plot the exact and numerical solution.
3. Theory
Finite-Difference Methods (FDM) are numerical methods for solving
differential equations by approximating them with difference equations, in
which finite differences approximate the derivatives. FDMs are thus
discretization methods. FDMs convert a linear (non-linear) ODE (Ordinary
Differential Equations) into a system of linear (non-linear) equations, which
can then be solved by matrix algebra techniques. The reduction of the
differential equation to a system of algebraic equations makes the problem
of finding the solution to a given ODE ideally suited to modern computers,
hence the widespread use of FDMs in modern numerical analysis. The
quality and duration of simulated FDM solution depends on the
discretization equation selection and the step sizes (time and space
steps). The data quality and simulation duration increase significantly with
smaller step size.
4. Script File
a=0;b=1;
n=10;
dx=(b-a)/n;
x=a:dx:b;
A=sparse(n+1,n+1);
A(1,1)=1;
for i=2:n
A(i,[i-1 i i+1])=[1 -2 1];
end
A(n+1,n-1)=1;
%Right=hand side, B(1) and B(n+1) are initial
and final values
B=zeros(n+1,1);
B(1)=0;
B(2:n)=12.*x(2:n).^2.*dx^2;
B(n+1)=0;
%Solving the system
U=AB
%Comparing with exact solution
xf=a:1/1000:b;
yf=xf.^4-xf;
plot(x,U,'O',xf,yf)
xlabel('x'); grid on;
legend('Finite Diff','Exact')
5. Methodology
Given boundary value problem y’’=12x2 y(0)=y(1)=0
with exact soln= x4-x
Now we have j+1 linear equation
of j+1 unknowns to solve matrix
AY=B
7. Conclusion
• The difference system obtained above has a unique
solution
• Difference system is strictly diagonally dominant
• To estimate the error in the numerical solution of BVP by
finite difference method we first define the local
truncation error in Tj, as an approximation to L, for any
smooth function , by for
1<j<J
• The difference scheme given above has been shown to
yield an approximation to the solution of the BVP to
8. References
• Class Notes by Prof. S.C. Pandey Sir
• MATLAB documentation
• https://nptel.ac.in/content/storage2/courses/111
104030/pdf_lectures/lecture38.pdf