Effacer les filtres
Effacer les filtres

How to fix this error?

1 vue (au cours des 30 derniers jours)
sing lai
sing lai le 23 Fév 2014
Commenté : sing lai le 24 Fév 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?

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by