How to fix this error?

2 visualizaciones (últimos 30 días)
sing lai
sing lai el 23 de Feb. de 2014
Comentada: sing lai el 24 de Feb. de 2014
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?

Respuesta aceptada

Peter Nave
Peter Nave el 23 de Feb. de 2014
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 comentario
sing lai
sing lai el 24 de Feb. de 2014
okay..thanks,do you know what actually the current means? current = ((2*h*L^)..., what is this equation should be put?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by