Azzera filtri
Azzera filtri

Thomas algorithm - tridiagonal matrix

10 visualizzazioni (ultimi 30 giorni)
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)];

Risposta accettata

Torsten
Torsten il 2 Mar 2023
Modificato: Torsten il 2 Mar 2023
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 Commenti
Torsten
Torsten il 2 Mar 2023
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 il 2 Mar 2023
Right thank you, just wanted to have a different version. Thanks

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by