How to fix this error?

2 Ansichten (letzte 30 Tage)
sing lai
sing lai am 23 Feb. 2014
Kommentiert: sing lai am 24 Feb. 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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by