Use second-order and fourth-order Runge-Kutta methods
1 次查看(过去 30 天)
显示 更早的评论
The one-dimensional linear convection equation for a scalar T is,
𝜕𝑇/𝜕𝑡 + 𝑎*𝜕𝑇/𝜕𝑥 = 0 0 ≤ 𝑥 ≤ 1
With the initial condition and boundary conditions of, (𝑥, 0) = 𝑒 ^(−200(𝑥−0.25)^ 2) , 𝑇(0,𝑡) = 0, 𝑇(1,𝑡): outflow condition Take 𝑎 = 1, ∆𝑥 = 0.01
Plot the results for t = 0.25, .5, 0.75 for both of them.
2 个评论
回答(1 个)
darova
2021-3-9
I'd try simple euler scheme first. The scheme i used
𝜕𝑇/𝜕𝑡 + 𝑎*𝜕𝑇/𝜕𝑥 = 0
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/544147/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/544152/image.png)
clc,clear
a = 1;
x = 0:0.01:1;
t = 0:0.01:0.75;
U = zeros(length(t),length(x));
U(1,:) = exp(-200*(x-0.25).^2);
U(:,1) = 0;
dx = x(2)-x(1);
dt = t(2)-t(1);
for i = 1:size(U,1)-1
for j = 1:size(U,2)-1
U(i+1,j) = U(i,j) + a*dt/dx*(U(i,j+1)-U(i,j));
end
end
surf(U)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!