Can someone help me to correct the code for this problem using Crank-Nicolson finite difference implicit method?
5 views (last 30 days)
Show older comments
Question is:
Governing equations:


Boundary conditions:

The Crank-Nicolson finite difference implicit method is used to solve the above equations:
As tried here, I want to plot graphs for velocity profile using parameters like Pe, beta, and N.
This trial code generates plain plot without errors.
Can anyone help me solve this problem?
Trial code
% Trialcodecranknicolson analytical code
function vj_crank
clear all;
clc;
mr=41; mz=41; mt=1000; Pe=10; Kr=1; Sc=1; lambda=1; gamma=pi/8;
tp=600; ttp=500; tttp=100; Gr=1; Gc=1; S=1; Re=1; M=0.5; t=0.1; w=pi; N=1; Da=0.5; beta=1;
dely=0.05;
g=exp(1.i*w*t);
Peva=[1 2 3 4];
for iiii=1:4
Pe=Peva(iiii);
X=linspace(-1,1,mr+1);
V=zeros(mr,mt);
T=zeros(mr,mt);
C=zeros(mr,mt);
%Initial Conditions
for i=1:mr+1
for j=1:mt+1
for k=1:mz+1
V(i,1)=0;
T(i,1)=1;
C(i,1)=1;
end
end
end
for i=1:mr+1
for j=1:mt+1
for k=1:mz+1
V(1,j)=0;
T(1,j)=0;
C(1,j)=0;
end
end
end
% Boundary Conditions
for i=1:mr+1
for j=1:mt+1
for k=1:mz+1
V(mr+1,j)=0;
T(mr+1,j)=0;
C(mr+1,j)=0;
end
end
end
for j=1:mt
for k=2:mz
for i=2:mr
V(i,j+1)=(1/1+beta*1.i*w)*((V(i-1,j)-(2*(V(i,j)))+V(i+1,j)+V(i-1,j+1)-(2*(V(i,j+1)))+V(i+1,j+1))/(2*(dely)^2))+(Re*S)*((V(i+1,j)-V(i,j))/(dely))-(lambda)+(Gr*sin(gamma))*((T(i,j+1)+T(i,j))/(2))+(Gc*sin(gamma))*((C(i,j+1)+C(i,j))/(2))-((Da+M-(Re*1.i*w))*((T(i,j+1)+T(i,j))/(2)));
T(i,j+1)=((T(i-1,j)-(2*(T(i,j)))+T(i+1,j)+T(i-1,j+1)-(2*(T(i,j+1)))+T(i+1,j+1))/(2*(dely)^2))+S*((T(i+1,j)-T(i,j))/(dely))+((N-(Pe*1.i*w))*((T(i,j+1)-T(i,j))/2));
C(i,j+1)=(Sc)*((C(i-1,j)-(2*(C(i,j)))+C(i+1,j)+C(i-1,j+1)-(2*(C(i,j+1)))+C(i+1,j+1))/(2*(dely)^2))+S*((C(i+1,j)-C(i,j))/(dely))-((Kr+1.i*w)*((C(i,j+1)-C(i,j))/2));
end
end
end
figure (1)
hold on
grid off
plot(X,V(:,tp)*g,'-','linewidth',2);
hold off
end
5 Comments
Torsten
on 30 Jun 2023
Can I use Crank Nicholson method to solve the below equations?
Maybe, but I have no idea how to discretize and solve the equation for u together with the third-order term.
You have a fourth equation for p ?
Answers (0)
See Also
Categories
Find more on Boundary Value Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

