How to accomplish periodic boundary condition?

조회 수: 72 (최근 30일)
adv v
adv v 2015년 3월 6일
답변: CKanellas 2017년 5월 10일
%Explicit Method
clear;
%Parameters to define the advective equation and the range in space and time
l=4*pi;%length of the wire
t=1.;%Final time
c=0.1
% Parameters needed to solve the equation within the explicit method
maxk=10; %Number of time steps
n=20; %Number of space steps
dx=l/n;
dt=dx*0.5/c
b=0.5
% Initial value of the function u(amplitude of the wave).
for i=1:n+1
for k=1:maxk
x(i) = (i-1)*dx;
t(k) = (k-1)*dt;
u0(i,:)= (sin(x(i))).^6
ua(i,k)= (sin(x(i)-c*t(k))).^6
end
end
u=ua(:,1:1)
u1=ua(:,1:1)
%p=[0:0.1:2*pi]
% Implementation of the explicit method
for k=2:maxk+1 %Timeloop
for i=2:n-1; %space loop
u(i,k+1)=u(i,k-1)-b*(u(i+1,k)-u(i-1,k));%Centeredinspace and centered in time(leapfrog)
end
end
for k=1:maxk %Timeloop
for i=2:n; %space loop
u1(1,k+1)=u1(n,k);
u1(i,k+1)=u1(i,k)-b*(u1(i,k)-u1(i-1,k));%upwind(forwardintime and backwardinspace
u1(n+1,k)=u1(n,k);
end
end
figure(1)
%plot(x,u)
%integrating the values at different time 1,5,10,25...
plot(x,ua(:,10),'g-',x,u1(:,10),'b-',x,u(:,10),'r')
legend('exact','uw','lf')
title('sinx,Resol(20)')
xlabel('X')
ylabel('Amplitude')
  댓글 수: 1
adv v
adv v 2015년 3월 8일
Hi, Could someone help me how to accomplish periodic boundary condition in Leap frog and Upwind method. I have printed the copy of my program too.

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

답변 (1개)

CKanellas
CKanellas 2017년 5월 10일
Instead of using u1(i-1,k) try circshift(u1,1,2).

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by