필터 지우기
필터 지우기

1D wave equation finite difference method [urgent]

조회 수: 9 (최근 30일)
sing lai
sing lai 2014년 2월 20일
댓글: Aleksandra Brenko 2022년 5월 1일
dx = .01 ; % Spacing of points on string dt =.01 ; % Size of time step
c = 1 ;% Speed of wave propagation
L = 1 ;% Length of string
stopTime = 30 ; % Time to run the simulation
r = c*dt/dx ;
n=L/dx+1
% Set current and past to the graph of a plucked string
current = .5-.5* cos (2* pi /L * [ 0 : dx :L ] ) ;
past = current ;
for t=0: dt : stopTime
% Calculate the future position of the string
future ( 1 ) = 0 ;
future ( 2 : n-1) = r^2*( current ( 1 : n-2)+current ( 3 : n ) ) + 2*(1-r^2)* current ( 2 : n-1) - past ( 2 : n-1);
future (n) = 0 ;
% Set things up for the next time step
past = current ;
current = future ;
% Plot the graph after every 10th frame
if mod( t /dt , 10) == 0
plot ( [ 0 : dx :L] , current )
axis ( [ 0 L -2 2 ] )
pause ( .001 )
end
end
The above is the matlab code i found from internet, many questions to ask..
1. n=L/dx + 1, what formula and meaning of this equation?
2. current = .5-.5cos.... Is this one the initial condition?
3. if mod(t/dt , 10) = 0, what is the meaning of this code?
Thanks everyone who willing to help me~
  댓글 수: 1
Aleksandra Brenko
Aleksandra Brenko 2022년 5월 1일
I can't help you much but I can tell you this:
  1. The variable x cannot be continuous for us to use a numerical method, it must be an array. The length L (observed length of the string) is divided into small sections dx. So n is the number of those sections, aka the length of the array x.
  2. Yes, it is the position of the string at time 0
  3. mod(t/dt , 10) = 0 means that when you divide t/dt by 10 you get a whole number and the rest is 0. So the code under if mod(t/dt , 10) = 0 will be executed whenever t/dt is divisible by 10.
Also, this code seems incomplete, eg. dx and dt are not defined.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by