Euler's method to solve the heat equation
조회 수: 3 (최근 30일)
이전 댓글 표시
hello,
I want to plot the exact and proximative curves for the solution of the heat equation
but my code has a problem:
x1=0;
a = 1;
x2=a;
T = 1; % length of time for solution
n = 599;
N = 150;
dx = a/(n+1.);
dt = T/N;
t=0.; % initial time = 0
beta = 1.e-5;
s = beta*dt/(dx^2);
if s > 0.5
fprintf('gain parameter > 0.5');
end
Adiag = (1-2*s)*ones(n,1);
Asubs = s*ones(n,1);
Asuper = s*ones(n,1);
A = spdiags([Asubs,Adiag,Asuper],[-1 0 1],n,n);
A(n,n) = 1-s;
b= zeros(n,1);
b(1) = 0;
b(n) = 0;
x = linspace(0,a, n+1)';
f=inline('sin(pi*x)');
U_tk = f(x);
a=1 ;
v = inline('exp(-a^2*pi*t)*sin(pi*x)','x','t','a'); % exact solution
for n=1:N
plot(x,U_tk,'b',x,v(x,t,a),'r')
axis([0,1.5,-0.5, 1.5])
title(['lambda=',num2str(s)])
pause,
end;
also, I have to use Euler's explicit method here:
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Thermal Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!