Hello all. I'm still trying to find what mistake I've made in the code above. Is the error due to no boundary conditions along z direction (along j direction)? Is that why I'm getting the graph as a line at the axis and not any other curve? Or have I made any other mistake in the code? Can anyone please help me find where I went wrong?
Error in graph - Finite difference code
조회 수: 20 (최근 30일)
이전 댓글 표시
I'm a research scholar and I've started coding in MATLAB recently. I'm trying to solve a system of differential equations using finite difference method. The paper I'm working on is by Sharma et al. (I've given the link to the paper here Sharma et al. (2019)). In the paper, they have solved the finite difference equations using Thomas algorithm. But, I'm trying to solve the same finite difference equations without using Thomas algorithm. I've attached my code for your reference. There are no errors shown in the code. However, I'm unable to recreate the graphs given in the paper. May I know where I've gone wrong?
Nr=21; Nz=161; %number of values for radius r, z
R=1; L=16; %max values along each axis
dr=R/(Nr-1); dz=L/(Nz-1); %deltas
r=(0:Nr-1)*dr; z=(0:Nz-1)*dz; %vectors for r, z
u=zeros(Nr,Nz); w=zeros(Nr,Nz);
p=zeros(Nr,Nz); theta=zeros(Nr,Nz);
sigma=zeros(Nr,Nz); %allocate arrays
R=1; M=1; delta=0.6; epsilon=0.005; %constants
alpha=0; n=2; beta=1; Df=1; Sc=0.5; Sr=0.2; %constants
eta=(delta*(n^(n/(n-1))))/(n-1);
%alpha=a/b
h=(1+(epsilon*beta))*(1-eta*((beta-alpha)-(beta-alpha)^n));
%w(:,1)=w*ones(Nr,1); %w distribution at z=0
%w(1,:)=w*ones(1,Nz); %w distribution at r=0
for j=1:Nz-1
for i=2:h
u(i+1,j)=(1/dz*(r(i)))*(((u(i,j))*(r(i))*dz)-((u(i,j))*(dr)*(dz))+((w(i,j))*(r(i))*(dr))-((w(i,j+1))*(r(i))*(dr)));
%(u(i+1,j)-u(i,j))/(dr)+(u(i,j)/r(i,j))+(w(i,j+1)-w(i,j))/(dz)==0;
p(i+1,j)=p(i,j);
p(i,j+1)=p(i,j)+(dz/r(i))*((w(i+1,j)-w(i,j))/dr)+((dz)/(dr)^2)*(w(i+1,j)-2*w(i,j)+w(i-1,j))-(M^2)*dz*w(i,j);
((1+(4/3*R))*(((theta(i+1,j)-theta(i,j))/(dr*(r(i))))+((theta(i+1,j)-2*theta(i,j)+(theta(i-1,j)))/((dr)^2))))+(Df*(((sigma(i+1,j)-sigma(i,j))/(dr*(r(i))))+((sigma(i+1,j)-2*sigma(i,j)+sigma(i-1,j))/((dr)^2))))==0;
((1/Sc)*(((sigma(i+1,j)-sigma(i,j))/(dr*(r(i))))+((sigma(i+1,j)-2*sigma(i,j)+sigma(i-1,j))/((dr)^2))))+((Sr)*(((theta(i+1,j)-theta(i,j))/(dr*(r(i))))+((theta(i+1,j)-2*theta(i,j)+theta(i-1,j))/((dr)^2))))==0;
w(1,j)=w(2,j); theta(1,j)=theta(2,j); sigma(1,j)=sigma(2,j); %boundary condition at r=0
w(Nr,j)=0; theta(Nr,j)=0; sigma(Nr,j)=0; %boundary condition at r=R
%w(i,1)=0; theta(i,1)=0; sigma(i,1)=0;
%w(i,Nz)=0; theta(i,Nz)=0; sigma(i,Nz)=0;
end
end
%plot(r,[w(10,:);w(15,:);w(20,:)])
plot(r,theta)
댓글 수: 17
Torsten
2023년 10월 12일
편집: Torsten
2023년 10월 12일
R=1.5;
P_0=10;
k=1;
eps=1.0000e-04;
r=linspace(eps,R,1000);
solinit = bvpinit(r,[0,0]);
options = bvpset('RelTol', 10e-4,'AbsTol',10e-7);
sol = bvp4c(@(r,y)soret(r,y,P_0),@soret_BC,solinit,options);
y=deval(sol,r);
plot(r,y(1,:))
function dydx = soret(r,y,P_0) % Details ODE to be solved
dydx = zeros(2,1);
dydx(1) = y(2);
dydx(2) = -P_0 - 1/r * y(2) + y(1) ; % This equation is invalid at r = 0, so taken as r+eps
end
function res = soret_BC(ya,yb) % Details boundary conditions
res=[ya(2);yb(1)];
end
R=1.5;
Q=1;
D_f=1;
Sc=0.5;
Sr=0.2;
k=1;
eps=1.0000e-04;
r=linspace(eps,R,100);
solinit = bvpinit(r,[0,0,1,1]);
options = bvpset('RelTol', 1e-8,'AbsTol',1e-8);
sol = bvp4c(@(r,y)soret(r,y),@soret_BC,solinit,options);
y=deval(sol,r);
plot(r,y(2,:))
function dydx = soret(r,y) % Details ODE to be solved
dydx = zeros(4,1);
dydx(1) = y(3); dydx(2)=y(4);
dydx(3) = -y(3)/r;
dydx(4) = -y(4)/r;
% This equation is invalid at r = 0
end
function res = soret_BC(ya,yb) % Details boundary conditions
res=[ya(3); ya(4); yb(1); yb(2)];
end
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




