How can I program the code for solving PDE equation using finite difference method?

조회 수: 49 (최근 30일)
Hi, I am trying to solve a PDE governing equation using finite differenc method and I am having trouble to set up the programming code for this equation together with the initial and boundary condition. I tried to do the programming code, but it always show 'Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-300'. The equation is dudt= A0+A1*cos(omega*t) +Beta1* [d2udr2+1/r(dudr)], initial condition is u(r,0) = 0, and boundary condition is u(1,t) = 0, t>0.
  댓글 수: 2
Nur Nadhirah Syed Malik
Nur Nadhirah Syed Malik 2021년 12월 27일
%Parameters to define the governing casson fluid equation and the
%parameters value range
L = 1; % Length of the artery
maxk= 2500; % Number of time steps
beta1 = 0.025; % Beta parameter
delta_t = 0.0001; % Time step
delta_r = 0.025; % Radial direction
A0 =0.2; % Amplitude of systolic pressure gradient
A1 =0.4; % Amplitude of diastolic pressure gradient
n = 50; % Number of space steps
du = L/n;
r = 1; %Radius of artery
omega = pi/4;
%Initial conditions of velocity
for i = 1:n+1
u(i) =(i-1)*du;
u(r,1)= 0; % 0<=r<=1
end
% Boundary conditions
for k=1:maxk+1
u(1,k) = 1.;
u(n+1,k)=0.;
end
% Implementation of the explicit
for k=1:maxk % Time Loop
for i=2:n % Space Loop
u(i,k+1) = u(i,k)+ delta_t*(A0 +A1*cos(omega*t)+beta1*((u(i+1,k)-2*u(i,k) + u(i-1,k))/(delta_r)^2 + 1/r *(u(i+1,k)-u(i-1,k))/(2*delta_r)));
end
end
% Graphical representation of the velocity at different selected times
figure(1)
plot(u(:,1),y,'-',u(:,100),y,'-',u(:,300),y,'-',u(:,600),y,'-')
tittle('velocity within explicit method')
xlabel('r')
ylabel('t')
legend('dt=1','dt=100','dt=300','dt=600')

댓글을 달려면 로그인하십시오.

답변 (1개)

Rishabh Singh
Rishabh Singh 2022년 1월 9일
Hi,
In the line below,
u(i,k+1) = u(i,k)+ delta_t*(A0 +A1*cos(omega*t)+beta1*((u(i+1,k)-2*u(i,k) + u(i-1,k))/(delta_r)^2 + 1/r *(u(i+1,k)-u(i-1,k))/(2*delta_r)));
make sure to replace 't' with 'k'. Also the code which you have provided does not produce the error as mentioned by you. Also can you provide more information regarding the variable which you are trying to plot. Is it velocity vs time or something else?

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by