Numerical Partial Differential Equation Lecture 6 l Matlab Code For Heat Equation l ut=auxx

preview_player
Показать описание
Lecture # 6
MATLAB Coding For HEAT Equation

Consider the heat equation 𝑈_𝑡=𝑎𝑈_𝑥𝑥
With initial data
U(0,x) = {(2𝑥 𝑥 less than 0.5 and 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 2(1−𝑥)
Boundary Conditions
U(t,0 ) 0 (L.B.C)
U(t,1) = 0 (R.B.C)

Calculate the numerical solution with explicit method.
Use h = 0.25 and 𝝀=𝟎.𝟒
==============================================================================
MATLAB Lectures

Calculus Lectures

Numerical Method With MATLAB Coding

Numerical Solution to Partial Differential Equations

==============================================================================
#MATLABCodingForHeatEquation
#MuhammadAsifMushtaq
#scientific_Math
Рекомендации по теме
Комментарии
Автор

Very good explained. Sir I need Euler method or Runge Kutta method for PDEs.

NASAFrontierBillions
Автор

Thank you so much, but Can you please share Crank Nicholson method ?

mohimen
Автор

May allah give u much and more success in every field of life

FL-to-space
Автор

clc
close all
function [errout, x0, t0;u0] = heatFTCS(nt;nx;alpha;L, tmax;errPlots)
if nargin<1, nt=10; end
if nargin<2, nx=20; end
if nargin<3, alpha=0.1; end
if nargin<4 L=1; end
if nargin<5, tmax=0.5; end
if nargin<6, errPlots=1; end
%----compute mesh spacing and time step
dx=L/(nx-1);
dt=tmax/(nt-1);
r=alpha*dt/dx^2;
r2=1-2*r;
%---creat arrays to save data for export
x=linspace(0, L, nx);
t=linspace(0, tmax, nt);
u=zeros(nx, nt);
%---set IC and BC
u(:, 1)=sin(pi*x/L) %implies u0=0; uL=0
u0=0; uL=0; % needed to apply the BC inside time step loop
%---loop over time steo
for n=2:nt
for i=2:nx-1
u(i, n)=r*u(i-1, n-1)+r2*u(i, n-1)+r*u(i+1, n-1);
end
end
%--- compare with exact solution at end of simulation

err = norm(u(:, nt)- ue);
%set values of optional output variables
if nargout>0, errout=err; end
if nargout>1, x0=x; t0=t; u0=u; end
%---plot error in solution at last time step
if errPlots, return; end
fprintf('\nNors of error=%12.3e at t=%8.2f\n', err, t(nt));
fprintf('\tdt, dx, r=%12.3e %12.3e %8.3f\n', dt, dx, r);
figure; plot(x, u(:, nt), 'o--', x, ue, '-'); xlabel('x'); ylabel('u');
legend('FTCS', 'Exact');
figure; plot(x, u(:, nt)-ue, 'o--'); xlabel('x'); ylabel('u-u_e');
whenever i run this code i got error in norm, plz help me in correcting it

royalkhan
Автор

brother needs help in crank nicolson method ..

VijayKumar-vjo
Автор

لیکن یہ لکھائی ہم مطلب میں کس طرح درج کرنے گے؟

nasih