フィルターのクリア

Thomas algorithm - tridiagonal matrix

10 ビュー (過去 30 日間)
Cesar Cardenas
Cesar Cardenas 2023 年 3 月 1 日
コメント済み: Cesar Cardenas 2023 年 3 月 2 日
Is there any other way to code and solve the tridiagonal matrix? the idea would be to try to get the plot shown. Matlab beginner, so, no sure how to do it. Any help will be greatly appreciated. Thanks
clear
cm=1/100;
delta = 1*cm;
nu=1e-6;
Uinf=1;
H=2*delta;
y=linspace(0,H,40);
u=Uinf*erf(3*y/delta);
dy=mean(diff(y));
dx=100*dy;
Q=nu*dx/Uinf/dy^2;
a=-Q;
c=-Q;
b=1+2*Q;
N=length(y)-2;
M = diag(b*ones(1,N)) + diag(c*ones(1,N-1),1) + diag(a*ones(1,N-1),-1);
%Constant Ue
Ue = @(x) Uinf;
u = u(2:end-1);
x=0;
uall=[0,u,Ue(x)];

採用された回答

Torsten
Torsten 2023 年 3 月 2 日
編集済み: Torsten 2023 年 3 月 2 日
clear
cm=1/100;
delta = 1*cm;
nu=1e-6;
Uinf=1;
H=2*delta;
y=linspace(0,H,40);
u=Uinf*erf(3*y/delta);
dy=mean(diff(y));
dx=100*dy;
Q=nu*dx/Uinf/dy^2;
a=-Q;
c=-Q;
b=1+2*Q;
N = length(y);
M = diag(b*ones(1,N)) + diag(c*ones(1,N-1),1) + diag(a*ones(1,N-1),-1);
M(1,:) = [1,zeros(1,N-1)];
M(end,:) = [zeros(1,N-1),1];
%Constant Ue
Ue = @(x) Uinf;
u = u(2:end-1);
x=0;
uall=[0,u,Ue(x)];
sol = M\uall.';
plot(y,sol)
grid on
  5 件のコメント
Torsten
Torsten 2023 年 3 月 2 日
You can assign values to certain elements in a matrix by using a loop. But if the above line to define M is correct, it's elegant, isn't it ? Why do you want to define it differently ?
Cesar Cardenas
Cesar Cardenas 2023 年 3 月 2 日
Right thank you, just wanted to have a different version. Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by