How to fix this error?

1 次查看(过去 30 天)
sing lai
sing lai 2014-2-23
评论: sing lai 2014-2-24
This is the code:
dx = .01 ; % Spacing of points on string
dt =.001 ; % Size of time step
c = 1 ;% Speed of wave propagation
L = 0.64 ;% Length of string
stopTime = 30 ; % Time to run the simulation
r = c*dt/dx ;
n = L/dx+1
k = 1
h = 0.005
d = 0.16
% Set current and past to the graph of a plucked string
current = ((2*h*L^2)/(pi^2 * k^2 *d*(L-d)))*sin((k*pi*d)/L)*sin((k*pi*x)/L)*cos((c*k*pi*t)/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 error at line 29 which is this one:
??? Error using ==> plot
Vectors must be the same lengths.
Error in ==> new at 29
plot ( [ 0 : dx :L] , current )
How to fix the error?

采纳的回答

Peter Nave
Peter Nave 2014-2-23
In the line
current = ((2*h*L^2)/(p ...
neither x nor t is defined.
Line:
if mod( t /dt , 10) == 0
testing for equality of two doubles is always dangerous.
  1 个评论
sing lai
sing lai 2014-2-24
okay..thanks,do you know what actually the current means? current = ((2*h*L^)..., what is this equation should be put?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by