Thomas algorithm - tridiagonal matrix
11 次查看(过去 30 天)
显示 更早的评论
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)];
0 个评论
采纳的回答
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
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 ?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!