- 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.
- Yes, it is the position of the string at time 0
- 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.
1D wave equation finite difference method [urgent]
13 次查看(过去 30 天)
显示 更早的评论
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
2022-5-1
I can't help you much but I can tell you this:
Also, this code seems incomplete, eg. dx and dt are not defined.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!