How can I solve this partial differentiation equation numerically?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everyone
I'm trying to solve a PDE by Euler's method : the implicit one. I've written a code to solve it first by the explicit method and I got the results correctly, but the results given by the implicit method are not right. It must be better than the first method because it is unconditionally stable, but that's not happening...
I attached my code so that you can observe any errors and help me.
0 件のコメント
採用された回答
Torsten
2021 年 5 月 26 日
A = zeros(M+1);
U2 = zeros(M+1,N+1);
A(1,1) = 1;
for i=2:M
A(i,i-1) = -sigma;
A(i,i) = 1+2*sigma;
A(i,i+1) = -sigma;
end
A(M+1,M+1) = 1;
U2(:,1) = linsolve(A,U(:,1));
for i=2,N+1
U2(:,i) = linsolve(A,U2(:,i-1));
end
Note that the code could be made faster by factorizing A once and solving the linear systems for only changing right-hand sides. This is possible since A is constant for all times.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Partial Differential Equation Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!