Finite-difference implicit method

조회 수: 15 (최근 30일)
Ewona CZ
Ewona CZ 2019년 12월 15일
I tried to solve with matlab program the differential equation with finite difference IMPLICIT method. The problem: With finite difference implicit method solve heat problem with initial condition: and boundary conditions: , . Graphs not look good enough. I believe the problem in method realization(%Implicit Method part).
In the pic above are explicit method two graphs (not this code part here) and below - implicit. I think they shouldn't be like these, they are with hips now, so need help with method realization.
clear;
L = 1.; % Lenth of the wire 0<x<L
T =1; % Number of space steps 0<t<T
% Parameters needed to solve the equation within the fully implicit methodv
maxk = 1000; % Number of time steps
dt = T/maxk;
n = 10; % Number of space steps
dx = L/n;
a = 1;
b = (a^2)*dt/(dx*dx); % b Parameter of the method
% Initial temperature of the wire:
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(x(i));
end
% Temperature at the boundary
for t=1:maxk+1
time(t) = (t-1)*dt;
u(1,t) = exp(time(t));
u(n+1,t) = sin(1)*exp(time(t));
end
% Implicit Method
aa(1:n-1) = -b;
b1=-b;
bb(1:n-1) = 1.+2.*b;
a1=1.+2.*b;
cc(1:n-1) = -b;
c1=-b;
for t = 2:maxk % Time loop
uu = u(2:n,t) + dt*(x(2:n)-time(t)).';
v = zeros(n-1,1);
w = a1;
u(2,t) = uu(1)/w;
for i=2:(n-1)
v(i-1) = c1/w;
w = a1 - b1*v(i-1);
u(i+1,t) = (uu(i) - b1*u(i,t))/w;
end
for j=(n-2):-1:1
u(j+1,t) = u(j+1,t) - v(j)*u(j+2,t);
end
end
% Graphical representation of the temperature at different selected times
subplot(2,2,3);
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,45),'-',x,u(:,30),'-',x,u(:,60),'-')
title('Temperatura neisreikstiniu metodu')
xlabel('X')
ylabel('T')
subplot(2,2,4);
mesh(x,time,u')
title('Temperatura neisreikstiniu metodu')
xlabel('X')
ylabel('Temp')
graphs.PNG

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by