This document discusses various computational methods for solving partial differential equations (PDEs) using MATLAB. It begins by introducing three types of PDEs - elliptic, parabolic, and hyperbolic - and provides examples of each. It then describes explicit methods like the Forward Time Centered Space (FTCS) method, Lax method, and Crank-Nicolson (CTCS) method for solving the advection equation. The document provides MATLAB code implementing these methods for a test case of solving the advection equation modeling a square wave.
finite difference Method, For Numerical analysis. working matlab code. numeric analysis finite difference method. MATLAB provides tools to solve math. Using linear programing techniques we can easily solve system of equations. This file provides a running code of Finite difference matlab code
FINITE DIFFERENCE MODELLING FOR HEAT TRANSFER PROBLEMSroymeister007
This report provides a practical overview of numerical solutions to the heat equation using the finite difference method (FDM). The forward time, centered space (FTCS), the backward time, centered space (BTCS), and Crank-Nicolson schemes are developed, and applied to a simple problem in1volving the one-dimensional heat equation. Complete, working Matlab and FORTRAN codes for each program are presented. The results of running the codes on finer (one-dimensional) meshes, and with smaller time steps are demonstrated. These sample calculations show that the schemes realize theoretical predictions of how their truncation errors depend on mesh spacing and time step. The Matlab codes are straightforward and allow us to see the differences in implementation between explicit method (FTCS) and implicit methods (BTCS). The codes also allow us to experiment with the stability limit of the FTCS scheme.
finite difference Method, For Numerical analysis. working matlab code. numeric analysis finite difference method. MATLAB provides tools to solve math. Using linear programing techniques we can easily solve system of equations. This file provides a running code of Finite difference matlab code
FINITE DIFFERENCE MODELLING FOR HEAT TRANSFER PROBLEMSroymeister007
This report provides a practical overview of numerical solutions to the heat equation using the finite difference method (FDM). The forward time, centered space (FTCS), the backward time, centered space (BTCS), and Crank-Nicolson schemes are developed, and applied to a simple problem in1volving the one-dimensional heat equation. Complete, working Matlab and FORTRAN codes for each program are presented. The results of running the codes on finer (one-dimensional) meshes, and with smaller time steps are demonstrated. These sample calculations show that the schemes realize theoretical predictions of how their truncation errors depend on mesh spacing and time step. The Matlab codes are straightforward and allow us to see the differences in implementation between explicit method (FTCS) and implicit methods (BTCS). The codes also allow us to experiment with the stability limit of the FTCS scheme.
Numerical Analysis and Its application to Boundary Value ProblemsGobinda Debnath
here is a presentation that I have presented on a webinar. in this presentation, I mainly focused on the application of numerical analysis to Boundary Value problems. I described one of the most useful traditional methods called the finite difference method. those who are interested to do research in applied mathematics, CFD, Numerical analysis may go through it for the basic ideas.
Solving second order ordinary differential equations (boundary value problems) using the Least Squares Technique. Contains one numerical examples from Shah, Eldho, Desai
NUMERICAL METHODS IN STEADY STATE, 1D and 2D HEAT CONDUCTION- Part-IItmuliya
This file contains slides on NUMERICAL METHODS IN STEADY STATE 1D and 2D HEAT CONDUCTION – Part-II.
The slides were prepared while teaching Heat Transfer course to the M.Tech. students in Mechanical Engineering Dept. of St. Joseph Engineering College, Vamanjoor, Mangalore, India, during Sept. – Dec. 2010.
Contents: Methods of solving a system of simultaneous, algebraic equations - 1D steady state conduction in cylindrical and spherical systems - 2D steady state conduction in cartesian coordinates - Problems
Numerical Solution of Diffusion Equation by Finite Difference Methodiosrjce
IOSR Journal of Mathematics(IOSR-JM) is a double blind peer reviewed International Journal that provides rapid publication (within a month) of articles in all areas of mathemetics and its applications. The journal welcomes publications of high quality papers on theoretical developments and practical applications in mathematics. Original research papers, state-of-the-art reviews, and high quality technical notes are invited for publications.
Numerical Analysis and Its application to Boundary Value ProblemsGobinda Debnath
here is a presentation that I have presented on a webinar. in this presentation, I mainly focused on the application of numerical analysis to Boundary Value problems. I described one of the most useful traditional methods called the finite difference method. those who are interested to do research in applied mathematics, CFD, Numerical analysis may go through it for the basic ideas.
Solving second order ordinary differential equations (boundary value problems) using the Least Squares Technique. Contains one numerical examples from Shah, Eldho, Desai
NUMERICAL METHODS IN STEADY STATE, 1D and 2D HEAT CONDUCTION- Part-IItmuliya
This file contains slides on NUMERICAL METHODS IN STEADY STATE 1D and 2D HEAT CONDUCTION – Part-II.
The slides were prepared while teaching Heat Transfer course to the M.Tech. students in Mechanical Engineering Dept. of St. Joseph Engineering College, Vamanjoor, Mangalore, India, during Sept. – Dec. 2010.
Contents: Methods of solving a system of simultaneous, algebraic equations - 1D steady state conduction in cylindrical and spherical systems - 2D steady state conduction in cartesian coordinates - Problems
Numerical Solution of Diffusion Equation by Finite Difference Methodiosrjce
IOSR Journal of Mathematics(IOSR-JM) is a double blind peer reviewed International Journal that provides rapid publication (within a month) of articles in all areas of mathemetics and its applications. The journal welcomes publications of high quality papers on theoretical developments and practical applications in mathematics. Original research papers, state-of-the-art reviews, and high quality technical notes are invited for publications.
Low rank tensor approximation of probability density and characteristic funct...Alexander Litvinenko
Very often one has to deal with high-dimensional random variables (RVs). A high-dimensional RV can be described by its probability density (\pdf) and/or by the corresponding probability characteristic functions (\pcf), or by a function representation. Here the interest is mainly to compute characterisations like the entropy, or
relations between two distributions, like their Kullback-Leibler divergence, or more general measures such as $f$-divergences,
among others. These are all computed from the \pdf, which is often not available directly, and it is a computational challenge to even represent it in a numerically feasible fashion in case the dimension $d$ is even moderately large. It is an even stronger numerical challenge to then actually compute said characterisations in the high-dimensional case.
In this regard, in order to achieve a computationally feasible task, we propose to represent the density by a high order tensor product, and approximate this in a low-rank format.
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Alexander Litvinenko
Talk presented on SIAM IS 2022 conference.
Very often, in the course of uncertainty quantification tasks or
data analysis, one has to deal with high-dimensional random variables (RVs)
(with values in $\Rd$). Just like any other RV,
a high-dimensional RV can be described by its probability density (\pdf) and/or
by the corresponding probability characteristic functions (\pcf),
or a more general representation as
a function of other, known, random variables.
Here the interest is mainly to compute characterisations like the entropy, the Kullback-Leibler, or more general
$f$-divergences. These are all computed from the \pdf, which is often not available directly,
and it is a computational challenge to even represent it in a numerically
feasible fashion in case the dimension $d$ is even moderately large. It
is an even stronger numerical challenge to then actually compute said characterisations
in the high-dimensional case.
In this regard, in order to achieve a computationally feasible task, we propose
to approximate density by a low-rank tensor.
I am Paul G. I am a Mechanical Engineering Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. Matlab, University of Adelaide, Australia. I have been helping students with their homework for the past 10 years. I solve assignments related to Mechanical Engineering.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Mechanical Engineering Assignments.
Stochastic reaction networks (SRNs) are a particular class of continuous-time Markov chains used to model a wide range of phenomena, including biological/chemical reactions, epidemics, risk theory, queuing, and supply chain/social/multi-agents networks. In this context, we explore the efficient estimation of statistical quantities, particularly rare event probabilities, and propose two alternative importance sampling (IS) approaches [1,2] to improve the Monte Carlo (MC) estimator efficiency. The key challenge in the IS framework is to choose an appropriate change of probability measure to achieve substantial variance reduction, which often requires insights into the underlying problem. Therefore, we propose an automated approach to obtain a highly efficient path-dependent measure change based on an original connection between finding optimal IS parameters and solving a variance minimization problem via a stochastic optimal control formulation. We pursue two alternative approaches to mitigate the curse of dimensionality when solving the resulting dynamic programming problem. In the first approach [1], we propose a learning-based method to approximate the value function using a neural network, where the parameters are determined via a stochastic optimization algorithm. As an alternative, we present in [2] a dimension reduction method, based on mapping the problem to a significantly lower dimensional space via the Markovian projection (MP) idea. The output of this model reduction technique is a low dimensional SRN (potentially one dimension) that preserves the marginal distribution of the original high-dimensional SRN system. The dynamics of the projected process are obtained via a discrete $L^2$ regression. By solving a resulting projected Hamilton-Jacobi-Bellman (HJB) equation for the reduced-dimensional SRN, we get projected IS parameters, which are then mapped back to the original full-dimensional SRN system, and result in an efficient IS-MC estimator of the full-dimensional SRN. Our analysis and numerical experiments verify that both proposed IS (learning based and MP-HJB-IS) approaches substantially reduce the MC estimator’s variance, resulting in a lower computational complexity in the rare event regime than standard MC estimators. [1] Ben Hammouda, C., Ben Rached, N., and Tempone, R., and Wiechert, S. Learning-based importance sampling via stochastic optimal control for stochastic reaction net-works. Statistics and Computing 33, no. 3 (2023): 58. [2] Ben Hammouda, C., Ben Rached, N., and Tempone, R., and Wiechert, S. (2023). Automated Importance Sampling via Optimal Control for Stochastic Reaction Networks: A Markovian Projection-based Approach. To appear soon.
All of material inside is un-licence, kindly use it for educational only but please do not to commercialize it.
Based on 'ilman nafi'an, hopefully this file beneficially for you.
Thank you.
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfKamal Acharya
The College Bus Management system is completely developed by Visual Basic .NET Version. The application is connect with most secured database language MS SQL Server. The application is develop by using best combination of front-end and back-end languages. The application is totally design like flat user interface. This flat user interface is more attractive user interface in 2017. The application is gives more important to the system functionality. The application is to manage the student’s details, driver’s details, bus details, bus route details, bus fees details and more. The application has only one unit for admin. The admin can manage the entire application. The admin can login into the application by using username and password of the admin. The application is develop for big and small colleges. It is more user friendly for non-computer person. Even they can easily learn how to manage the application within hours. The application is more secure by the admin. The system will give an effective output for the VB.Net and SQL Server given as input to the system. The compiled java program given as input to the system, after scanning the program will generate different reports. The application generates the report for users. The admin can view and download the report of the data. The application deliver the excel format reports. Because, excel formatted reports is very easy to understand the income and expense of the college bus. This application is mainly develop for windows operating system users. In 2017, 73% of people enterprises are using windows operating system. So the application will easily install for all the windows operating system users. The application-developed size is very low. The application consumes very low space in disk. Therefore, the user can allocate very minimum local disk space for this application.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
2. Mehboob, K
NE: 402 computation Method in Nuclear
Engineering
Department of Nuclear Engineering,
KAU, Jeddah, KSA
2017. 5. 1
How to solve 1st Order PDEs
using MATLAB
2
4. PDE (Partial Differential Equation)
PDEs are used as mathematical models for phenomena in
all branches of engineering and science.
2 2 2
2 2
2 ( , , , , )
u u u u u
A B C D x t u
t xt x t x
u u
and
t x
linear in
- Three Types of PDEs:
1) Elliptic:
Steady heat transfer, flow and diffusion
2) Parabolic:
Transient heat transfer, flow and diffusion
3) Hyperbolic:
Transient wave equation
2
0B AC
2 2
2 2 0u u
x y
Laplace equations
2
0B AC
2
2
u uD
t x
Diffusion Equation
2
0B AC 2 2
2 2 2
1u u
x c t
Wave Equation
4
5. Similarity method to solve PDE
often the solution of a PDE together wit its initial and boundary problem depends upon its
variables. In such cases the problem can be reduce to the combination ODEs with its
independent variables
The key to the similarity solution is the diffusing equation is that both the equations and
initial and boundary conditions are under the scaling x→lx and t →l2x.
Therefore, x/√t is independent transformation. In general the function should be of
form
The u(x,t)=U(z)
2
2
u u
t x
, 0t x
( , ) 1 0
( , ) 0 0
u x t t
u x t x
( / )u t f x t
x
t
2
2
1 0
2
U U
(0) 1
( ) 0
U
U
2
/4
0
( ) s
U C e ds D
2
/41( ) s
U e ds
2
/4
/
1( , ) s
x t
u x t e ds
5
6. FTCS method for Advection Eq
Advection equation
The Forward time and central space (FTCS)
method implementation
,
0,1........
0,1........
( , )
n o n
j o n
n j n j
x x n x n N
t t j x j t
u u x t
, 1 , 1, 1,
2
n j n j n j n j
u u u u
c
t x
0u uc
t x
FTCS is explicit scheme
, 1 , 1, 1,
( )
2n j n j n j n j
c tu u u u
x
6
7. Implementation in MATLAB
FTCS is explicit scheme
Square-wave Test for the Explicit Method to solve the Advection Equation
clear;
% Parameters to define the advection equation and the range in space and time
Lmax = 1.0; % Maximum length
Tmax = 1.0; % Maximum time
c = 1.0; % Advection velocity
% Parameters needed to solve the equation within the explicit method
maxt = 3000; % Number of time steps
dt = Tmax/maxt;
n = 30; % Number of space steps
nint=15; % The wave-front: intermediate point from which u=0
dx = Lmax/n;
b = c*dt/(2.*dx);
% Initial value of the function u (amplitude of the wave)
for i = 1:(n+1)
if i < nint
u(i,1)=1.;
else
u(i,1)=0.;
end
x(i) =(i-1)*dx;
end
% Value of the amplitude at the boundary
for k=1:maxt+1
u(1,k) = 1.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit method
for k=1:maxt % Time loop
for i=2:n % Space loop
u(i,k+1) =u(i,k)-b*(u(i+1,k)-u(i-1,k));
end
end
% Graphical representation of the wave at different selected times
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,50),'-',x,u(:,100),'-')
title('Square-wave test within the Explicit Method I')
xlabel('X')
ylabel('Amplitude(X)')
0u uc
t x
( , ) 1 0
( , ) 0 0
u x t t
u x t x
7
0.025
2
c t
x
8. FTSC Lax method for Advection Eq
Advection equation
To increase the stability of FTCS method simply
talke the average of term u(n,j) ,
0,1........
0,1........
( , )
n o n
j o n
n j n j
x x n x n N
t t j x j t
u u x t
0u uc
t x
FTCS is explicit scheme, 1 , 1, 1,
( )
2n j n j n j n j
c tu u u u
x
1, 1,
,
( )
2
n j n j
n j
u u
u
1, 1,
, 1 1, 1,
( )
( )
2 2
n j n j
n j n j n j
u u c tu u u
x
LEX method (explicit)
8
9. Implementation in MATLAB
LEX method is explicit scheme
0u uc
t x
( , ) 0 0 ( , ) 1 0u x t t u x t x
wave Test for the Lax method to solve the Advection Equation
clear;
% Parameters to define the advection equation and the range in space and time
Lmax = 1.0; % Maximum length
Tmax = 1.; % Maximum time
c = 1.0; % Advection velocity
% Parameters needed to solve the equation within the Lax method
maxt = 350; % Number of time steps
dt = Tmax/maxt;
n = 300; % Number of space steps
nint=50; % The wave-front: intermediate point from which u=0 (nint<n)!!
dx = Lmax/n;
b = c*dt/(2.*dx);
% The Lax method is stable for abs(b)=< 1/2 but it gets difussed unless abs(b)= 1/2
% Initial value of the function u (amplitude of the wave)
for i = 1:(n+1)
if i < nint
u(i,1)=1.;
else
u(i,1)=0.;
end
x(i) =(i-1)*dx;
end
% Value of the amplitude at the boundary at any time
for k=1:maxt+1
u(1,k) = 1.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the Lax method
for k=1:maxt % Time loop
for i=2:n % Space loop
u(i,k+1) =0.5*(u(i+1,k)+u(i-1,k))-b*(u(i+1,k)-u(i-1,k));
end
end
% Graphical representations of the evolution of the wave
figure(1)
mesh(x,time,u')
title('Square-wave test within the Lax Method'); xlabel('X'); ylabel('T')
figure(2)
plot(x,u(:,1),'-',x,u(:,20),'-',x,u(:,50),'-',x,u(:,100),'-')
title('Square-wave test within the Lax Method')
xlabel('X')
ylabel('Amplitude(X)')
9
1.01
2
c t
x
1.0
2
c t
x
0.5
2
c t
x
10. CTCS method for Advection
Advection equation
The Forward time and central space (FTCS)
method implementation
,
0,1........
0,1........
( , )
n o n
j o n
n j n j
x x n x n N
t t j x j t
u u x t
0u uc
t x
Center point in time
2 2, 1 , 1 1, 1,
( ) ( )
2 2
n j n j n j n j
u u u uu uo t o x
t t x x
Center point in Space
, 1 , 1 1, 1,
2 2
n j n j n j n ju u
t
u u
c
x
, 1 , 1 1, 1,
2 ( )
2n j n j n j n j
c tu u u u
x
, 1 , 1 1, 1,
( )n j n j n j n j
c tu u u u
x
CTCS is also an explicit scheme
10
11. CTCS Lax method for Advection Eq
Advection equation
To increase the stability of CTCS method simply
take the average of term u(n,j-1)
,
0,1........
0,1........
( , )
n o n
j o n
n j n j
x x n x n N
t t j x j t
u u x t
0u uc
t x
CTCS explicit scheme, 1 , 1 1, 1,
( )n j n j n j n j
c tu u u u
x
1, 1 1, 1
, 1
( )
2
n j n j
n j
u u
u
1, 1 1, 1
, 1 1, 1,
( )
( )
2
n j n j
n j n j n j
u u c tu u u
x
LEX CTCS method (explicit)
, 1 , 1 1, 1,
( )n j n j n j n j
c tu u u u
x
11
12. Implementation in MATLAB (CTCS)
0u uc
t x
( , ) 1 0
( , ) 0 0
u x t t
u x t x
% Matlab Program : Square-wave Test for the Explicit Method to solve the advection Equation
clear;
% Parameters to define the advection equation and the range in space and % time
Lmax = 1.0; % Maximum length
Tmax = 1.; % Maximum time
c = 1.0; % Advection velocity
% Parameters needed to solve the equation within the explicit method
maxt = 100; % Number of time steps
dt = Tmax/maxt;
n = 100; % Number of space steps
nint=15; % The wave-front: intermediate point from which u=0
dx = Lmax/n;
b = c*dt/(dx)
% Initial value of the function u (amplitude of the wave)
for i = 1:(n+1)
if i < nint
u(i,1)=1.;else
u(i,1)=0.;
end
x(i) =(i-1)*dx;
end
% Value of the amplitude at the boundary
for k=2:maxt+1
u(1,k) = 1.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit method
for k=2:maxt % Time loop
for i=2:n % Space loop
u(i,k+1) =u(i,k-1)-b*(u(i+1,k)-u(i-1,k));
end
end
% Graphical representation of the wave at different selected times
plot(x,u(:,10),'-',x,u(:,50),'-',x,u(:,100),'-',x,u(:,maxt),'-')
title('Square-wave test within the Explicit Method')
xlabel('X')
ylabel('Amplitude(X)')
1c t
x
0.5c t
x
12
13. Implementation in MATLAB (CTCS)
0u uc
t x
( , ) 1 0
( , ) 0 0
u x t t
u x t x
% Matlab Program : Square-wave Test for the Explicit Method to solve the advection Equation
clear;
% Parameters to define the advection equation and the range in space and % time
Lmax = 1.0; % Maximum length
Tmax = 1.; % Maximum time
c = 1.0; % Advection velocity
% Parameters needed to solve the equation within the explicit method
maxt = 100; % Number of time steps
dt = Tmax/maxt;
n = 100; % Number of space steps
nint=15; % The wave-front: intermediate point from which u=0
dx = Lmax/n;
b = c*dt/(dx)
% Initial value of the function u (amplitude of the wave)
for i = 1:(n+1)
if i < nint
u(i,1)=1.;else
u(i,1)=0.;
end
x(i) =(i-1)*dx;
end
% Value of the amplitude at the boundary
for k=2:maxt+1
u(1,k) = 1.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit method
for k=2:maxt % Time loop
for i=2:n % Space loop
u(i,k+1) =0.5*(u(i+1,k-1)+u(i-1,k-1))-b*(u(i+1,k)-u(i-1,k));
end
end
% Graphical representation of the wave at different selected times
plot(x,u(:,10),'-',x,u(:,50),'-',x,u(:,100),'-',x,u(:,maxt),'-')
title('Square-wave test within the Explicit Method')
xlabel('X')
ylabel('Amplitude(X)')
0.5c t
x
1c t
x
13
14. Mehboob, K
NE: 402 computation Method in Nuclear
Engineering
Department of Nuclear Engineering,
KAU, Jeddah, KSA
2017. 5. 3
How to solve 2nd Order PDEs
using MATLAB
14
16. FTCS method for the heat equation
FTCS ( Forward Euler in Time and Central difference in Space )
):),(),(),(),0((
),(),(),(
21
2
2
ydiffusivitthermalDtutLututu
txStxu
x
Dtxu
t
Heat equation in a slab
),( 1
t
uu
t
txu n
j
n
jnj
2
11
2
2
2),(
x
uuu
x
txu n
j
n
j
n
jnj
n
jnj utxu ),(Let
Forward Euler in Time
2nd order Central difference in Space
1
2 1 1
( 2 )n n n n n n
j j j j j j
D tu u tS u u u
x
1
1 1
2
2
( , )
n n n n n
j j j j j
u u u u u
D s x t
t x
FTCS explicit scheme for diffusion Equation
16
17. Implementation in MATLAB (FTCS heat equation)
% Heat Diffusion in one dimensional wire within the % Explicit Method
clear;
% Parameters to define the heat equation and the range in space and time
L = 1.; % Length of the wire
T =1.; % Final time
% Parameters needed to solve the equation within the explicit method
maxk = 2500; % Number of time steps
dt = T/maxk;
n = 50; % Number of space steps
dx = L/n;
cond = 1/4; % Conductivity
b = cond*dt/(dx*dx); % Stability parameter (b=<1)
% Initial temperature of the wire: a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(pi*x(i));
end
% Temperature at the boundary (T=0)
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit method
for k=1:maxk % Time Loop
for i=2:n; % Space Loop
u(i,k+1) =u(i,k) + b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
% Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-',x,u(:,100),'-',x,u(:,300),'-',x,u(:,600),'-')
title('Temperature within the explicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the explicit method')
xlabel('X')
ylabel('Temperature')
),(
),(),(
2
2
txS
x
txu
D
t
txu
)sin()0,(
0),(,0),(,0),0(
xxu
conditionsinitial
txstLutu
conditionsBoundry
17
18. Implementation in MATLAB (FTCS heat equation)
Courant condition for
FTCS
1
2
2
x
tD
2
2 1.01D t
x
2
2 1
2
D t
x
18
19. CTCS method for the heat equation
FTCS ( Forward Euler in Time and Central difference in Space )
):),(),(),(),0((
),(),(),(
21
2
2
ydiffusivitthermalDtutLututu
txStxu
x
Dtxu
t
Heat equation in a slab
2
),( 11
t
uu
t
txu n
j
n
jnj
2
11
2
2
2),(
x
uuu
x
txu n
j
n
j
n
jnj
n
jnj utxu ),(Let
Center difference in Time
2nd order Central difference in Space
1 1
2 1 1
22 ( 2 )n n n n n n
j j j j j j
D tu u tS u u u
x
1 1
1 1
2
2
( , )
2
n n n n n
j j j j j
u u u u u
D s x t
t x
FTCS explicit scheme for diffusion Equation
19
20. CTCS method for the heat equation% Heat Diffusion in one dimensional wire within the % Explicit Method
clear; clc;
% Parameters to define the heat equation and the range in space and time
L = 1.; % Length of the wire
T =1.; % Final time
% Parameters needed to solve the equation within the explicit method
maxk = 600; % Number of time steps
dt = T/maxk;
n = 20; % Number of space steps
dx = L/n;
cond = 1/132; % Conductivity
b =2.*cond*dt/(dx*dx) % Stability parameter (b=<0.01)
% Initial temperature of the wire: a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(pi*x(i));
end
% Temperature at the boundary (T=0)
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit method
for k=2:maxk % Time Loop
for i=2:n; % Space Loop
u(i,k+1) =u(i,k-1) + 0.5*2*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
% Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,30),'-',x,u(:,60),'-')
title('Temperature within the explicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the explicit method')
xlabel('X')
ylabel('Temperature')
),(
),(),(
2
2
txS
x
txu
D
t
txu
)sin()0,(
0),(,0),(,0),0(
xxu
conditionsinitial
txstLutu
conditionsBoundry
0126.0
2
2
x
tD
20
21. Stability of FTCS and CTCS
FTCS is first-order accuracy in time and second-order
accuracy in space.
So small time steps are required to achieve reasonable
accuracy.
Courant condition for FTCS
2
1
2
x
tD
)2(
2
2 112
11 n
j
n
j
n
j
n
j
n
j
n
j uuu
x
tD
tSuu
CTCS method for heat equation
(Both the time and space derivatives are
center-differenced.)
However, CTCS method is unstable for
any time step size.
2
2 1
2
D t
x
2
2 0.0126D t
x
CTCS (unstable)
FTCS (Stable)
21
22. Lax method (FTCS)
Simple modification to the FTCS method
In the differenced time derivative,
)2()( 112112
11 n
j
n
j
n
j
n
j
n
j
n
j
n
j uuu
x
tD
tSuuu
t
uuu
t
uu n
j
n
j
n
j
n
j
n
j
)]([)( 112
111
Replacement by average value from surrounding grid points
The resulting difference equation is
Courant condition for Lax method
4
1
2
x
tD
( Second-order accuracy in both time and space )
22
23. Lax method(CTCS)
Simple modification to the CTCS method
In the differenced time derivative,
)2(
2
2)( 112
1
1
1
12
11 n
j
n
j
n
j
n
j
n
j
n
j
n
j uuu
x
tD
tSuuu
t
uuu
t
uu n
j
n
j
n
j
n
j
n
j
2
)]([
2
)( 1
1
1
12
1111
Replacement by average value from surrounding grid points
The resulting difference equation is
Courant condition for Lax method
4
1
2
x
tD
( Second-order accuracy in both time and space )
23
24. Implementation (FTCS-Lax) Method
% Initial temperature of the wire: a
sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(pi*x(i));
end
% Temperature at the boundary (T=0)
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit
method
for k=2:maxk % Time Loop
for i=2:n; % Space Loop
u(i,k+1) =0.5*(u(i+1,k)+u(i-1,k)) +
0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
2
2 0.1786D t
x
2
2 1
2
D t
x
Stability condition
2
2 0.0047D t
x
24
25. Implementation Lax method(CTCS)
2
2 0.3571D t
x
2
2 1
2
D t
x
Stability condition
% Initial temperature of the wire:
a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(pi*x(i));
end
% Temperature at the boundary (T=0)
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k) = 0.;
time(k) = (k-1)*dt;
end
% Implementation of the explicit
method
for k=2:maxk % Time Loop
for i=2:n; % Space Loop
u(i,k+1) =0.5*(u(i+1,k-1)+u(i-1,k-
1))+ 0.5*2*b*(u(i-1,k)+u(i+1,k)-
2.*u(i,k));
end
end
25
27. Crank Nicolson Algorithm ( Implicit Method )
BTCS ( Backward time, centered space ) method for heat equation
)2( 11
1
2
n
j
n
j
n
jx
tn
j
n
j
n
j TTTtSTT
( This is stable for any choice of time steps,
however it is first-order accurate in time. )
Crank-Nicolson scheme for heat equation
taking the average between time steps n-1 and n,
))22(
)(
1
1
11
111
1
2
11
2
n
j
n
j
n
j
n
j
n
j
n
jx
t
n
j
n
j
n
j
n
j
TTTTTT
SStTT
( This is stable for any choice of time steps and second-order accurate in time. )
a set of coupled linear equations for n
jT
27
30. Multiple Spatial Dimensions
),,(),,(),,( 2
2
2
2
tyxStyxT
yx
tyxT
t
FTCS for 2D heat equation
)2()2( 112112
1 n
jk
n
jk
n
jk
n
kj
n
jk
n
kj
n
jk
n
jk
n
jk TTT
y
t
TTT
x
t
tSTT
Courant condition for this scheme
22
22
2
1
yx
yx
t
( Other schemes such as CTCS and Lax can be easily extended to multiple dimensions. )
30
31. Wave equation with nonuniform wave speed
),,(),(),,( 2
2
2
2
2
2
2
tyxz
yx
yxctyxz
t
2D wave equation
0
),()0,,(),,()0,,(
00
00
vz
yxvyxzyxzyxz
txxtxz
txztyztyz
2sin)1(),0,(
,0),1,(),,1(),,0(
Initial condition :
Boundary
condition :
])5.0(5)5.0(2exp[7.01),( 22
10
1
yxyxcWave speed :
)2()2(2 112
22
112
22
11 n
jk
n
jk
n
jk
jkn
kj
n
jk
n
kj
jkn
jk
n
jk
n
jk TTz
y
tc
zzz
x
tc
zzz
CTCS method for the wave equation :
)(
2
1
2
22
yxfor
tc
Courant condition :
31
32. Wave equation with nonuniform wave speed
Since evaluation of the nth timestep
refers back to the n-2nd step,
for the first step, a trick is employed.
jk
t
jkjkjk atvzz 20
01 2
)2()2( 112
2
0
1
00
12
2
n
jk
n
jk
n
jk
jk
kjjkkj
jk
jk TTz
y
c
zzz
x
c
a
Since initial velocity and value,
0
0
1
0
0
jk
jkjk
z
zv
32
36. Jacobi’s method ( Relaxation method )
Direct solution can be difficult to program efficiently.
Relaxation methods are relatively simple to code,
however, they are not as fast as the direct methods.
Idea :
I. Poisson’s equation can be thought of as the equilibrium solution to the heat
equation with source.
II. Starting with any initial condition, the heat equation solution will eventually
relax to a solution of Poisson’s equation.
)2(
1
)2(
1
2
1
11211222
22
1 n
jk
n
jk
n
jk
n
kj
n
jk
n
kjjk
n
jk
n
jk
yxyx
yx
)(
1
)(
1
2
1
11211222
22
n
jk
n
jk
n
kj
n
kjjk
yxyx
yx
),(),(),,(
t
),(),( 22
yxyxtyxyxyx
)
2
1
( 22
22
yx
yx
t
FTCS
(Maximum time step satisfying Courant condition)
36
38. Simultaneous OverRelaxation (SOR)
The convergence of the Jacobi method is quite slow.
Furthermore, the larger the system, the slower the convergence.
Simultaneous OverRelaxation (SOR) :
the Jacobi method is modified in two ways,
)(
1
)(
1
2
)1(
1
112
1
112
22
22
1
n
jk
n
jk
n
kj
n
kjjk
n
jk
n
jk
yx
yx
yx
1. Improved values are used as soon as they become available.
2. Relaxation parameter ω tries to overshoot for going to the final result.
( 1<ω<2)
38
40. MATLAB The Language of Technical Computing MATLAB PDE
Run: dftcs.m >> dftcs
dftcs - Program to solve the diffusion equation using the Forward Time Centered Space scheme.
Enter time step: 0.0001
Enter the number of grid points: 51
Solution is expected to be stable
2
2
),(),(
x
txT
t
txT
40
41. MATLAB The Language of Technical Computing MATLAB PDE
Run: dftcs.m >> dftcs
dftcs - Program to solve the diffusion equation using the Forward Time Centered Space scheme.
Enter time step: 0.00015
Enter the number of grid points: 61
WARNING: Solution is expected to be unstable
41
42. MATLAB The Language of Technical Computing MATLAB PDE
Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.
Enter time step: 0.0005
Enter the number of grid points: 61
Enter system length: 2 => System length is subcritical
Solution is expected to be stable
Enter number of time steps: 12000
),(
),(),(
2
2
txn
x
txn
t
txn
42
43. MATLAB The Language of Technical Computing MATLAB PDE
Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.
Enter time step: 0.0005
Enter the number of grid points: 61
Enter system length: 4 => System length is supercritical
Solution is expected to be stable
Enter number of time steps: 12000
43
44. MATLAB The Language of Technical Computing MATLAB PDE
Run: advect.m >> advect
advect - Program to solve the advection equation using the various hyperbolic PDE schemes:
FTCS, Lax, Lax-Wendorf
Enter number of grid points: 50
Time for wave to move one grid spacing is 0.02
Enter time step: 0.002
Wave circles system in 500 steps
Enter number of steps: 500
FTCS FTCS
0
),(),(
x
txu
t
txu
44
45. MATLAB The Language of Technical Computing MATLAB PDE
Run: advect.m >> advect
advect - Program to solve the advection equation using the various hyperbolic PDE schemes:
FTCS, Lax, Lax-Wendorf
Enter number of grid points: 50
Time for wave to move one grid spacing is 0.02
Enter time step: 0.02
Wave circles system in 50 steps
Enter number of steps: 50
Lax Lax
45
46. MATLAB The Language of Technical Computing MATLAB PDE
Run: relax.m >> relax
relax - Program to solve the Laplace equation using Jacobi, Gauss-Seidel and SOR methods on a
square grid
Enter number of grid points on a side: 50
Theoretical optimum omega = 1.88184
Enter desired omega: 1.8
Potential at y=L equals 1
Potential is zero on all other boundaries
Desired fractional change = 0.0001
0
),(),(
2
2
2
2
y
yx
x
yx
46