How to fix this error?

1 view (last 30 days)
sing lai
sing lai on 23 Feb 2014
Commented: sing lai on 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?

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!